I would fix the design:
public boolean lock(Application app, User user);
public void unlock(Application app, User user);
so the names will be more clear. The behavior would be as follows: the client code calls lock (), and if it blocked smth, it returns true, otherwise false. This fixes some of the misunderstandings in your api: if it successfully blocked smth, then why does it return false? In addition, it would be easier to write client code:
if (lockManager.lock()) {
...
} else {
throw new LockNotObtainedException()
}
The second method, in my opinion, is in order.
source
share