org.xlightweb.server
Interface ISessionManager

Package class diagram package ISessionManager
All Superinterfaces:
Closeable
All Known Implementing Classes:
SessionManager

public interface ISessionManager
extends Closeable

Session Manager. The API required to manage sessions. By implementing and assigning the SessionManager the HttpSession can be managed by a custom implementation. It can also be used to intercept the (default) SessionManager data flow. See example:

 class MySessionManagerInterceptor implements ISessionManager {
    private ISessionManager delegate = null;
    
    void MySessionManagerInterceptor(ISessionManager delegate) {
       this.delegate = delegate;
    }
    
    public boolean isEmtpy() {
       return delegate.isEmtpy();
    }
    
    public Map getSessionMap() {
       return delegate.getSessionMap();
    }
    
    public String newSession(String idPrefix) throws IOException {
       String id = delegate.newSession(idPrefix);
       System.out.println("session " + id + " created");
       return id;
    }
    
    public void saveSession(String sessionId) throws IOException {
       delegate.saveSession(sessionId);
    }

    public void registerSession(HttpSession session) throws IOException {
       delegate.registerSession(session);
    }
    
    public HttpSession getSession(String sessionId) throws IOException {
       return delegate.getSession(sessionId);
    }
    
    public void removeSession(String sessionId) throws IOException {
       delegate.removeSession(sessionId);
    }
   
    public void close() throws IOException {
       delegate.close();
    }
 }

 ... 
 
 HttpServer httpServer = new HttpServer(8030, myHandler);
 httpServer.setSessionManager(new MySessionManagerInterceptor(httpServer.getSessionManager()));
 httpServer.start();
 


Method Summary
 HttpSession getSession(String sessionId)
          returns the session for a session id
 Map<String,HttpSession> getSessionMap()
          return the session map
 boolean isEmtpy()
          returns true, if no session exists
 String newSession(String idPrefix)
          creates a new session
 void registerSession(HttpSession session)
          registers a session
 void removeSession(String sessionId)
          removes a session
 void saveSession(String sessionId)
          save the session
 
Methods inherited from interface java.io.Closeable
close
 

Method Detail

isEmtpy

boolean isEmtpy()
returns true, if no session exists

Returns:
true, if no session exists

getSession

HttpSession getSession(String sessionId)
                       throws IOException
returns the session for a session id

Parameters:
sessionId - the session id
Returns:
the session or null
Throws:
IOException - if an exception occurs

getSessionMap

Map<String,HttpSession> getSessionMap()
return the session map

Returns:
the session map

newSession

String newSession(String idPrefix)
                  throws IOException
creates a new session

Parameters:
idPrefix - the id prefix
Returns:
the session id
Throws:
IOException - if an exception occurs

saveSession

void saveSession(String sessionId)
                 throws IOException
save the session

Parameters:
session - id the session id
Throws:
IOException - if an exception occurs

registerSession

void registerSession(HttpSession session)
                     throws IOException
registers a session

Parameters:
session - the session
Throws:
IOException - if an exception occurs

removeSession

void removeSession(String sessionId)
                   throws IOException
removes a session

Parameters:
session - the session id
Throws:
IOException - if an exception occurs