All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.contextfw.web.commons.cloud.session.CloudSession Maven / Gradle / Ivy

The newest version!
package net.contextfw.web.commons.cloud.session;

import net.contextfw.web.application.configuration.Configuration;
import net.contextfw.web.application.configuration.SettableProperty;
import net.contextfw.web.application.configuration.TemporalProperty;

/**
 * A common interface for cloud based sessions.
 * 
 * 

* Cloud session is a session handling, where session data is kept serialized on * database and allows multiple nodes to access same data in common way. *

*

* Session is a simple key/value-store and supports basic CRUD-operations. * Object are serialized and deserialized, so all kind of structures can be * stored in transparent way. *

*

* When values are fetched or stored, operations are cached by default and are * synced to database when session is closed. In this way, database connections * are minimized. For all CRUD-methods there exists also a non-cached variant if * that is needed. *

* *

Opening and closing session

* * It is best to handle opening and closing through LifecycleListener and there * exists a ready made listener CloudSessionLifecycleListener for it. * * By default session is opened in lazy-mode where session cookie and data * structures are created only when needed. This minifies unnecessary session * creations. * *

Opening session in existing mode

* * Sometimes it is necessary to open session in such mode that it must exist in * order to be effective. This is important especially in applications that poll * server frequently. In essence frequent polling may prevent session * expiration. * * The CloudSessionLifecycleListener is configured in such way that if remote * method is also annotated with * @CloudSessionOpenMode(OpenMode.EXISTING), an existing session is * required and session expiration is not altered. * * @author [email protected] */ public interface CloudSession { /** * Defines the the name of the cookie used to hold session handle. */ SettableProperty COOKIE_NAME = Configuration.createProperty(String.class, CloudSession.class.getName() + ".cookieName"); /** * Defines the maximum inactivity for session before it is expired. */ TemporalProperty MAX_INACTIVITY = Configuration.createTemporalProperty( CloudSession.class.getName() + ".maxInactivity"); /** * Closes session and syncs all cached data to database. */ void closeSession(); /** * Expires session and removes possible cookies and database structures. */ void expireSession(); /** * Fetches a value for given type. * *

* If type has been fetched before it is taken from local cache. *

* @param type * The type to be fetched. * @return * Corresponding value or null if value does not exist. */ T get(Class type); /** * * @param type * @param nonCached * @return * * * *

* If type has been fetched before it is taken from local cache. *

* @param type * The type to be fetched. * @return * Corresponding value or null if value does not exist. * */ T get(Class type, boolean nonCached); /** * * @param key * @param type * @return */ T get(String key, Class type); T get(String key, Class type, boolean nonCached); void openSession(OpenMode mode); void remove(Class type); void remove(Class type, boolean nonCached); void remove(String key); void remove(String key, boolean nonCached); /** * Sets a value to the cloud session * *

* This method creates a key from values class name and dispatches it to * set(String key, Object value). This method is nice shortcut * for objects that are stored as "singletons" to session. *

* * @param value * The value to be set */ void set(Object value); void set(Object value, boolean nonCached); /** * Sets a value with given key to the cloud session. * *

* The setting of the value is immediately seen by the session through * get(), but setting the actual value to storage is delayed until session * is closed. *

*

* If value has been removed or set earlier to different value, those * changes will be overriden. *

* * @param key * The key to distinguish value * @param value * The value to be set. If null is passed, the value * is removed. */ void set(String key, Object value); void set(String key, Object value, boolean nonCached); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy