List of usage examples for java.nio.channels SelectionKey OP_READ
int OP_READ
To view the source code for java.nio.channels SelectionKey OP_READ.
Click Source Link
From source file:org.apache.synapse.transport.utils.logging.LoggingIOSession.java
private static String formatOps(int ops) { StringBuilder buffer = new StringBuilder(6); buffer.append('['); if ((ops & SelectionKey.OP_READ) > 0) { buffer.append('r'); }/* ww w .ja v a 2 s . c o m*/ if ((ops & SelectionKey.OP_WRITE) > 0) { buffer.append('w'); } if ((ops & SelectionKey.OP_ACCEPT) > 0) { buffer.append('a'); } if ((ops & SelectionKey.OP_CONNECT) > 0) { buffer.append('c'); } buffer.append(']'); return buffer.toString(); }
From source file:me.xingrz.prox.tcp.tunnel.Tunnel.java
/** * ?// w w w .ja va2s. c om */ public final void beginReceiving() { try { if (channel.isBlocking()) { channel.configureBlocking(false); } channel.register(selector, SelectionKey.OP_READ, this); } catch (IOException e) { logger.w(e, "Failed to begin receiving, close"); IOUtils.closeQuietly(this); } }
From source file:com.github.neoio.nio.util.NIOUtils.java
public static SocketChannel openClientSocket(Selector selector, SocketAddress endPointAddress) throws NetSocketException { SocketChannel toReturn;/* w w w. ja v a2s.c o m*/ try { toReturn = SocketChannel.open(endPointAddress); toReturn.configureBlocking(false); toReturn.register(selector, SelectionKey.OP_READ); } catch (IOException e) { logger.error("IOException occurred while opening client socket", e); toReturn = null; } return toReturn; }
From source file:com.ok2c.lightmtp.impl.protocol.ExtendedSendHeloCodec.java
@Override public void reset(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { this.parser.reset(); this.writer.reset(); this.codecState = CodecState.SERVICE_READY_EXPECTED; iosession.setEventMask(SelectionKey.OP_READ); }
From source file:com.tera.common.network.nio.MMOConnection.java
protected MMOConnection(PacketService packetService, SelectorThread selectorThread, SocketChannel socketChannel) throws ClosedChannelException { super(packetService); this.selectorThread = selectorThread; this.readWriteThread = getSelectorThread().getReadWriteThread(); this.socket = socketChannel.socket(); this.inetAddress = socket.getInetAddress(); this.hostAddress = inetAddress.getHostAddress(); this.selectionKey = socketChannel.register(getReadWriteThread().getSelector(), SelectionKey.OP_READ); this.selectionKey.attach(this); setChannelState(ChannelState.CONNECTED); connectionId = idFactory.nextId();//TODO deallocate after disconnect }
From source file:com.ok2c.lightmtp.impl.protocol.PipeliningSendEnvelopCodec.java
@Override public void reset(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); this.writer.reset(); this.parser.reset(); this.recipients.clear(); this.codecState = CodecState.MAIL_REQUEST_READY; this.deliveryFailed = false; if (sessionState.getRequest() != null) { iosession.setEvent(SelectionKey.OP_WRITE); } else {//from w w w . ja va 2 s .c om iosession.setEvent(SelectionKey.OP_READ); } }
From source file:edu.tsinghua.lumaqq.qq.net.Porter.java
/** * portporter/*from w w w . j a v a 2 s .c o m*/ * * @param port * IPort * @throws ClosedChannelException * */ public void register(IPort port) throws ClosedChannelException { SelectableChannel channel = port.channel(); if (channel instanceof SocketChannel) channel.register(selector, SelectionKey.OP_CONNECT, port.getNIOHandler()); else if (channel instanceof DatagramChannel) channel.register(selector, SelectionKey.OP_READ, port.getNIOHandler()); if (!ports.contains(port)) ports.add(port); }
From source file:net.socket.nio.TimeClientHandle.java
private void handleInput(SelectionKey key) throws IOException { if (key.isValid()) { // ??/*from ww w . j a va2s . c o m*/ SocketChannel sc = (SocketChannel) key.channel(); if (key.isConnectable()) { if (sc.finishConnect()) { sc.register(selector, SelectionKey.OP_READ); doWrite(sc); } else { System.exit(1);// } } if (key.isReadable()) { ByteBuffer readBuffer = ByteBuffer.allocate(1024); int readBytes = sc.read(readBuffer); if (readBytes > 0) { readBuffer.flip(); byte[] bytes = new byte[readBuffer.remaining()]; readBuffer.get(bytes); String body = new String(bytes, "UTF-8"); System.out.println("Now is : " + body); this.stop = true; } else if (readBytes < 0) { // key.cancel(); sc.close(); } else { ; // 0 } } } }
From source file:com.ok2c.lightmtp.impl.protocol.ServiceReadyCodec.java
@Override public void produceData(final IOSession iosession, final ServerState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionOutputBuffer buf = this.iobuffers.getOutbuf(); if (this.pendingReply != null) { this.writer.write(this.pendingReply, buf); this.pendingReply = null; }//from w w w. ja v a 2 s . com if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { this.completed = true; iosession.setEventMask(SelectionKey.OP_READ); } }
From source file:edu.tsinghua.lumaqq.qq.net.TCPHttpPort.java
public void proxyReady(InetSocketAddress bindAddress) throws IOException { ready = true;/* w w w . j av a 2 s.co m*/ channel = (SocketChannel) proxy.channel(); ((PortGate) getPool()).getPorter().register(this, SelectionKey.OP_READ); }