net.sf.cindy.session
Class AbstractSession

java.lang.Object
  extended by net.sf.cindy.session.AbstractSession
All Implemented Interfaces:
Session
Direct Known Subclasses:
AbstractChannelSession

public abstract class AbstractSession
extends java.lang.Object
implements Session

Abstract session.

Version:
$id$
Author:
Roger Chen

Constructor Summary
AbstractSession()
           
 
Method Summary
 void addSessionFilter(int index, SessionFilter filter)
          Add session filter.
 void addSessionFilter(SessionFilter filter)
          Add session filter.
 boolean containsAttribute(java.lang.Object key)
          Returns true if the session contains an attribute for the specified key.
protected  void dispatchException(java.lang.Throwable throwable)
           
 Future flush(Packet packet)
          Send packet with normal priority.
 Future flush(Packet packet, int priority)
          Send packet with specified priority.
 java.lang.Object getAttribute(java.lang.Object key)
          Get the session attribute mapped with the specified key.
 java.util.Map getAttributes()
          Get all session attributs.
 java.net.SocketAddress getLocalAddress()
          Get the local address which the session bind with.
 PacketDecoder getPacketDecoder()
          Get packet decoder.
 PacketEncoder getPacketEncoder()
          Get packet encoder.
 int getReadPacketSize()
           
 java.net.SocketAddress getRemoteAddress()
          Get the remote address which the session connmected to.
 SessionFilter getSessionFilter(int index)
          Get session filter.
 SessionFilterChain getSessionFilterChain(boolean reversed)
          Get session filter chain.
protected  SessionFilterChain getSessionFilterChain(SessionFilter operateFilter, boolean reversed)
           
 SessionFilter[] getSessionFilters()
          Get all session filters.
 SessionHandler getSessionHandler()
          Get session handler.
 int getSessionTimeout()
          Get session timeout, in millisecond.
 void removeAttribute(java.lang.Object key)
          Removes the attribute for this key if it is present.
 void removeSessionFilter(SessionFilter filter)
          Remove session filter.
 Future send(java.lang.Object obj)
          Send object with normal priority.
 Future send(java.lang.Object obj, int priority)
          Send object with specified priority.
protected abstract  Future send(java.lang.Object obj, Packet packet, int priority)
           
 void setAttribute(java.lang.Object key, java.lang.Object attribute)
          Set session attribute.
 void setLocalAddress(java.net.SocketAddress address)
          Set the local address which the session bind with.
 void setPacketDecoder(PacketDecoder decoder)
          Set packet decoder.
 void setPacketEncoder(PacketEncoder encoder)
          Set packet encoder.
 void setReadPacketSize(int size)
           
 void setRemoteAddress(java.net.SocketAddress address)
          Set the remote address which the session will connected to.
 void setSessionHandler(SessionHandler handler)
          Set session handler.
 void setSessionTimeout(int timeout)
          Set session timeout, in millisecond.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.cindy.Session
close, getSessionType, isStarted, start
 

Constructor Detail

AbstractSession

public AbstractSession()
Method Detail

setRemoteAddress

public void setRemoteAddress(java.net.SocketAddress address)
Description copied from interface: Session
Set the remote address which the session will connected to.

Specified by:
setRemoteAddress in interface Session
Parameters:
address - the remote address

getRemoteAddress

public java.net.SocketAddress getRemoteAddress()
Description copied from interface: Session
Get the remote address which the session connmected to.

Specified by:
getRemoteAddress in interface Session
Returns:
the remote address

setLocalAddress

public void setLocalAddress(java.net.SocketAddress address)
Description copied from interface: Session
Set the local address which the session bind with.

Specified by:
setLocalAddress in interface Session
Parameters:
address - the local address

getLocalAddress

public java.net.SocketAddress getLocalAddress()
Description copied from interface: Session
Get the local address which the session bind with.

Specified by:
getLocalAddress in interface Session
Returns:
the local address

getPacketDecoder

public PacketDecoder getPacketDecoder()
Description copied from interface: Session
Get packet decoder.

Specified by:
getPacketDecoder in interface Session
Returns:
packet decoder

getPacketEncoder

public PacketEncoder getPacketEncoder()
Description copied from interface: Session
Get packet encoder.

Specified by:
getPacketEncoder in interface Session
Returns:
packet encoder

setPacketDecoder

public void setPacketDecoder(PacketDecoder decoder)
Description copied from interface: Session
Set packet decoder.

Specified by:
setPacketDecoder in interface Session
Parameters:
decoder - packet decoder

setPacketEncoder

public void setPacketEncoder(PacketEncoder encoder)
Description copied from interface: Session
Set packet encoder.

Specified by:
setPacketEncoder in interface Session
Parameters:
encoder - packet encoder

getReadPacketSize

public int getReadPacketSize()

setReadPacketSize

public void setReadPacketSize(int size)

