net.directj.csf
Interface Server

All Superinterfaces:
java.lang.Runnable
All Known Implementing Classes:
ServerImpl

public interface Server
extends java.lang.Runnable

This a simple interface to implements a network server. It is a quite simple class, but it is powerfull enough to realize any networking application.

Version:
0.1.3
Author:
CARTAPANIS Alexandre <earendil@jprolog.net>

Method Summary
 void addServerListener(ServerListener _listener)
          Adds a server listener to this class.
 void fireEvent(ServerEvent _evt)
          Send a server event to the listeners
 java.net.InetAddress getInetAddress()
          Returns the address of the endpoint this server is listening to.
 java.lang.String getInfo()
          Returns the server's informations (port, address, version...).
 int getMaximumClient()
          Returns the maximum amount of client the server can handle.
 java.lang.String getName()
          Returns the server's name.
 int getPort()
          Returns the port on which this server is listening.
 java.lang.String getStatus()
          Returns the server's status (state, number of connection, ...).
 boolean isRunning()
          Indicates if the server is running or not.
 void killClient(java.lang.String _address)
          Kills a client identified by his hostname or IP address.
 void removeAllServerListener()
          Removes all the listeners associated with this class.
 void removeServerListener(ServerListener _listener)
          Removes a specified server listener from the list.
 void setClientHandlerFactory(ClientHandlerFactory _factory)
          Sets the ClientHandlerFactory.
 void setInetAddress(java.net.InetAddress _address)
          Changes the server's address.
 void setMaximumClient(int _max)
          Changes the server's maximum client amount.
 void setName(java.lang.String _name)
          Changes the server's name.
 void setPort(int _port)
          Changes the server's port.
 void setServerSocketFactory(javax.net.ServerSocketFactory _factory)
          Sets the ServerSocketFactory.
 void startServer()
          Starts the server.
 void stopServer()
          Stops the server.
 java.lang.String toString()
          Returns a string representation of this server.
 
Methods inherited from interface java.lang.Runnable
run
 

Method Detail

startServer

public void startServer()
Starts the server.


stopServer

public void stopServer()
Stops the server.


isRunning

public boolean isRunning()
Indicates if the server is running or not.

Returns:
boolean - True if the server is running and ready to accept client, false otherwise.

killClient

public void killClient(java.lang.String _address)
Kills a client identified by his hostname or IP address. If the address does not correspond to any connected client, nothing happens. If the _address correspond to more than one client (for example when the same machine have more than one client connected to this server), then all clients are killed.

Parameters:
_address - The address of the client we want to kill.

setClientHandlerFactory

public void setClientHandlerFactory(ClientHandlerFactory _factory)
                             throws java.lang.IllegalStateException,
                                    java.lang.IllegalArgumentException
Sets the ClientHandlerFactory. The factory is used to create the client handler that will be in charge of manage a client's requests and asnwers. Cannot be used if the server is running.

Parameters:
_factory - The client handler factory.
Throws:
java.lang.IllegalStateException - If the server is running.
java.lang.IllegalArgumentException - If the ClientHandlerFactory is not valid or has not been initialized.

setServerSocketFactory

public void setServerSocketFactory(javax.net.ServerSocketFactory _factory)
                            throws java.lang.IllegalStateException,
                                   java.lang.IllegalArgumentException
Sets the ServerSocketFactory. The factory is used to create the server socket. Cannot be used if the server is running.

Parameters:
_factory - The server socket factory.
Throws:
java.lang.IllegalStateException - If the server is running.
java.lang.IllegalArgumentException - If the ServerSocketFactory is not valid or has not been initialized.

addServerListener

public void addServerListener(ServerListener _listener)
Adds a server listener to this class.

Parameters:
_listener - The Listener to add.

removeServerListener

public void removeServerListener(ServerListener _listener)
Removes a specified server listener from the list.

Parameters:
_listener - The Listener to remove.

removeAllServerListener

public void removeAllServerListener()
Removes all the listeners associated with this class.


fireEvent

public void fireEvent(ServerEvent _evt)
Send a server event to the listeners

Parameters:
_evt - The event to be fired.

getInfo

public java.lang.String getInfo()
Returns the server's informations (port, address, version...).

Returns:
String - The server's informations.

getStatus

public java.lang.String getStatus()
Returns the server's status (state, number of connection, ...).

Returns:
String - The server's status.

getPort

public int getPort()
Returns the port on which this server is listening.

Returns:
int - The port number to which this server is listening.

setPort

public void setPort(int _port)
             throws java.lang.IllegalStateException,
                    java.lang.IllegalArgumentException
Changes the server's port. Cannot be used if the server is running. The port must be between 0 and 65535, inclusive.

Parameters:
_port - The new server's port.
Throws:
java.lang.IllegalStateException - If the server is running.
java.lang.IllegalArgumentException - If the port is not valid.

getInetAddress

public java.net.InetAddress getInetAddress()
Returns the address of the endpoint this server is listening to.

Returns:
InetAddress - A InetAddress representing the local endpoint of this server.

setInetAddress

public void setInetAddress(java.net.InetAddress _address)
                    throws java.lang.IllegalStateException,
                           java.lang.IllegalArgumentException
Changes the server's address. Cannot be used if the server is running. The _address argument can be used on a multi-homed host for a server that will only accept connect requests to one of its addresses.

Parameters:
_address - The new server's address.
Throws:
java.lang.IllegalStateException - If the server is running.
java.lang.IllegalArgumentException - If the address is not valid.

getName

public java.lang.String getName()
Returns the server's name.

Returns:
String - The server's name.

setName

public void setName(java.lang.String _name)
             throws java.lang.IllegalStateException
Changes the server's name. Cannot be used if the server is running. If the specified _name is null, then the current name isnot modified.

Parameters:
_name - The new server's name.
Throws:
java.lang.IllegalStateException - If the server is running.

getMaximumClient

public int getMaximumClient()
Returns the maximum amount of client the server can handle.

Returns:
int - The maximum client amount.

setMaximumClient

public void setMaximumClient(int _max)
                      throws java.lang.IllegalArgumentException
Changes the server's maximum client amount. If the new size is greater than the current size, nothing happens. If the new size is less than the current size, all components at index _max and greater are discarded.

Parameters:
_max - The new maximum client amount.
Throws:
java.lang.IllegalArgumentException - If the specified number is not valid.

toString

public java.lang.String toString()
Returns a string representation of this server.

Overrides:
toString in class java.lang.Object
Returns:
String - A string representation of this server.


Copyright 2002 CARTAPANIS Alexandre
This page was last updated on May 10 2003