code: public synchronized Session getSession(String workspaceName, ManageableRepository repository) throws LoginException,
        NoSuchWorkspaceException, RepositoryException
     {
  
        if (closed)
        {
           throw new IllegalStateException("Session provider already closed");
        }
  
        if (workspaceName == null)
        {
           throw new IllegalArgumentException("Workspace Name is null");
        }
  
        ExtendedSession session = cache.get(key(repository, workspaceName));
        // create and cache new session
  
        if (session == null)
        {
           if (conversationState != null)
           {
              session =
                       (ExtendedSession) repository.getDynamicSession(workspaceName, conversationState.getIdentity()
                                .getMemberships());
           }
           else if (!isSystem)
           {
              session = (ExtendedSession)repository.login(workspaceName);
           }
           else
           {
              session = (ExtendedSession)repository.getSystemSession(workspaceName);
           }
  
           session.registerLifecycleListener(this);
  
           cache.put(key(repository, workspaceName), session);
        }
  
        return session;
     }
docs: Gets the session from an internal cache if a similar session has already been used
  or creates a new session and puts it into the internal cache.
  
  @param workspaceName the workspace name
  @param repository the repository instance
  @return a session corresponding to the given repository and workspace
  @throws LoginException if an error occurs while trying to login to the workspace
  @throws NoSuchWorkspaceException if the requested workspace doesn't exist
  @throws RepositoryException if any error occurs