public ConnectorHandler acquireConnectorHandler(Protocol protocol){ ConnectorHandler ch = null; SelectorHandler selectorHandler = controller.getSelectorHandler(protocol); if (selectorHandler != null) { ch = selectorHandler.acquireConnectorHandler(); ch.setController(controller); } return ch; }
public void releaseConnectorHandler(ConnectorHandler connectorHandler){ SelectorHandler selectorHandler = controller.getSelectorHandler(connectorHandler.protocol()); if (selectorHandler != null) { selectorHandler.releaseConnectorHandler(connectorHandler); } } }
/** * Register a SelectionKey. * @param key <tt>SelectionKey</tt> to register * @param ops - the interest op to register * @param protocol specified protocol SelectorHandler key should be registered on */ public void registerKey(SelectionKey key, int ops, Protocol protocol){ if (stateHolder.getState() == State.STOPPED) { return; } getSelectorHandler(protocol).register(key,ops); }
/** * Connect to hostname:port. When an aysnchronous event happens (e.g * OP_READ or OP_WRITE), the {@link Controller} will invoke * the CallBackHandler. * @param remoteAddress remote address to connect * @param localAddress local address to bind * @param callbackHandler the handler invoked by its associated {@link SelectorHandler} when * a non blocking operation is ready to be handled. When null, all * read and write operation will be delegated to the default * {@link ProtocolChain} and its list of {@link ProtocolFilter} * . When null, this {@link ConnectorHandler} will create an instance of {@link DefaultCallbackHandler}. * @throws java.io.IOException */ public void connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler) throws IOException { if (controller == null){ throw new IllegalStateException("Controller cannot be null"); } connect(remoteAddress,localAddress,callbackHandler, (TCPSelectorHandler)controller.getSelectorHandler(protocol())); }
/** * Connect to hostname:port. When an aysnchronous event happens (e.g * OP_READ or OP_WRITE), the {@link Controller} will invoke * the {@link CallbackHandler}. * @param remoteAddress remote address to connect * @param localAddress local address to bind * @param callbackHandler the handler invoked by its associated {@link SelectorHandler} when * a non blocking operation is ready to be handled. When null, all * read and write operation will be delegated to the default * {@link ProtocolChain} and its list of {@link ProtocolFilter} * . When null, this {@link ConnectorHandler} will create an instance of {@link DefaultCallbackHandler}. * @throws java.io.IOException */ public void connect(SocketAddress remoteAddress, SocketAddress localAddress, SSLCallbackHandler callbackHandler) throws IOException { if (controller == null) { throw new IllegalStateException("Controller cannot be null"); } connect(remoteAddress, localAddress, callbackHandler, (SSLSelectorHandler) controller.getSelectorHandler(protocol())); }
/** * Connect to hostname:port. When an aysnchronous event happens (e.g * OP_READ or OP_WRITE), the {@link Controller} will invoke * the CallBackHandler. * @param remoteAddress remote address to connect * @param localAddress local address to bind * @param callbackHandler the handler invoked by its associated {@link SelectorHandler} when * a non blocking operation is ready to be handled. When null, all * read and write operation will be delegated to the default * {@link ProtocolChain} and its list of {@link ProtocolFilter} * . When null, this {@link ConnectorHandler} will create an instance of {@link DefaultCallbackHandler}. */ public void connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler) throws IOException { if (controller == null){ throw new IllegalStateException("Controller cannot be null"); } connect(remoteAddress,localAddress,callbackHandler, (UDPSelectorHandler)controller.getSelectorHandler(protocol())); }
/** * Cancel a SelectionKey * @param key <tt>SelectionKey</tt> to cancel * @deprecated */ public void cancelKey(SelectionKey key){ if (stateHolder.getState() == State.STOPPED) { return; } SelectorHandler selectorHandler = getSelectorHandler(key.selector()); if (selectorHandler != null) { selectorHandler.getSelectionKeyHandler().cancel(key); } else { throw new IllegalStateException("SelectionKey is not associated " + "with known SelectorHandler"); } }
controller.getSelectorHandler(protocol()));
(UDPSelectorHandler)controller.getSelectorHandler(protocol()));
(TCPSelectorHandler)controller.getSelectorHandler(protocol()));