org.zkoss.zk.ui.http
Class SimpleSession

java.lang.Object
  extended by org.zkoss.zk.ui.http.SimpleSession
All Implemented Interfaces:
Scope, Session, SessionCtrl
Direct Known Subclasses:
SerializableSession

public class SimpleSession
extends java.lang.Object
implements Session, SessionCtrl

A non-serializable implementation of Session.

Note:
Though this class is serializable, it is meaningless to serialize it directly. Reason: it doesn't serialize any session attributes. Rather, it is serialized when Web server serialized HttpSession. Also, notice that SimpleSession is stored as an attribute HttpSession.

Author:
tomyeh

Constructor Summary
protected SimpleSession()
          Used by the deriving class, only if the deriving class implements java.io.Serializable.
  SimpleSession(WebApp wapp, javax.servlet.http.HttpSession hsess, java.lang.Object request)
          Construts a ZK session with a HTTP session.
  SimpleSession(WebApp wapp, javax.portlet.PortletSession psess, java.lang.Object request)
          Construts a ZK session with a Portlet session.
 
Method Summary
 java.lang.Object getAttribute(java.lang.String name)
          Returns the value of the specified custom attribute.
 java.util.Map getAttributes()
          Returns a map of custom attributes associated with this session.
 java.lang.String getClientAddr()
          Deprecated. As of release 3.0.1, replaced with getRemoteAddr().
 java.lang.String getClientHost()
          Deprecated. As of release 3.0.1, replaced with getRemoteHost().
 DesktopCache getDesktopCache()
          Returns the desktop cache, or null if not available.
 java.lang.String getDeviceType()
          Returns the device type that this session belongs to.
 java.lang.String getLocalAddr()
          Returns the Internet Protocol (IP) address of the interface on which the first request was received (and creates this session).
 java.lang.String getLocalName()
          Returns the host name of the Internet Protocol (IP) interface on which the first request was received (and creates this session).
 int getMaxInactiveInterval()
          Return the time, in seconds, between client requests before the servlet container will invalidate this session.
 java.lang.Object getNativeSession()
          Returns the native session, or null if not available.
 java.lang.String getRemoteAddr()
          Returns the Internet Protocol (IP) address of the client or last proxy that sent the first request creating this session.
 java.lang.String getRemoteHost()
          Returns the fully qualified name of the client or the last proxy that sent the first request creating this session.
 java.lang.String getServerName()
          Returns the host name of the server to which the first request was sent (and created this session).
 WebApp getWebApp()
          Returns the Web application that this session belongs to.
 void invalidate()
          Invalidates this session then unbinds any objects bound to it.
 void invalidateNow()
          Really invalidates the session.
 boolean isInvalidated()
          Returns whether this session is invalidated (i.e., Session.invalidate() was called).
 void notifyClientRequest(boolean keepAlive)
          Notifies the session that a client request is received.
 void onDestroyed()
          Called when the session is destroyed.
protected  void readThis(java.io.ObjectInputStream s)
          Used by the deriving class to read back this object, only if the deriving class implements java.io.Serializable.
 void recover(java.lang.Object nativeSession)
          Called when ZK detects Session.getNativeSession() is not initialized properly.
 void removeAttribute(java.lang.String name)
          Removes the specified custom attribute.
protected  void sessionDidActivate(javax.servlet.http.HttpSession hsess)
          Used by the deriving class to post-process a session after it is read back.
protected  void sessionWillPassivate()
          Used by the deriving class to pre-process a session before writing the session Refer to SerializableSession for how to use this method.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets the value of the specified custom attribute.
 void setDesktopCache(DesktopCache cache)
          Sets the desktop cache.
 void setDeviceType(java.lang.String deviceType)
          Sets the device type that this session belongs to.
 void setMaxInactiveInterval(int interval)
          Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.
protected  void writeThis(java.io.ObjectOutputStream s)
          Used by the deriving class to write this object, only if the deriving class implements java.io.Serializable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleSession

public SimpleSession(WebApp wapp,
                     javax.servlet.http.HttpSession hsess,
                     java.lang.Object request)
Construts a ZK session with a HTTP session.

