public class PerpetualSocketAcceptor extends SocketAcceptor
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.
socketlistenerList| Constructor and Description |
|---|
PerpetualSocketAcceptor() |
PerpetualSocketAcceptor(ConnectionModel model) |
PerpetualSocketAcceptor(ConnectionModel model,
int backlog) |
| Modifier and Type | Method and Description |
|---|---|
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.
|
getConnectionModel, open, setConnectionModel, setConnectionModelfireConnectionClosed, fireConnectionEstablishedaddConnectionListener, fireConnectionStarting, fireConnectionStartingWithoutVeto, removeConnectionListenerpublic PerpetualSocketAcceptor()
public PerpetualSocketAcceptor(ConnectionModel model) throws java.io.IOException
java.io.IOExceptionpublic PerpetualSocketAcceptor(ConnectionModel model, int backlog) throws java.io.IOException
java.io.IOExceptionpublic 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 SocketAcceptorpublic 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 SocketAcceptorpublic void close()
close in class SocketAcceptorCopyright © 2001-2005 Echomine. All Rights Reserved.