ucar.unidata.collab
Class Server

java.lang.Object
  extended by ucar.unidata.collab.Server
Direct Known Subclasses:
CollabServer

public class Server
extends Object

A generic server

Version:
$Revision: 1.13 $Date: 2005/09/21 17:13:21 $
Author:
Metapps development team

Field Summary
static int DEFAULT_PORT
          _more_
 
Constructor Summary
Server()
          Create a new Server connection.
Server(int port)
          Create a new Server connection on the given port.
 
Method Summary
 void addClient(Client client)
          Add the given client to the list of clients managed by this server
 void addClient(Client client, boolean andStartListening)
          Add the given client to the list of clients managed by this server
protected  Client createClient(Socket clientSocket)
          A factory method for creating a new client.
 List getClients()
          _more_
 boolean getIsRunning()
          Get the IsRunning property.
protected  void handleIncomingMessage(Client fromClient, String message)
          Handle the message rcvd from the given client.
 boolean hasClients()
          Does this server have any clients.
protected  void initClient(Socket clientSocket)
          Create a new client object and listen for input.
protected  void logException(String msg, Exception exc)
          _more_
static void main(String[] args)
          _more_
protected  void notifyClientAdd(Client client)
          Gets called when we have added a new client.
protected  void notifyClientRemove(Client client)
          Gets called when we have removed a client.
protected  void notifyServerStart()
          Gets called when we are starting to listen
protected  void notifyServerStop()
          Gets called when we are done running on the server socket
 void removeClient(Client client)
          Remove the given client from the list of clients managed by this server
 void startServer()
          _more_
 void startServer(int newPort)
          _more_
 void stopServer()
          _more_
 void write(String message)
          _more_
 void write(String message, Client exceptClient)
          _more_
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static int DEFAULT_PORT
_more_

Constructor Detail

Server

public Server()
Create a new Server connection.


Server

public Server(int port)
Create a new Server connection on the given port.

Parameters:
port -
Method Detail

startServer

public void startServer(int newPort)
                 throws IOException
_more_

Parameters:
newPort -
Throws:
IOException

startServer

public void startServer()
                 throws IOException
_more_

Throws:
IOException

stopServer

public void stopServer()
_more_


notifyServerStart

protected void notifyServerStart()
Gets called when we are starting to listen


notifyServerStop

protected void notifyServerStop()
Gets called when we are done running on the server socket


notifyClientAdd

protected void notifyClientAdd(Client client)
Gets called when we have added a new client.

Parameters:
client -

notifyClientRemove

protected void notifyClientRemove(Client client)
Gets called when we have removed a client.

Parameters:
client -

getIsRunning

public boolean getIsRunning()
Get the IsRunning property.

Returns:
The IsRunning

createClient

protected Client createClient(Socket clientSocket)
                       throws IOException
A factory method for creating a new client.

Parameters:
clientSocket - The socket we are connected to the client with.
Returns:
a new Client
Throws:
IOException

initClient

protected void initClient(Socket clientSocket)
Create a new client object and listen for input.

Parameters:
clientSocket -

getClients

public List getClients()
_more_

Returns:
_more_

hasClients

public boolean hasClients()
Does this server have any clients.

Returns:
_more_

addClient

public void addClient(Client client)
Add the given client to the list of clients managed by this server

Parameters:
client -

addClient

public void addClient(Client client,
                      boolean andStartListening)
Add the given client to the list of clients managed by this server

Parameters:
client -
andStartListening -

removeClient

public void removeClient(Client client)
Remove the given client from the list of clients managed by this server

Parameters:
client -

handleIncomingMessage

protected void handleIncomingMessage(Client fromClient,
                                     String message)
Handle the message rcvd from the given client. The default is to just turn around and write it to each of the other clients.

Parameters:
fromClient -
message -

write

public void write(String message)
_more_

Parameters:
message -

write

public void write(String message,
                  Client exceptClient)
_more_

Parameters:
message -
exceptClient -

logException

protected void logException(String msg,
                            Exception exc)
_more_

Parameters:
msg -
exc -

main

public static void main(String[] args)
_more_

Parameters:
args -