|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--ocsf.server.ObservableServer
This class acts as a subclass of AbstractServer
and is also an Observable
class.
This means that when a message is received, all observers
are notified. In this implementation, there are two options
for notifications. Under the default anonymous notification
mode, the observers receive only the message, information about
the client that sends this message is therefore lost. In the other
option, an array of 2 elements is sent: the first one is the
message and the second one is a ConnectionToClient
object describing the client.
Field Summary | |
private AdaptableServer |
service
The service used to simulate multiple class inheritance. |
Fields inherited from class java.util.Observable |
changed,
obs |
Constructor Summary | |
ObservableServer(int port)
Constructs a new server. |
Method Summary | |
protected void |
clientConnected(ConnectionToClient client)
Hook method called each time a new client connection is accepted. |
protected void |
clientDisconnected(ConnectionToClient client)
Hook method called each time a client disconnects. |
protected void |
clientException(ConnectionToClient client,
java.lang.Throwable exception)
Hook method called each time an exception is raised in a client thread. |
void |
close()
Closes the server's connections with all clients. |
java.lang.Thread[] |
getClientConnections()
Returns an array of containing the existing client connections. |
int |
getNumberOfClients()
|
int |
getPort()
|
protected void |
handleMessageFromClient(java.lang.Object message,
ConnectionToClient client)
This method is used to handle messages coming from the client. |
boolean |
isListening()
|
void |
listen()
Begins the thread that waits for new clients |
protected void |
listeningException(java.lang.Throwable exception)
This method is called when the server stops accepting connections because an exception has been raised. |
void |
sendToAllClients(java.lang.Object msg)
Sends a message to every client connected to the server. |
protected void |
serverClosed()
This method is called when the server is closed. |
protected void |
serverPaused()
This method is called when the server briefly stop accepting connections. |
protected void |
serverStarted()
This method is called when the server starts listening for connections. |
protected void |
serverStopped()
This method is called when the server stops accepting connections for any reason. |
void |
setBacklog(int backlog)
Sets the maximum number of waiting connections accepted by the operating system. |
void |
setPort(int port)
Sets the port number for the next connection. |
void |
setTimeout(int timeout)
Sets the timeout time when accepting connection. |
void |
stopListening()
Causes the server to stop accepting new connections. |
Methods inherited from class java.util.Observable |
addObserver,
clearChanged,
countObservers,
deleteObserver,
deleteObservers,
hasChanged,
notifyObservers,
notifyObservers,
setChanged |
Methods inherited from class java.lang.Object |
|
Field Detail |
private AdaptableServer service
Constructor Detail |
public ObservableServer(int port)
port
- the port on which to listen.Method Detail |
public final void listen() throws java.io.IOException
public final void stopListening()
public final void close() throws java.io.IOException
public void sendToAllClients(java.lang.Object msg)
msg
- Object: The message to be sentpublic final boolean isListening()
public final java.lang.Thread[] getClientConnections()
Thread
containing
ConnectionToClient
instances.public final int getNumberOfClients()
public final int getPort()
public final void setPort(int port)
port
- the port number.public final void setTimeout(int timeout)
timeout
- the timeout time in ms.public final void setBacklog(int backlog)
backlog
- the maximum number of connections.protected void clientConnected(ConnectionToClient client)
client
- the connection connected to the client.protected void clientDisconnected(ConnectionToClient client)
client
- the connection with the client.protected void clientException(ConnectionToClient client, java.lang.Throwable exception)
client
- the client that raised the exception.exception
- the exception raised.protected void listeningException(java.lang.Throwable exception)
stopListening
.
This method may be overriden by subclasses.exception
- the exception raised.protected void serverPaused()
protected void serverStopped()
protected void serverClosed()
protected void serverStarted()
protected void handleMessageFromClient(java.lang.Object message, ConnectionToClient client)
message
- The message received from the client.client
- The connection to the client.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |