|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dellroad.stuff.net.SocketAcceptor
public abstract class SocketAcceptor
Spring bean that listens for connections on a TCP socket and spawns a child thread to handle each new connection.
Subclasses must implement getSocketHandler(java.net.Socket). Only the port property is required to be set.
| Field Summary | |
|---|---|
static int |
DEFAULT_BACKLOG
Default maximum incoming connection queue length (50). |
protected Logger |
log
|
| Constructor Summary | |
|---|---|
SocketAcceptor()
|
|
| Method Summary | |
|---|---|
void |
afterPropertiesSet()
Verifies configuration and invokes start(). |
protected ServerSocket |
createServerSocket()
Create the server's socket via which connections will be accepted. |
void |
destroy()
Invokes stop(). |
int |
getBacklog()
Get maximum connect backlog. |
InetAddress |
getInetAddress()
Get address to listen on. |
int |
getMaxConnections()
Get maximum number of concurrent connections. |
int |
getPort()
Get TCP port to listen on. |
protected abstract SocketHandler |
getSocketHandler(Socket socket)
Get the SocketHandler that will handle a new connection using the given socket. |
void |
setBacklog(int backlog)
|
void |
setInetAddress(InetAddress address)
|
void |
setMaxConnections(int maxConnections)
|
void |
setPort(int port)
|
void |
start()
Start accepting incoming connections. |
void |
stop()
Stop accepting connections. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_BACKLOG
setBacklog(int),
Constant Field Valuesprotected final Logger log
| Constructor Detail |
|---|
public SocketAcceptor()
| Method Detail |
|---|
public void afterPropertiesSet()
throws Exception
start().
afterPropertiesSet in interface InitializingBeanException
public void destroy()
throws Exception
stop().
destroy in interface DisposableBeanExceptionpublic InetAddress getInetAddress()
public void setInetAddress(InetAddress address)
public int getBacklog()
public void setBacklog(int backlog)
public int getMaxConnections()
public void setMaxConnections(int maxConnections)
public int getPort()
public void setPort(int port)
public void start()
throws IOException
IOExceptionpublic void stop()
Any currently active connections are stopped via SocketHandler.stop(),
and this method waits until all such connections have returned from SocketHandler.handleConnection() before returning.
protected ServerSocket createServerSocket()
throws IOException
The implementation in SocketAcceptor creates the socket and sets the "reuse address" flag.
Subclasses may override.
IOException
protected abstract SocketHandler getSocketHandler(Socket socket)
throws IOException
SocketHandler that will handle a new connection using the given socket.
null to disconnect the socket immediately
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||