Parameters:
hsess - the original HTTP session.
request - the original request causing this session to be created. If HTTP and servlet, it is javax.servlet.http.HttpServletRequest. If portlet, it is javax.portlet.RenderRequest.
Since:
3.0.1

SimpleSession

public SimpleSession(WebApp wapp,
                     javax.portlet.PortletSession psess,
                     java.lang.Object request)
Construts a ZK session with a Portlet session.

Note: it assumes the scope of attributes is PortletSession.APPLICATION_SCOPE.

Parameters:
psess - the original Portlet session.
request - the original request causing this session to be created. If portlet, it is javax.portlet.RenderRequest.
Since:
3.0.5

SimpleSession

protected SimpleSession()
Used by the deriving class, only if the deriving class implements java.io.Serializable.

Method Detail

getDeviceType

public java.lang.String getDeviceType()
Description copied from interface: Session
Returns the device type that this session belongs to.

A device type identifies the type of a client. For example, "ajax" represents the Web browsers with Ajax support, while "mil" represents clients that supports Mobile Interactive markup Language (on Limited Connected Device, such as mobile phones).

All desktops of the same session must belong to the same device type.

The session's device type is determined by the first desktop's device type.

Specified by:
getDeviceType in interface Session

setDeviceType

public void setDeviceType(java.lang.String deviceType)
Description copied from interface: SessionCtrl
Sets the device type that this session belongs to.

It is called by the desktop when Desktop.setDeviceType(java.lang.String) is called. Don't call this method directly. Otherwise, the result is inpredictable.

Specified by:
setDeviceType in interface SessionCtrl

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface: Session
Returns the value of the specified custom attribute.

Specified by:
getAttribute in interface Scope
Specified by:
getAttribute in interface Session

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Description copied from interface: Session
Sets the value of the specified custom attribute.

Specified by:
setAttribute in interface Session

removeAttribute

public void removeAttribute(java.lang.String name)
Description copied from interface: Session
Removes the specified custom attribute.

Specified by:
removeAttribute in interface Session

getAttributes

public java.util.Map getAttributes()
Description copied from interface: Session
Returns a map of custom attributes associated with this session.

Specified by:
getAttributes in interface Scope
Specified by:
getAttributes in interface Session

getRemoteAddr

public java.lang.String getRemoteAddr()
Description copied from interface: Session
Returns the Internet Protocol (IP) address of the client or last proxy that sent the first request creating this session.

Specified by:
getRemoteAddr in interface Session

getRemoteHost

public java.lang.String getRemoteHost()
Description copied from interface: Session
Returns the fully qualified name of the client or the last proxy that sent the first request creating this session. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address.

Specified by:
getRemoteHost in interface Session

getServerName

public java.lang.String getServerName()
Description copied from interface: Session
Returns the host name of the server to which the first request was sent (and created this session). It is the value of the part before ":" in the Host header value, if any, or the resolved server name, or the server IP address.

Specified by:
getServerName in interface Session
See Also:
Session.getLocalName()

getLocalName

public java.lang.String getLocalName()
Description copied from interface: Session
Returns the host name of the Internet Protocol (IP) interface on which the first request was received (and creates this session).

Note: it is the host name defined in the server. To retrieve the name in URL, use Session.getServerName().

Specified by:
getLocalName in interface Session
See Also:
Session.getServerName()

getLocalAddr

public java.lang.String getLocalAddr()
Description copied from interface: Session
Returns the Internet Protocol (IP) address of the interface on which the first request was received (and creates this session).

Specified by:
getLocalAddr in interface Session

getClientAddr

public java.lang.String getClientAddr()
Deprecated. As of release 3.0.1, replaced with getRemoteAddr().

Specified by:
getClientAddr in interface Session

getClientHost

public java.lang.String getClientHost()
Deprecated. As of release 3.0.1, replaced with getRemoteHost().

Specified by:
getClientHost in interface Session

invalidateNow

public void invalidateNow()
Description copied from interface: SessionCtrl
Really invalidates the session.

Application shall never access this method.

Specified by:
invalidateNow in interface SessionCtrl

setMaxInactiveInterval

public void setMaxInactiveInterval(int interval)
Description copied from interface: Session
Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout.

