(one-shot logout for all opened sessions)
Use org.exoplatform.services.jcr.ext.common.SessionProvider which is responsible for caching/obtaining your JCR Sessions and closing all opened sessions at once.
public class SessionProvider {
/**
* Creates a SessionProvider for a certain identity
* @param cred
*/
public SessionProvider(Credentials cred)
/**
* Gets the session from internal cache or creates and caches a new one
*/
public Session getSession(String workspaceName, ManageableRepository repository)
throws LoginException, NoSuchWorkspaceException, RepositoryException
/**
* Calls a logout() method for all cached sessions
*/
public void close()
/**
* a Helper for creating a System session provider
* @return System session
*/
public static SessionProvider createSystemProvider()
/**
* a Helper for creating an Anonimous session provider
* @return System session
*/
public static SessionProvider createAnonimProvider()
}
The SessionProvider is per-request or per-user object, depending on your policy. Create it with your application before performing JCR operations, use it to obtain the Sessions and close at the end of an application session(request). See the following example:
// (1) obtain current javax.jcr.Credentials, for example get it from AuthenticationService
Credentials cred = ....
// (2) create SessionProvider for current user
SessionProvider sessionProvider = new SessionProvider(ConversationState.getCurrent());
// NOTE: for creating an Anonymous or System Session use the corresponding static SessionProvider.create...() method
// Get appropriate Repository as described in "Obtaining Repository object" section for example
ManageableRepository repository = (ManageableRepository) ctx.lookup("repositoryName");
// get an appropriate workspace's session
Session session = sessionProvider.getSession("workspaceName", repository);
.........
// your JCR code
.........
// Close the session provider
sessionProvider.close();