/** * Execute the non blocking connect operation. * @param ioEvent an {@link IOEvent} representing the current state * of the OP_CONNECT operations. */ public void onConnect(IOEvent<Context> ioEvent) { SelectionKey key = ioEvent.attachment().getSelectionKey(); if (ioEvent.attachment().getProtocol() == Controller.Protocol.TCP){ ((TCPConnectorHandler)connectorHandler).setUnderlyingChannel( (SocketChannel)key.channel()); } else if (ioEvent.attachment().getProtocol() == Controller.Protocol.TLS){ ((SSLConnectorHandler)connectorHandler).setUnderlyingChannel( (SocketChannel)key.channel()); } try { connectorHandler.finishConnect(key); } catch (IOException ex) { Controller.logger().severe(ex.getMessage()); } }
@Override public void onConnect(IOEvent<Context> ioEvent) { SelectionKey key = ioEvent.attachment().getSelectionKey(); if (connectorHandler instanceof AbstractConnectorHandler) { ((AbstractConnectorHandler) connectorHandler).setUnderlyingChannel( key.channel()); } try { connectorHandler.finishConnect(key); ioEvent.attachment().getSelectorHandler().register(key, SelectionKey.OP_READ); } catch (IOException ex) { Controller.logger().severe(ex.getMessage()); } }
/** * Delegate the processing of the read operation to the {@link IOEvent{ * associated {@link ProtocolChain} * @param ioEvent an {@link IOEvent} representing the current state of the * OP_CONNECT operations. */ public void onRead(IOEvent<Context> ioEvent) { if (!delegateToProtocolChain) return; Context context = ioEvent.attachment(); try { context.getProtocolChain().execute(context); } catch (Exception ex) { Controller.logger().log(Level.SEVERE, "Read/Write operation failed.", ex); } }
@Override public void onRead(IOEvent<Context> ioEvent) { // We don't expect any read, so if any data comes - we suppose it's "close" notification final Context context = ioEvent.attachment(); final SelectionKey selectionKey = context.getSelectionKey(); // close the channel context.getSelectorHandler().addPendingKeyCancel(selectionKey); }
public void onConnect(IOEvent<Context> ioEvent) { SelectionKey key = ioEvent.attachment().getSelectionKey(); finishConnect(key); getController().registerKey(key,SelectionKey.OP_WRITE, protocol); } public void onRead(IOEvent<Context> ioEvent) {}