net.sf.cindy
Interface Session

All Known Implementing Classes:
AbstractChannelSession, AbstractSession, DatagramChannelSession, PipeSession, ServerSocketChannelSession, SocketChannelSession

public interface Session

Session represents the network connection.

Version:
$id$
Author:
Roger Chen

Method Summary
 void addSessionFilter(int index, SessionFilter filter)
          Add session filter.
 void addSessionFilter(SessionFilter filter)
          Add session filter.
 Future close()
          Close the session.
 boolean containsAttribute(java.lang.Object key)
          Returns true if the session contains an attribute for the specified key.
 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.
 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.
 SessionFilter[] getSessionFilters()
          Get all session filters.
 SessionHandler getSessionHandler()
          Get session handler.
 int getSessionTimeout()
          Get session timeout, in millisecond.
 SessionType getSessionType()
          Get session type.
 boolean isStarted()
          Session have started.
 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.
 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 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.
 Future start()
          Start the session.
 

Method Detail

getSessionType

SessionType getSessionType()
Get session type.

Returns:
session type

setRemoteAddress

void setRemoteAddress(java.net.SocketAddress address)
Set the remote address which the session will connected to.

Parameters:
address - the remote address
Throws:
java.lang.IllegalStateException

getRemoteAddress

java.net.SocketAddress getRemoteAddress()
Get the remote address which the session connmected to.

Returns:
the remote address

setLocalAddress

void setLocalAddress(java.net.SocketAddress address)
Set the local address which the session bind with.

Parameters:
address - the local address
Throws:
java.lang.IllegalStateException

getLocalAddress

java.net.SocketAddress getLocalAddress()
Get the local address which the session bind with.

Returns:
the local address

setPacketDecoder

void setPacketDecoder(PacketDecoder decoder)
Set packet decoder.

Parameters:
decoder - packet decoder

getPacketDecoder

PacketDecoder getPacketDecoder()
Get packet decoder.

Returns:
packet decoder

setPacketEncoder

void setPacketEncoder(PacketEncoder encoder)
Set packet encoder.

Parameters:
encoder - packet encoder

getPacketEncoder

PacketEncoder getPacketEncoder()
Get packet encoder.

Returns:
packet encoder

getAttributes

java.util.Map getAttributes()
Get all session attributs. The returned map is unmodifiable.

Returns:
all attributes

containsAttribute

boolean containsAttribute(java.lang.Object key)
Returns true if the session contains an attribute for the specified key.

Parameters:
key - key
Returns:
true if the session contains an attribute for the specified key

getAttribute

java.lang.Object getAttribute(java.lang.Object key)
Get the session attribute mapped with the specified key.

Parameters:
key - key
Returns:
attribute

setAttribute

void setAttribute(java.lang.Object key,
                  java.lang.Object attribute)
Set session attribute.

Parameters:
key - key
attribute - attribute

removeAttribute

void removeAttribute(java.lang.Object key)
Removes the attribute for this key if it is present.

Parameters:
key - key

setSessionTimeout

void setSessionTimeout(int timeout)
Set session timeout, in millisecond.

Parameters:
timeout - session timeout

getSessionTimeout

int getSessionTimeout()
Get session timeout, in millisecond.

Returns:
session timeout

getSessionFilterChain

SessionFilterChain getSessionFilterChain(boolean reversed)
Get session filter chain.

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

addSessionFilter

void addSessionFilter(SessionFilter filter)
Add session filter.

Parameters:
filter - session filter

addSessionFilter

void addSessionFilter(int index,
                      SessionFilter filter)
Add session filter.

Parameters:
index - index
filter - session filter

removeSessionFilter

void removeSessionFilter(SessionFilter filter)
Remove session filter.

Parameters:
filter - session filter

getSessionFilter

SessionFilter getSessionFilter(int index)
Get session filter.

Parameters:
index - index
Returns:
session filter

getSessionFilters

SessionFilter[] getSessionFilters()
Get all session filters.

Returns:
session filters

setSessionHandler

void setSessionHandler(SessionHandler handler)
Set session handler.

Parameters:
handler - session handler

getSessionHandler

SessionHandler getSessionHandler()
Get session handler.

Returns:
session handler

isStarted

boolean isStarted()
Session have started.

Returns:
session have started

start

Future start()
Start the session.

Returns:
start future

close

Future close()
Close the session.

Returns:
close future

flush

Future flush(Packet packet)
Send packet with normal priority. This method is a shorthand for flush(packet, 0).

Parameters:
packet - send packet
Returns:
send future

flush

Future flush(Packet packet,
             int priority)
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.

Parameters:
packet - send packet
priority - send priority
Returns:
send future

send

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

Parameters:
obj - send object
Returns:
send future

send

Future send(java.lang.Object obj,
            int priority)
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.

Parameters:
obj - send object
priority - send priority
Returns:
send future