jhomenet.shell.server
Class Server

java.lang.Object
  extended by java.lang.Thread
      extended by jhomenet.shell.server.Server
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
LocalServer, TelnetServer

public abstract class Server
extends java.lang.Thread

A generic server. Servers will listen on some system resource for connection requests. When someone attempts to login, the server spins off a session to handle that login. Servers are designed to be multi-threaded, allowing multiple simultaneous connections.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  boolean pauseServer
          Flag used to pause and restart the server
protected  java.util.ArrayList<Session> sessions
          List of sessions created by this server.
protected  boolean shutdown
          Stops this server when set to true.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected Server(SystemInterface systemInterface)
          Initializes the server and creates the list of sessions (initially empty).
 
Method Summary
protected abstract  Session acceptNewSession()
          Waits for a connection request.
 void broadcast(java.lang.String sendThis)
          Cycles through the list of know sessions, sending the specified message.
protected  void checkForNewSessions()
          Listens for connection requests.
protected abstract  void closeAllPorts()
          Cleans up any system resources held by this server.
 java.lang.String[] getConnectedUsers()
          Gets an array of the names of all of the users that are currently connected to this server.
 SystemInterface getSystemInterface()
           
 void pauseServer()
          Pause the server.
 void resumeServer()
          Resume the server.
 void run()
          Starts the server.
 void sessionEnded(Session session)
          Notifies this server that a particular session is ending.
 void shutDown()
          Requests that the server stop taking connections and terminate any current sessions.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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
 

Field Detail

sessions

protected java.util.ArrayList<Session> sessions
List of sessions created by this server.


shutdown

protected boolean shutdown
Stops this server when set to true.


pauseServer

protected boolean pauseServer
Flag used to pause and restart the server

Constructor Detail

Server

protected Server(SystemInterface systemInterface)
Initializes the server and creates the list of sessions (initially empty).

Method Detail

getSystemInterface

public SystemInterface getSystemInterface()

pauseServer

public void pauseServer()
Pause the server.


resumeServer

public void resumeServer()
Resume the server.


run

public void run()
Starts the server. This method continuously loops checking for new connections until the shutdown field is set to true.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

checkForNewSessions

protected void checkForNewSessions()
Listens for connection requests. This method blocks until a request is received. Once the new session is created, it is added to the list of known sessions.


acceptNewSession

protected abstract Session acceptNewSession()
Waits for a connection request. This method should block until a request is received. When a request is made, it should create, initialize, and return a new Session to handle that connection.

Returns:
a new Session

shutDown

public void shutDown()
              throws java.io.IOException
Requests that the server stop taking connections and terminate any current sessions. Cycles through the list of known sessions, closing down each one and then cleaning up its own system resources.

Throws:
java.io.IOException

sessionEnded

public void sessionEnded(Session session)
Notifies this server that a particular session is ending. Removes the closing session from the list of known sessions.

Parameters:
session - the session that has terminated

getConnectedUsers

public java.lang.String[] getConnectedUsers()
Gets an array of the names of all of the users that are currently connected to this server.

Returns:
user names of all connected users

broadcast

public void broadcast(java.lang.String sendThis)
Cycles through the list of know sessions, sending the specified message.

Parameters:
sendThis - message to send to all sessions

closeAllPorts

protected abstract void closeAllPorts()
                               throws java.io.IOException
Cleans up any system resources held by this server.

Throws:
java.io.IOException


Copyright © 2004-2005 David Irwin. All Rights Reserved.