Class SessionManager
- java.lang.Object
-
- com.gurock.smartinspect.session.SessionManager
-
public class SessionManager extends Object
Manages and configures Session instances. This class manages and configures a list of sessions. Sessions can be configured and added to the list with the add method. To lookup a stored session, you can use get. To remove an existing session from the list, call delete. Stored sessions will be reconfigured if loadConfiguration has been called and contains corresponding session entries.This class is fully threadsafe.
-
-
Constructor Summary
Constructors Constructor Description SessionManager()Creates and initializes a new SessionManager instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Session session, boolean store)Configures a passed Session instance and optionally saves it for later access.voidclear()Clears the configuration of this session manager and removes all sessions from the internal lookup table.voiddelete(Session session)Removes a session from the internal list of sessions.Sessionget(String name)Returns a previously added session.SessionDefaultsgetDefaults()This method lets you specify the default property values for new sessions which will be passed to the add method.voidloadConfiguration(Configuration config)Loads the configuration properties of this session manager.voidupdate(Session session, String to, String from)Updates an entry in the internal lookup table of sessions.
-
-
-
Method Detail
-
loadConfiguration
public void loadConfiguration(Configuration config)
Loads the configuration properties of this session manager.This method loads the configuration of this session manager from the passed Configuration object. Sessions which have already been stored or will be added with add will automatically configured with the new properties if the passed Configuration object contains corresponding session entries. Moreover, this method also loads the default session properties which will be applied to all sessions which are passed to add.
Please see the SmartInspect.loadConfiguration method for details on how session entries look like.
- Parameters:
config- The Configuration object to load the configuration from
-
add
public void add(Session session, boolean store)
Configures a passed Session instance and optionally saves it for later access.This method configures the passed session with the default session properties as specified by the defaults property. This default configuration can be overridden on a per-session basis by loading the session configuration with the loadConfiguration method.
If the 'store' parameter is true, the passed session is stored for later access and can be retrieved with the get method. To remove a stored session from the internal list, call delete.
If this method is called multiple times with the same session name, then the get method operates on the session which got added last. If the session parameter is null, this method does nothing.
- Parameters:
session- The session to configure and to save for later access, if desiredstore- Indicates if the passed session should be stored for later access
-
delete
public void delete(Session session)
Removes a session from the internal list of sessions.This method removes a session which has previously been added with the add method. After this method returns, the get method returns null when called with the same session name unless a different session with the same name has been added. This method does nothing if the supplied session argument is null.
- Parameters:
session- The session to remove from the lookup table of sessions. Not allowed to be null
-
get
public Session get(String name)
Returns a previously added session. This method returns a session which has previously been added with the add method and can be identified by the supplied name parameter. If the requested session is unknown or if the name argument is null, this method returns null. Note that the behavior of this method can be unexpected in terms of the result value if multiple sessions with the same name have been added. In this case, this method returns the session which got added last and not necessarily the session you expect. Adding multiple sessions with the same name should therefore be avoided.- Parameters:
name- The name of the session to lookup and return. Not allowed to be null- Returns:
- The requested session or null if the supplied name is null or if the session is unknown
-
update
public void update(Session session, String to, String from)
Updates an entry in the internal lookup table of sessions.Once the name of a session has changed, this method is called to update the internal session lookup table. The 'to' argument specifies the new name and 'from' the old name of the session. After this method returns, the new name can be passed to the get method to lookup the supplied session.
- Parameters:
session- The session whose name has changed and whose entry should be updatedto- The new name of the sessionfrom- The old name of the session
-
clear
public void clear()
Clears the configuration of this session manager and removes all sessions from the internal lookup table.
-
getDefaults
public SessionDefaults getDefaults()
This method lets you specify the default property values for new sessions which will be passed to the add method. Please see the add method for details. For information about the available session properties, please refer to the documentation of the Session class.- Returns:
- The default property values for new sessions
-
-