TopoWeb Commons API

org.topoweb.net.server
Class PlainSession

java.lang.Object
  |
  +--org.topoweb.net.server.PlainSession
All Implemented Interfaces:
Session

public class PlainSession
extends java.lang.Object
implements Session

A minimal implementation of the Session interface. This implementation comes with its own trivial SessionPool implementation.

Author:
Babak Farhang
See Also:
getFactory()

Constructor Summary
protected PlainSession()
           
  PlainSession(java.nio.channels.SocketChannel channel)
          Creates an instance with the specified socket channel.
 
Method Summary
 void appendReadBuffer(java.nio.ByteBuffer buffer)
          Append the given buffer into this instance's internal "read buffer".
protected  void clear()
          Clears the fields of this instance.
static SessionPool getFactory()
          Returns a trivial pool that returns PlainSession instances and doesn't do any caching.
 int getReadAmount()
          Returns the content-length of the internal "read buffer".
 byte[] getReadArray()
          Returns the internal "read buffer".
 java.nio.channels.SocketChannel getSocketChannel()
          Returns the socket channel used by this session.
 java.nio.ByteBuffer[] getWriteBuffers()
          Returns the "write buffers".
protected  void setSocketChannel(java.nio.channels.SocketChannel channel)
          Sets the socket channel.
 void setWriteBuffers(java.nio.ByteBuffer[] buffers)
          Sets the "write buffers".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlainSession

protected PlainSession()

PlainSession

public PlainSession(java.nio.channels.SocketChannel channel)
Creates an instance with the specified socket channel.

Parameters:
channel - the SocketChannel returned by the getSocketChannel method
Throws:
java.lang.IllegalArgumentException - if channel is null
Method Detail

getFactory

public static SessionPool getFactory()
Returns a trivial pool that returns PlainSession instances and doesn't do any caching.

Returns:
a new SessionPool instance.

getSocketChannel

public java.nio.channels.SocketChannel getSocketChannel()
Description copied from interface: Session
Returns the socket channel used by this session.

Specified by:
getSocketChannel in interface Session

appendReadBuffer

public void appendReadBuffer(java.nio.ByteBuffer buffer)
Description copied from interface: Session
Append the given buffer into this instance's internal "read buffer". The "read amount" is incremented by the buffer.remaining().

Specified by:
appendReadBuffer in interface Session
Parameters:
buffer - the buffer whose contents are appended
See Also:
Session.getReadArray(), Session.getReadAmount()

getReadArray

public byte[] getReadArray()
Description copied from interface: Session
Returns the internal "read buffer". The bytes actually read begin at the zero offset and is of the length specified by the getReadAmount() method.

Specified by:
getReadArray in interface Session
Returns:
the intenal read buffer
See Also:
Session.appendReadBuffer(ByteBuffer), Session.getReadAmount()

getReadAmount

public int getReadAmount()
Description copied from interface: Session
Returns the content-length of the internal "read buffer".

Specified by:
getReadAmount in interface Session
Returns:
the number of bytes appended into the read buffer
See Also:
Session.appendReadBuffer(ByteBuffer), Session.getReadArray()

setWriteBuffers

public void setWriteBuffers(java.nio.ByteBuffer[] buffers)
Description copied from interface: Session
Sets the "write buffers". The given buffers are to be written out to the client.

Specified by:
setWriteBuffers in interface Session
Parameters:
buffers - the write buffers
See Also:
Session.getWriteBuffers()

getWriteBuffers

public java.nio.ByteBuffer[] getWriteBuffers()
Description copied from interface: Session
Returns the "write buffers". The returned buffers are to be written out to the client.

Specified by:
getWriteBuffers in interface Session
Returns:
the write buffers
See Also:
Session.setWriteBuffers(ByteBuffer[])

clear

protected void clear()
Clears the fields of this instance.


setSocketChannel

protected void setSocketChannel(java.nio.channels.SocketChannel channel)
Sets the socket channel.

Parameters:
channel - the new channel for which this instance encapsulates conversational state.
Throws:
java.lang.IllegalArgumentException - if channel is null
See Also:
getSocketChannel()

TopoWeb Commons API

Copyright (C) 2002 Babak Farhang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.