|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.echomine.net.Connection
com.echomine.net.TimeableConnection
com.echomine.net.SocketAcceptor
com.echomine.net.PerpetualSocketAcceptor
public class PerpetualSocketAcceptor
Accepts connections indefinitely. Once a connection is accepted, it is immediately handled in a spawned thread. The acceptor will go back to receiving more connections.
The acceptor offers both a synchronous and asynchronous version of accept. Running perpetually, this means that (1) synchronous accept will accept and handle one connection at a time and (2) asynchronous accept will accept, hand it to a handler in a different thread, then go back to accept more connections (ie. a daemon). Depending on which suits your situation, use the appropriate method.
Perpetual Acceptor also support firiing off of connection events.
NOTE: Using this class requires that the handler is multi-threading safe if asynchronous accept is used (doesn't apply to synchronous accept). This means for async accepts, the handler cannot contain any per-connection data. Otherwise, you'll get into data corruption because of multi-threading issues.
Field Summary |
---|
Fields inherited from class com.echomine.net.SocketAcceptor |
---|
socket |
Fields inherited from class com.echomine.net.Connection |
---|
listenerList |
Constructor Summary | |
---|---|
PerpetualSocketAcceptor()
|
|
PerpetualSocketAcceptor(ConnectionModel model)
|
|
PerpetualSocketAcceptor(ConnectionModel model,
int backlog)
|
Method Summary | |
---|---|
void |
aaccept(SocketHandler socketHandler)
Accepts a connection,hands it over to the handler for processing, and immediately goes back to accepting more connections. |
void |
accept(SocketHandler socketHandler)
Accepts a connection and hands it over to the handler for processing one at a time. |
void |
close()
Closes the server socket, unbind from the port, and shuts down the perpetual loops. |
Methods inherited from class com.echomine.net.SocketAcceptor |
---|
getConnectionModel, open, setConnectionModel, setConnectionModel |
Methods inherited from class com.echomine.net.TimeableConnection |
---|
fireConnectionClosed, fireConnectionEstablished |
Methods inherited from class com.echomine.net.Connection |
---|
addConnectionListener, fireConnectionStarting, fireConnectionStartingWithoutVeto, removeConnectionListener |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PerpetualSocketAcceptor()
public PerpetualSocketAcceptor(ConnectionModel model) throws java.io.IOException
java.io.IOException
public PerpetualSocketAcceptor(ConnectionModel model, int backlog) throws java.io.IOException
java.io.IOException
Method Detail |
---|
public void accept(SocketHandler socketHandler)
Accepts a connection and hands it over to the handler for processing one at a time.
To stop the daemon from accepting more connections, just call the close method.
The method will return immediately and run the daemon in a background thread.
accept
in class SocketAcceptor
public void aaccept(SocketHandler socketHandler)
Accepts a connection,hands it over to the handler for processing, and immediately goes back to accepting more connections. This differs from the regular accept method in that it does not process connections one at a time.
The async accept is a little more intricate than the sync accept since it can't just use SocketAcceptor.aaccept().
The method returns immediately and runs the daemon in a background thread.
aaccept
in class SocketAcceptor
public void close()
close
in class SocketAcceptor
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |