Session session = lockable.getSession();
SessionNamespaceResolver resolver = new SessionNamespaceResolver(session);
Lock lock;
EventListener listener = null;
try {
// check whether the lockable can be locked at all
if (!lockable.isNodeType(NameFormat.format(QName.MIX_LOCKABLE, resolver))) {
throw new IllegalArgumentException("Node is not lockable");
}
lock = tryLock(lockable, isDeep);
if (lock != null) {
return runAndUnlock(lock);
}
if (timeout == 0) {
return TIMED_OUT;
}
long timelimit;
if (timeout == Long.MAX_VALUE) {
timelimit = Long.MAX_VALUE;
} else {
timelimit = System.currentTimeMillis() + timeout;
}
// node is locked by other session -> register event listener if possible
if (isObservationSupported(session)) {
ObservationManager om = session.getWorkspace().getObservationManager();
listener = new EventListener() {
public void onEvent(EventIterator events) {
synchronized (Locked.this) {
Locked.this.notify();
}
}