8.4.7 Session-scoped and Open-scoped Locks

When a lock is placed on a node, it can be specified to be either a session-scoped lock or an open-scoped lock. A session-scoped lock automatically expires when the session through which the lock owner placed the lock expires. An open-scoped lock does not expire until it is either explicitly unlocked or an implementation-specific limitation intervenes (like a timeout, see below).

In both cases, the lock token must be attached to the current session in order to alter any nodes locked by that token's lock. In the case of session-scoped locks, however, the user need not explicitly do anything since the token is automatically attached to the session and expires with it in any case.

With open–scoped locks the token is also automatically attached to the session. However, the user must additionally ensure that a reference to the lock token is preserved separately so that it can later be attached to another session. By assumption, an open-scoped lock is being used to avoid co-expiration with the initial session. Otherwise, there would be no point in using an open scoped lock, since session scoping would suffice. It is for handling these cases of attaching an existing lock token from a previous session to a new session that the methods addLockToken, removeLockToken and getLockTokens are provided.

To determine an existing lock’s scoping, the method Lock.isSessionScoped() is provided.