|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--net.directj.csf.impl.ServerImpl
This a simple implementation of network server. It is a quite simple class, but it is powerfull enough to realize any networking application.
| Nested Class Summary | |
private class |
ServerImpl.ShutdownHook
This class is used to stop the server at the end of the JVM. |
| Field Summary | |
private java.net.InetAddress |
address
The local endpoint of this server. |
private java.util.Vector |
clients
The list of connected clients. |
static java.lang.String |
DEFAULT_NAME
The default name. |
private ClientHandlerFactory |
handlerFactory
The factory that will be used to create the ClientHandler. |
private java.util.Vector |
listeners
The list of listeners. |
static int |
MAX_CLIENT
The default maximum client amount. |
private int |
maxClient
The maximum client amount. |
private java.lang.String |
name
The server's name. |
private int |
port
The port number to which this server is listening. |
private java.lang.Thread |
runner
The server thread. |
private boolean |
running
Indicates if the server is running or not. |
private java.net.ServerSocket |
serverSock
The server's socket. |
private javax.net.ServerSocketFactory |
socketFactory
The factory that will be used to create the ServerSocket. |
static java.lang.String |
VERSION
The server's version. |
| Constructor Summary | |
ServerImpl()
Creates a new server implementation. |
|
| Method Summary | |
void |
addServerListener(ServerListener _listener)
Adds a server listener to this class. |
void |
fireEvent(ServerEvent _evt)
Send a server event to the listeners |
private void |
getClient()
Waits for the client to connect. |
java.net.InetAddress |
getInetAddress()
Returns the address of the endpoint this server is listening to. |
java.lang.String |
getInfo()
Returns the server 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 status (idle, 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 |
run()
Runs the server. |
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 class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.String VERSION
public static final int MAX_CLIENT
public static final java.lang.String DEFAULT_NAME
private java.lang.String name
private java.net.ServerSocket serverSock
private javax.net.ServerSocketFactory socketFactory
private int port
private java.net.InetAddress address
private int maxClient
private java.util.Vector clients
private ClientHandlerFactory handlerFactory
private java.util.Vector listeners
private volatile boolean running
private java.lang.Thread runner
| Constructor Detail |
public ServerImpl()
| Method Detail |
public void startServer()
startServer in interface Serverpublic void stopServer()
stopServer in interface Serverpublic void run()
run in interface java.lang.Runnablepublic boolean isRunning()
isRunning in interface Serverboolean - True if the server is running and ready to accept client, false otherwise.private void getClient()
public void killClient(java.lang.String _address)
killClient in interface Server_address - The address of the client we want to kill.
public void setClientHandlerFactory(ClientHandlerFactory _factory)
throws java.lang.IllegalStateException,
java.lang.IllegalArgumentException
setClientHandlerFactory in interface Server_factory - The client handler factory.
java.lang.IllegalStateException - If the server is running.
java.lang.IllegalArgumentException - If the ClientHandlerFactory is not valid or has not been initialized.
public void setServerSocketFactory(javax.net.ServerSocketFactory _factory)
throws java.lang.IllegalStateException,
java.lang.IllegalArgumentException
setServerSocketFactory in interface Server_factory - The server socket factory.
java.lang.IllegalStateException - If the server is running.
java.lang.IllegalArgumentException - If the ClientHandlerFactory is not valid or has not been initialized.public void fireEvent(ServerEvent _evt)
fireEvent in interface Server_evt - The event to be fired.public void addServerListener(ServerListener _listener)
addServerListener in interface Server_listener - The Listener to add.public void removeServerListener(ServerListener _listener)
removeServerListener in interface Server_listener - The Listener to remove.public void removeAllServerListener()
removeAllServerListener in interface Serverpublic java.lang.String getInfo()
getInfo in interface ServerString - The server's informations.public java.lang.String getStatus()
getStatus in interface ServerString - The server's status.public java.lang.String toString()
toString in interface ServertoString in class java.lang.ObjectString - A string representation of this server.public int getPort()
getPort in interface Serverint - The port number to which this server is listening.
public void setPort(int _port)
throws java.lang.IllegalStateException,
java.lang.IllegalArgumentException
setPort in interface Server_port - The new server's port.
java.lang.IllegalStateException - If the server is running.
java.lang.IllegalArgumentException - If the port is not valid.public java.net.InetAddress getInetAddress()
getInetAddress in interface ServerInetAddress - A InetAddress representing the local endpoint of this server.
public void setInetAddress(java.net.InetAddress _address)
throws java.lang.IllegalStateException,
java.lang.IllegalArgumentException
setInetAddress in interface Server_address - The new server's address.
java.lang.IllegalStateException - If the server is running.
java.lang.IllegalArgumentException - If the address is not valid.public java.lang.String getName()
getName in interface ServerString - The server's name.
public void setName(java.lang.String _name)
throws java.lang.IllegalStateException
setName in interface Server_name - The new server's name.
java.lang.IllegalStateException - If the server is running.public int getMaximumClient()
getMaximumClient in interface Serverint - The maximum client amount.
public void setMaximumClient(int _max)
throws java.lang.IllegalArgumentException
setMaximumClient in interface Server_max - The new maximum client amount.
java.lang.IllegalArgumentException - If the specified number is not valid.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||