to.etc.telnet
Class TelnetSession

java.lang.Object
  extended by to.etc.telnet.TelnetStateThing
      extended by to.etc.telnet.TelnetSession
All Implemented Interfaces:
java.lang.Runnable

public class TelnetSession
extends TelnetStateThing
implements java.lang.Runnable

Encapsulates a single session. A session consists of the socket used to talk with the peer, a thread used to read() the socket and to accept input, and an instance of this class.

Author:
Frits Jalvingh

Field Summary
 
Fields inherited from class to.etc.telnet.TelnetStateThing
tsDOWN, tsINITING, tsNONE, tsRUN, tsSHUT
 
Constructor Summary
protected TelnetSession(TelnetServer srv, java.net.Socket s)
          This constructor will only be called by TelnetServer.
 
Method Summary
 void _write(java.lang.String s)
          Writes a stream of characters to the stream.
 void close()
          Called when the session MUST close.
 java.lang.Object get(java.lang.String name)
          Removes a client data thing from this-session's session data.
 java.lang.String getName()
          Returns a session name from the IP address and the port.
 void init()
          Called after construction before this session is fully accepted, this retrieves all data, opens the streams and starts the reader thread.
 void put(java.lang.String n, java.lang.Object o)
          Adds a client data thing to this-session's session data.
 void run()
          The actual reader thread's main code.
 void write(java.lang.String s)
          Writes a string to this terminal.
 
Methods inherited from class to.etc.telnet.TelnetStateThing
getState, getStateString, inState, setState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TelnetSession

protected TelnetSession(TelnetServer srv,
                        java.net.Socket s)
This constructor will only be called by TelnetServer.

Method Detail

getName

public java.lang.String getName()
Returns a session name from the IP address and the port.


init

public void init()
          throws java.lang.Exception
Called after construction before this session is fully accepted, this retrieves all data, opens the streams and starts the reader thread. If all works then the session will be accepted.

Throws:
java.lang.Exception

write

public void write(java.lang.String s)
           throws java.lang.Exception
Writes a string to this terminal. If the mode is not NORMAL then the lines are cached.

Throws:
java.lang.Exception

_write

public void _write(java.lang.String s)
            throws java.lang.Exception
Writes a stream of characters to the stream. If the write causes an error this session gets closed and will be released. This call is synchronized. If the session is not in running state the call returns silently. This call does NOT respect input mode and the like!

Throws:
java.lang.Exception

close

public void close()
Called when the session MUST close.


run

public void run()
The actual reader thread's main code. Basically reads data till EOF.

Specified by:
run in interface java.lang.Runnable

put

public void put(java.lang.String n,
                java.lang.Object o)
Adds a client data thing to this-session's session data.


get

public java.lang.Object get(java.lang.String name)
Removes a client data thing from this-session's session data.