@Test public void shouldBeAbleToLock() throws Exception { final Optional<Lock> lock = repository.tryLock("2222", 1, SECONDS); assertThat(lock).isNotNull(); assertTrue(lock.isPresent()); }
@Override public Optional<Lock> tryLock(String stateMachineId, long timeout, TimeUnit timeUnit) { final Handle handle = jdbi.open(); final boolean lock = attachDao(handle).lock(stateMachineId, timeUnit.toSeconds(timeout)); if (lock) { return Optional.<Lock>of(new JdbiLock(handle, stateMachineId)); } else { handle.close(); } return Optional.<Lock>empty(); }
MysqlTransitionRepository implements TransitionRepository { @Override public Optional<Lock> tryLock(String stateMachineId, long timeout, TimeUnit timeUnit) { final Handle handle = jdbi.open(); final boolean lock = attachDao(handle).lock(stateMachineId, timeUnit.toSeconds(timeout)); if (lock) { return Optional.<Lock>of(new JdbiLock(handle, stateMachineId)); } else { handle.close(); } return Optional.<Lock>empty(); } }
MysqlTransitionRepository implements TransitionRepository { @Override public Optional<Lock> tryLock(String stateMachineId, long timeout, TimeUnit timeUnit) { final Handle handle = jdbi.open(); final boolean lock = attachDao(handle).lock(stateMachineId, timeUnit.toSeconds(timeout)); if (lock) { return Optional.<Lock>of(new JdbiLock(handle, stateMachineId)); } else { handle.close(); } return Optional.<Lock>empty(); } MysqlTransitionRepository(DBI jdbi); }
MysqlTransitionRepository implements TransitionRepository { @Override public Optional<Lock> tryLock(String stateMachineId, long timeout, TimeUnit timeUnit) { final Handle handle = jdbi.open(); final boolean lock = attachDao(handle).lock(stateMachineId, timeUnit.toSeconds(timeout)); if (lock) { return Optional.<Lock>of(new JdbiLock(handle, stateMachineId)); } else { handle.close(); } return Optional.<Lock>empty(); } MysqlTransitionRepository(DBI jdbi); @Override Transition get(String stateMachineId); @Override Set<String> getIds(); @Override String create(Object initialState, List<Object> initialContextData); @Override Optional<Lock> tryLock(String stateMachineId, long timeout, TimeUnit timeUnit); }
MysqlTransitionRepository implements TransitionRepository { @Override public Optional<Lock> tryLock(String stateMachineId, long timeout, TimeUnit timeUnit) { final Handle handle = jdbi.open(); final boolean lock = attachDao(handle).lock(stateMachineId, timeUnit.toSeconds(timeout)); if (lock) { return Optional.<Lock>of(new JdbiLock(handle, stateMachineId)); } else { handle.close(); } return Optional.<Lock>empty(); } MysqlTransitionRepository(DBI jdbi); @Override Transition get(String stateMachineId); @Override Set<String> getIds(); @Override String create(Object initialState, List<Object> initialContextData); @Override Optional<Lock> tryLock(String stateMachineId, long timeout, TimeUnit timeUnit);  }