Specified by:
setMaxInactiveInterval in interface Session
See Also:
Configuration.setTimerKeepAlive(boolean), Configuration.setSessionMaxInactiveInterval(int)

getMaxInactiveInterval

public int getMaxInactiveInterval()
Description copied from interface: Session
Return the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout.

Specified by:
getMaxInactiveInterval in interface Session
See Also:
Configuration.isTimerKeepAlive(), Configuration.getSessionMaxInactiveInterval()

getNativeSession

public java.lang.Object getNativeSession()
Description copied from interface: Session
Returns the native session, or null if not available. The returned object depends on the type of clients. If HTTP, the object is an instance of javax.servlet.http.HttpSession. If portlet, the object is an instance of javax.portlet.PortletSession.

Specified by:
getNativeSession in interface Session

notifyClientRequest

public void notifyClientRequest(boolean keepAlive)
Description copied from interface: SessionCtrl
Notifies the session that a client request is received.

Specified by:
notifyClientRequest in interface SessionCtrl
Parameters:
keepAlive - if the request will keep the session alive, or the request shall be ignored. If the request shall be ignored and the session is timeout, it will cause the session to expire (i.e., be invalidated).

getWebApp

public final WebApp getWebApp()
Description copied from interface: Session
Returns the Web application that this session belongs to.

Specified by:
getWebApp in interface Session

invalidate

public final void invalidate()
Description copied from interface: Session
Invalidates this session then unbinds any objects bound to it.

Note: you usually have to ask the client to redirect to another page (or reload the same page) by use of Executions.sendRedirect(java.lang.String).

The session is not invalidated immediately. Rather, it is invalidated after processing the current request.

Specified by:
invalidate in interface Session

isInvalidated

public final boolean isInvalidated()
Description copied from interface: SessionCtrl
Returns whether this session is invalidated (i.e., Session.invalidate() was called).

Note: ZK doesn't invalidate it immediately (until the event has been processed), so the session might be still alive.

Specified by:
isInvalidated in interface SessionCtrl

getDesktopCache

public DesktopCache getDesktopCache()
Description copied from interface: SessionCtrl
Returns the desktop cache, or null if not available.

Note: this is an utility to implement DesktopCacheProvider, which might or might not use this method. Other part of ZK shall not access this method.

Specified by:
getDesktopCache in interface SessionCtrl

setDesktopCache

public void setDesktopCache(DesktopCache cache)
Description copied from interface: SessionCtrl
Sets the desktop cache.

Note: this is an utility to implement DesktopCacheProvider, which might or might not use this method. Other part of ZK shall not access this method.

Specified by:
setDesktopCache in interface SessionCtrl
Parameters:
cache - the desktop cache; null to denote no cache available.

recover

public void recover(java.lang.Object nativeSession)
Description copied from interface: SessionCtrl
Called when ZK detects Session.getNativeSession() is not initialized properly.

It is actually a workaround to solve the issue that some Web contrainer fails to call HttpSessionActivationListener.sessionDidActivate() unpon failover.

Specified by:
recover in interface SessionCtrl

onDestroyed

public void onDestroyed()
Description copied from interface: SessionCtrl
Called when the session is destroyed.

Application shall never access this method.

Specified by:
onDestroyed in interface SessionCtrl

writeThis

protected void writeThis(java.io.ObjectOutputStream s)
                  throws java.io.IOException
Used by the deriving class to write this object, only if the deriving class implements java.io.Serializable.

Refer to SerializableSession for how to use this method.

Throws:
java.io.IOException

readThis

protected void readThis(java.io.ObjectInputStream s)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Used by the deriving class to read back this object, only if the deriving class implements java.io.Serializable.

Refer to SerializableSession for how to use this method.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

sessionWillPassivate

protected void sessionWillPassivate()
Used by the deriving class to pre-process a session before writing the session

Refer to SerializableSession for how to use this method.


sessionDidActivate

protected void sessionDidActivate(javax.servlet.http.HttpSession hsess)
Used by the deriving class to post-process a session after it is read back.

Application shall not call this method directly.

Refer to SerializableSession for how to use this method.



Copyright © 2005-2009 Potix Corporation. All Rights Reserved.