|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
com.antelmann.net.NetConnectionServer
public class NetConnectionServer
A NetConnectionServer - once run() is called - listens to incoming requests from NetConnection objects with a signature provided by the ConnectionDispatcher. The server creates and starts a new Thread for each NetConnection with the right signature; the Thread is initialized with a Runnable object provided by the ConnectionDispatcher. The NetConnection objects used by the NetConnectionServer are SocketConnection objects.
NetConnectionHandler,
ConnectionDispatcher,
NetConnection,
SocketConnection| Nested Class Summary | |
|---|---|
static class |
NetConnectionServer.DefaultDispatcher
The DefaultDispatcher provides a default ConnectionDispatcher that is used when the NetConnectionServer constructor in the enclosing class is called with a NetConnectionHandler |
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary |
|---|
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
NetConnectionServer(int port,
ConnectionDispatcher factory)
the factory is responsible for providing the runnable objects that handle each connection in a separate thread |
|
NetConnectionServer(int port,
ConnectionDispatcher factory,
Logger logger)
|
|
NetConnectionServer(int port,
NetConnectionHandler handler,
Handshake handshake)
each connection made will run in a separate thread that delegates every message received to the given handler |
|
NetConnectionServer(int port,
NetConnectionHandler handler,
Handshake handshake,
Logger logger)
each connection made will run in a separate thread that delegates every message received to the given handler; if logger is not null, it will be used to log both: connection and message handling |
|
| Method Summary | |
|---|---|
protected void |
finalize()
|
int |
getLocalPort()
|
Logger |
getLogger()
|
List<NetConnection> |
getNetConnections()
returns an unmovifiable view of all NetConnections that have been created with this server (minus those that have been removed through removeInactiveConnections()) |
ServerSocket |
getServerSocket()
|
List<Thread> |
getThreads()
returns the list that contains all Threads that were instanciated by this server to handle incoming connections |
boolean |
isEnabled()
|
void |
removeInactiveConnections()
removes inactive connections from the maintained list of connections |
void |
run()
starts listening and creates a new Thread for every connection made. |
void |
setLogger(Logger logger)
|
void |
setThreadFactory(ThreadFactory tf)
allows to customize Thread creation for a client connection |
void |
shutdown()
shutdown() does not close the connections that have already been established |
static NetConnection |
waitForConnection(int port,
Handshake handshake,
int timeout)
listens for a single connection to be made and returns a NetConnection if the connection made matches the signature |
| 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, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public NetConnectionServer(int port,
NetConnectionHandler handler,
Handshake handshake)
throws IOException
IOException
public NetConnectionServer(int port,
NetConnectionHandler handler,
Handshake handshake,
Logger logger)
throws IOException
IOException
public NetConnectionServer(int port,
ConnectionDispatcher factory)
throws IOException
IOException
public NetConnectionServer(int port,
ConnectionDispatcher factory,
Logger logger)
throws IOException
IOException| Method Detail |
|---|
public void setThreadFactory(ThreadFactory tf)
public static NetConnection waitForConnection(int port,
Handshake handshake,
int timeout)
throws IOException
timeout - specified in milliseconds; if 0, the method waits
indefinately until a connection is made or the
serverSocket is closed
IOExceptionSocketConnection.createServerConnection(ServerSocket, Handshake)public void run()
run in interface Runnablerun in class Threadpublic Logger getLogger()
public void setLogger(Logger logger)
public List<Thread> getThreads()
public List<NetConnection> getNetConnections()
removeInactiveConnections())
removeInactiveConnections()public void removeInactiveConnections()
getNetConnections()public void shutdown()
public boolean isEnabled()
public int getLocalPort()
public ServerSocket getServerSocket()
protected void finalize()
finalize in class Object
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||