|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.grizzly.AbstractConnectorHandler<TCPSelectorHandler,CallbackHandler>
com.sun.grizzly.TCPConnectorHandler
public class TCPConnectorHandler
Non blocking TCP Connector Handler. The recommended way to use this class is by creating an external Controller and share the same SelectorHandler instance.
Recommended -----------
Controller controller = new Controller();
// new TCPSelectorHandler(true) means the Selector will be used only
// for client operation (OP_READ, OP_WRITE, OP_CONNECT).
TCPSelectorHandler tcpSelectorHandler = new TCPSelectorHandler(true);
controller.setSelectorHandler(tcpSelectorHandler);
TCPConnectorHandler tcpConnectorHandler = new TCPConnectorHandler();
tcpConnectorHandler.connect(localhost,port, new CallbackHandler(){...},
tcpSelectorHandler);
TCPConnectorHandler tcpConnectorHandler2 = new TCPConnectorHandler();
tcpConnectorHandler2.connect(localhost,port, new CallbackHandler(){...},
tcpSelectorHandler);
Not recommended (but still works) ---------------------------------
TCPConnectorHandler tcpConnectorHandler = new TCPConnectorHandler();
tcpConnectorHandler.connect(localhost,port);
Internally, a new Controller will be created everytime connect(localhost,port) is invoked, which has an impact on performance.
| Field Summary | |
|---|---|
protected int |
connectionTimeout
Connection timeout is milliseconds |
protected int |
linger
The socket linger. |
protected boolean |
reuseAddress
The socket reuseAddress |
protected boolean |
tcpNoDelay
The socket tcpDelay. |
| Fields inherited from class com.sun.grizzly.AbstractConnectorHandler |
|---|
callbackHandler, controller, inputStream, isConnected, protocol, selectorHandler, underlyingChannel |
| Constructor Summary | |
|---|---|
TCPConnectorHandler()
|
|
| Method Summary | |
|---|---|
void |
close()
Close the underlying connection. |
void |
configureChannel(java.nio.channels.SelectableChannel channel)
|
void |
connect(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress)
Connect to hostname:port. |
void |
connect(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress,
CallbackHandler callbackHandler,
TCPSelectorHandler selectorHandler)
Connect to hostname:port. |
void |
finishConnect(java.nio.channels.SelectionKey key)
Finish handling the OP_CONNECT interest ops. |
int |
getConnectionTimeout()
Get TCP channel connection timeout in milliseconds |
int |
getLinger()
|
boolean |
isReuseAddress()
|
boolean |
isTcpNoDelay()
Return the tcpNoDelay value used by the underlying accepted Sockets. |
Controller.Protocol |
protocol()
A token decribing the protocol supported by an implementation of this interface |
void |
setConnectionTimeout(int connectionTimeout)
Set TCP channel connection timeout in milliseconds |
void |
setLinger(int linger)
|
void |
setReuseAddress(boolean reuseAddress)
|
void |
setTcpNoDelay(boolean tcpNoDelay)
Enable (true) or disable (false) the underlying Socket's tcpNoDelay. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected boolean tcpNoDelay
protected boolean reuseAddress
protected int linger
protected int connectionTimeout
| Constructor Detail |
|---|
public TCPConnectorHandler()
| Method Detail |
|---|
public void connect(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress,
CallbackHandler callbackHandler,
TCPSelectorHandler selectorHandler)
throws java.io.IOException
Controller will invoke
the CallBackHandler.
remoteAddress - remote address to connectlocalAddress - local address to bincallbackHandler - the handler invoked by its associated SelectorHandler when
a non blocking operation is ready to be handled. When null, all
read and write operation will be delegated to the default
ProtocolChain and its list of ProtocolFilter
. When null, this ConnectorHandler will create an instance of DefaultCallbackHandler.selectorHandler - an instance of SelectorHandler.
java.io.IOException
public void connect(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress)
throws java.io.IOException
remoteAddress - remote address to connectlocalAddress - local address to bin
java.io.IOException
public void close()
throws java.io.IOException
java.io.IOException
public void finishConnect(java.nio.channels.SelectionKey key)
throws java.io.IOException
key - - a SelectionKey
java.io.IOException
public void configureChannel(java.nio.channels.SelectableChannel channel)
throws java.io.IOException
java.io.IOExceptionpublic final Controller.Protocol protocol()
protocol in interface ConnectorHandler<TCPSelectorHandler,CallbackHandler>protocol in class AbstractConnectorHandler<TCPSelectorHandler,CallbackHandler>ConnectorHandler's protocolpublic boolean isTcpNoDelay()
public void setTcpNoDelay(boolean tcpNoDelay)
public int getLinger()
java.net.Socket#setLinger()public void setLinger(int linger)
java.net.Socket#setLinger()public int getConnectionTimeout()
public void setConnectionTimeout(int connectionTimeout)
connectionTimeout - TCP channel connection timeout in millisecondspublic boolean isReuseAddress()
java.net.Socket#setReuseAddress()public void setReuseAddress(boolean reuseAddress)
java.net.Socket#setReuseAddress()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||