getAttributes

public java.util.Map getAttributes()
Description copied from interface: Session
Get all session attributs. The returned map is unmodifiable.

Specified by:
getAttributes in interface Session
Returns:
all attributes

getAttribute

public java.lang.Object getAttribute(java.lang.Object key)
Description copied from interface: Session
Get the session attribute mapped with the specified key.

Specified by:
getAttribute in interface Session
Parameters:
key - key
Returns:
attribute

containsAttribute

public boolean containsAttribute(java.lang.Object key)
Description copied from interface: Session
Returns true if the session contains an attribute for the specified key.

Specified by:
containsAttribute in interface Session
Parameters:
key - key
Returns:
true if the session contains an attribute for the specified key

setAttribute

public void setAttribute(java.lang.Object key,
                         java.lang.Object attribute)
Description copied from interface: Session
Set session attribute.

Specified by:
setAttribute in interface Session
Parameters:
key - key
attribute - attribute

removeAttribute

public void removeAttribute(java.lang.Object key)
Description copied from interface: Session
Removes the attribute for this key if it is present.

Specified by:
removeAttribute in interface Session
Parameters:
key - key

getSessionTimeout

public int getSessionTimeout()
Description copied from interface: Session
Get session timeout, in millisecond.

Specified by:
getSessionTimeout in interface Session
Returns:
session timeout

setSessionTimeout

public void setSessionTimeout(int timeout)
Description copied from interface: Session
Set session timeout, in millisecond.

Specified by:
setSessionTimeout in interface Session
Parameters:
timeout - session timeout

setSessionHandler

public void setSessionHandler(SessionHandler handler)
Description copied from interface: Session
Set session handler.

Specified by:
setSessionHandler in interface Session
Parameters:
handler - session handler

getSessionHandler

public SessionHandler getSessionHandler()
Description copied from interface: Session
Get session handler.

Specified by:
getSessionHandler in interface Session
Returns:
session handler

addSessionFilter

public void addSessionFilter(SessionFilter filter)
Description copied from interface: Session
Add session filter.

Specified by:
addSessionFilter in interface Session
Parameters:
filter - session filter

addSessionFilter

public void addSessionFilter(int index,
                             SessionFilter filter)
Description copied from interface: Session
Add session filter.

Specified by:
addSessionFilter in interface Session
Parameters:
index - index
filter - session filter

removeSessionFilter

public void removeSessionFilter(SessionFilter filter)
Description copied from interface: Session
Remove session filter.

Specified by:
removeSessionFilter in interface Session
Parameters:
filter - session filter

getSessionFilter

public SessionFilter getSessionFilter(int index)
Description copied from interface: Session
Get session filter.

Specified by:
getSessionFilter in interface Session
Parameters:
index - index
Returns:
session filter

getSessionFilters

public SessionFilter[] getSessionFilters()
Description copied from interface: Session
Get all session filters.

Specified by:
getSessionFilters in interface Session
Returns:
session filters

flush

public Future flush(Packet packet)
Description copied from interface: Session
Send packet with normal priority. This method is a shorthand for flush(packet, 0).

Specified by:
flush in interface Session
Parameters:
packet - send packet
Returns:
send future

flush

public Future flush(Packet packet,
                    int priority)
Description copied from interface: Session
Send packet with specified priority. Integer.MAX_VALUE indicate the max priority, Integer.MIN_VALUE indicate the min priority and 0 indicate the normal priority.

Specified by:
flush in interface Session
Parameters:
packet - send packet
priority - send priority
Returns:
send future

send

public Future send(java.lang.Object obj)
Description copied from interface: Session
Send object with normal priority. The object will be encoded to Packet use associated PacketEncoder. This method is a shorthand for send(obj, 0).

Specified by:
send in interface Session
Parameters:
obj - send object
Returns:
send future

send

public Future send(java.lang.Object obj,
                   int priority)
Description copied from interface: Session
Send object with specified priority. Integer.MAX_VALUE indicate the max priority, Integer.MIN_VALUE indicate the min priority and 0 indicate the normal priority. The object will be encoded to Packet use associated PacketEncoder.

Specified by:
send in interface Session
Parameters:
obj - send object
priority - send priority
Returns:
send future

send

protected abstract Future send(java.lang.Object obj,
                               Packet packet,
                               int priority)

getSessionFilterChain

public SessionFilterChain getSessionFilterChain(boolean reversed)
Description copied from interface: Session
Get session filter chain.

Specified by:
getSessionFilterChain in interface Session
Parameters:
reversed - some events like xxxSend/xxxSent need to be dispatched in reversed order
Returns:
session filter chain

getSessionFilterChain

protected SessionFilterChain getSessionFilterChain(SessionFilter operateFilter,
                                                   boolean reversed)

dispatchException

protected void dispatchException(java.lang.Throwable throwable)