|
Sea 0.4.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgov.lbl.dsd.sea.nio.NetAgent
Efficient and scalable NIO based non-blocking single-threaded network agent that can be used both as a client and a server, both for TCP and UDP transports; Can handle large amounts of concurrent client and server connections in a single thread; Automatically deals with the subtle grunt work of life-cycle issues, threading, I/O multiplexing and NIO gotchas; This is the main work horse of this package.
General usage pattern:
start()
or by enqueuing a
AdminRequest.Start
gov.lbl.dsd.sea.nio.event
package via enqueue(request)
onto the agent. The agent will process the requests and enqueue responses to
the requests onto the (synchronous or asynchronous) observer stage of the
given network channel (connection), for example an AgentEventHandler
's stage.stop()
or by enqueuing a
AdminRequest.Stop
See the demo client and servers in the gov.lbl.dsd.sea.nio.demo
package for simple and complex example usage.
Whenever an IOException or EOS (end-of-stream) is encountered as a result of a channel request, the following happens, in that order:
ChannelResponse.Closed
or
ChannelResponse.Write
or
ChannelResponse.Read
or
ChannelResponse.Connected
or
ChannelResponse.Registered
, depending on
the type of request in use).ChannelResponse.Closed
response is
posted to the observer stage. The response contains the very same exception (unless
closing throws yet another exception).ChannelResponse.Closed
.
For a nice introduction to java networking, see here and there and also there .
Constructor Summary | |
NetAgent()
Constructs a new agent with default configuration options; the agent is not yet started. |
Method Summary | |
NetAgent |
addConnectAddress(Stage observer,
InetSocketAddress address)
Tells the agent to start a TCP client connection to the given remote address. |
NetAgent |
addListenPort(Stage observer,
int port)
Tells the agent to start listening as a server for TCP connections on the given port. |
void |
enqueue(Object event)
Hand a request event from the gov.lbl.dsd.sea.nio.event package
to the agent; the request will be processed the next time the agent thread
comes around the select loop. |
ByteBufferPool |
getReadBufferPool()
Returns the buffer pool to be used on reading from the network. |
void |
setAcceptHostAuthorizer(HostAuthorizer hostAuthorizer)
Sets the host authorizer the server uses to allow/deny accepting connections from the network. |
void |
setReadBufferPool(ByteBufferPool readBufferPool)
Sets the buffer pool to be used on reading from the network. |
void |
setSocketOptions(SocketOpts options)
Set the socket options to be used for newly accepted connections as well as client connections (on OP_ACCEPT and OP_CONNECT). |
void |
start()
The main selector loop; Runs the agent selector in the current thread. |
void |
stop()
Cleanly shut the agent down, releasing acquired resources. |
String |
toDebugString()
Returns a summary string representation of the receiver. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public NetAgent()
Method Detail |
public NetAgent addListenPort(Stage observer, int port) throws IOException
observer
- the stage onto which responses to the new server channel
should be enqueued (may be null)port
- the port to listen on
IOException
public NetAgent addConnectAddress(Stage observer, InetSocketAddress address) throws IOException
observer
- the stage onto which responses to the new client channel
should be enqueued (may be null)address
- the address to connect to
IOException
public void setAcceptHostAuthorizer(HostAuthorizer hostAuthorizer)
hostAuthorizer
- the host authorizer to use.public void setReadBufferPool(ByteBufferPool readBufferPool)
readBufferPool
- the pool to use.public ByteBufferPool getReadBufferPool()
public void setSocketOptions(SocketOpts options)
options
- the options to be set for the socket.public void enqueue(Object event)
gov.lbl.dsd.sea.nio.event
package
to the agent; the request will be processed the next time the agent thread
comes around the select loop.
event
- the event to hand to the agent.public void start()
public void stop()
public String toDebugString()
|
Sea 0.4.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |