TelnetD at SF

net.wimpi.telnetd.net
Class Connection

java.lang.Object
  extended byjava.lang.Thread
      extended bynet.wimpi.telnetd.net.Connection
All Implemented Interfaces:
java.lang.Runnable

public class Connection
extends java.lang.Thread

Class that implements a connection with this telnet daemon.
It is derived from java.lang.Thread, which reflects the architecture constraint of one thread per connection. This might seem a waste of resources, but as a matter of fact sharing threads would require a far more complex imlementation, due to the fact that telnet is not a stateless protocol (i.e. alive throughout a session of multiple requests and responses).
Each Connection instance is created by the listeners ConnectionManager instance, making it part of a threadgroup and passing in an associated ConnectionData instance, that holds vital information about the connection. Be sure to take a look at their documention.

Once the thread has started and is running, it will get a login shell instance from the ShellManager and run passing its own reference.

Version:
2.0 (13/03/2005)
Author:
Dieter Wimberger
See Also:
ConnectionManager, ConnectionData, ShellManager, TerminalIO

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Connection(java.lang.ThreadGroup tcg, ConnectionData cd)
          Constructs a TelnetConnection by invoking its parent constructor and setting of various members.
 
Method Summary
 void addConnectionListener(ConnectionListener cl)
          Method that registers a ConnectionListener with the Connection instance.
 void close()
          Closes the connection and its underlying i/o and network resources.
 ConnectionData getConnectionData()
          Method to access the associated connection data.
 BasicTerminalIO getTerminalIO()
          Method to access the associated terminal io.
 boolean isActive()
          Returns if a connection has been closed.
 void processConnectionEvent(ConnectionEvent ce)
          Method called by the io subsystem to pass on a "low-level" event.
 void removeConnectionListener(ConnectionListener cl)
          Method that removes a ConnectionListener from the Connection instance.
 void run()
          Method overloaded to implement following behaviour: On first entry, retrieve an instance of the configured login shell from the ShellManager and run it.
 boolean setNextShell(java.lang.String name)
          Method to prepare the Connection for a shell switch.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Connection

public Connection(java.lang.ThreadGroup tcg,
                  ConnectionData cd)
Constructs a TelnetConnection by invoking its parent constructor and setting of various members.
Subsequently instantiates the whole i/o subsystem, negotiating telnet protocol level options etc.

Parameters:
tcg - ThreadGroup that this instance is running in.
cd - ConnectionData instance containing all vital information of this connection.
See Also:
ConnectionData
Method Detail

run

public void run()
Method overloaded to implement following behaviour:
  1. On first entry, retrieve an instance of the configured login shell from the ShellManager and run it.
  2. Handle a shell switch or close down disgracefully when problems (i.e. unhandled unchecked exceptions) occur in the running shell.


getConnectionData

public ConnectionData getConnectionData()
Method to access the associated connection data.

Returns:
ConnectionData associated with the Connection instance.
See Also:
ConnectionData

getTerminalIO

public BasicTerminalIO getTerminalIO()
Method to access the associated terminal io.

Returns:
BasicTerminalIO associated with the Connection instance.
See Also:
BasicTerminalIO

setNextShell

public boolean setNextShell(java.lang.String name)
Method to prepare the Connection for a shell switch.
A shell instance will be acquired from the ShellManager according to the given name.
In case of a nonexistant name the return will be false, otherwise true.

Parameters:
name - String that should represent a valid shell name.
Returns:
boolean flagging if the request could be carried out correctly.
See Also:
ShellManager

close

public void close()
Closes the connection and its underlying i/o and network resources.


isActive

public boolean isActive()
Returns if a connection has been closed.

Returns:
the state of the connection.

addConnectionListener

public void addConnectionListener(ConnectionListener cl)
Method that registers a ConnectionListener with the Connection instance.

Parameters:
cl - ConnectionListener to be registered.
See Also:
ConnectionListener

removeConnectionListener

public void removeConnectionListener(ConnectionListener cl)
Method that removes a ConnectionListener from the Connection instance.

Parameters:
cl - ConnectionListener to be removed.
See Also:
ConnectionListener

processConnectionEvent

public void processConnectionEvent(ConnectionEvent ce)
Method called by the io subsystem to pass on a "low-level" event. It will be properly delegated to all registered listeners.

Parameters:
ce - ConnectionEvent to be processed.
See Also:
ConnectionEvent

TelnetD at SF

Copyright 2000-2005 Dieter Wimberger.