List of usage examples for java.nio.channels SelectionKey OP_WRITE
int OP_WRITE
To view the source code for java.nio.channels SelectionKey OP_WRITE.
Click Source Link
From source file:com.ok2c.lightmtp.impl.protocol.ServiceReadyCodec.java
@Override public void reset(final IOSession iosession, final ServerState sessionState) throws IOException, SMTPProtocolException { this.writer.reset(); InetSocketAddress socketAddress = (InetSocketAddress) iosession.getRemoteAddress(); InetAddress clientAddress = socketAddress.getAddress(); if (this.addressValidator != null) { if (!this.addressValidator.validateAddress(clientAddress)) { sessionState.terminated();/*w ww. j av a 2 s . c o m*/ iosession.close(); return; } } sessionState.setClientAddress(clientAddress); this.pendingReply = new SMTPReply(SMTPCodes.SERVICE_READY, null, sessionState.getServerId() + " service ready"); this.completed = false; iosession.setEventMask(SelectionKey.OP_WRITE); }
From source file:com.ok2c.lightmtp.impl.protocol.SendQuitCodec.java
@Override public void produceData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionOutputBuffer buf = this.iobuffers.getOutbuf(); switch (this.codecState) { case QUIT_READY: SMTPCommand quit = new SMTPCommand("QUIT"); this.writer.write(quit, buf); this.codecState = CodecState.QUIT_RESPONSE_EXPECTED; break;//from w w w . j ava 2 s.c o m } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }
From source file:com.ok2c.lightmtp.impl.protocol.SendRsetCodec.java
@Override public void produceData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionOutputBuffer buf = this.iobuffers.getOutbuf(); switch (this.codecState) { case RSET_READY: SMTPCommand quit = new SMTPCommand("RSET"); this.writer.write(quit, buf); this.codecState = CodecState.RSET_RESPONSE_EXPECTED; break;//from w w w . j a v a 2s.c om } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }
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 {//w w w .java2 s . c o m iosession.setEvent(SelectionKey.OP_READ); } }
From source file:com.ok2c.lightmtp.impl.protocol.ClientSession.java
private void signalDeliveryReady() { if (this.sessionState.getRequest() != null) { throw new IllegalStateException("Delivery request is not null"); }/*from ww w . j a v a 2 s .co m*/ this.log.debug("Ready for delivery request"); DeliveryRequest request = this.handler.submitRequest(this.context); this.sessionState.reset(request); if (request == null) { this.iosession.clearEvent(SelectionKey.OP_WRITE); this.log.debug("No delivery request submitted"); } else { this.iosession.setEvent(SelectionKey.OP_WRITE); if (this.log.isDebugEnabled()) { this.log.debug("Delivery request submitted: " + request); } } }
From source file:com.ok2c.lightmtp.impl.protocol.SimpleSendHeloCodec.java
@Override public void produceData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionOutputBuffer buf = this.iobuffers.getOutbuf(); switch (this.codecState) { case HELO_READY: SMTPCommand helo = new SMTPCommand("HELO", AddressUtils.resolveLocalDomain(iosession.getLocalAddress())); this.writer.write(helo, buf); this.codecState = CodecState.HELO_RESPONSE_EXPECTED; break;//from w w w . j av a2s .c o m } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }
From source file:com.ok2c.lightmtp.impl.protocol.SendLocalHeloCodec.java
@Override public void produceData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionOutputBuffer buf = this.iobuffers.getOutbuf(); switch (this.codecState) { case LHLO_READY: String helo = heloName;/*ww w. j a v a 2 s. co m*/ if (helo == null) { helo = AddressUtils.resolveLocalDomain(iosession.getLocalAddress()); } SMTPCommand ehlo = new SMTPCommand("LHLO", helo); this.writer.write(ehlo, buf); this.codecState = CodecState.LHLO_RESPONSE_EXPECTED; break; } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }
From source file:com.tera.common.network.nio.MMOConnection.java
@Override public synchronized void write(NetworkPacket networkPacket) { if (isClosed()) return;//from w w w. j a v a 2 s .co m try { getSelectionKey().interestOps(getSelectionKey().interestOps() | SelectionKey.OP_WRITE); getSendQueue2().addLast(networkPacket); } catch (CancelledKeyException e) { // ignore } }
From source file:com.ok2c.lightmtp.impl.protocol.ServerSession.java
public void timeout() { if (this.log.isDebugEnabled()) { this.log.error("Connection timed out: " + this.iosession.getRemoteAddress()); }// w w w. ja v a 2s .com this.sessionState.terminated(); this.iosession.setEvent(SelectionKey.OP_WRITE); }
From source file:com.ok2c.lightmtp.impl.protocol.SimpleSendHeloCodec.java
@Override public void consumeData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionInputBuffer buf = this.iobuffers.getInbuf(); int bytesRead = buf.fill(iosession.channel()); SMTPReply reply = this.parser.parse(buf, bytesRead == -1); if (reply != null) { switch (this.codecState) { case SERVICE_READY_EXPECTED: if (reply.getCode() == SMTPCodes.SERVICE_READY) { this.codecState = CodecState.HELO_READY; iosession.setEvent(SelectionKey.OP_WRITE); } else { this.codecState = CodecState.COMPLETED; sessionState.setReply(reply); }/*from ww w . ja v a 2 s .co m*/ break; case HELO_RESPONSE_EXPECTED: this.codecState = CodecState.COMPLETED; sessionState.setReply(reply); break; default: if (reply.getCode() == SMTPCodes.ERR_TRANS_SERVICE_NOT_AVAILABLE) { sessionState.setReply(reply); this.codecState = CodecState.COMPLETED; } else { throw new SMTPProtocolException("Unexpected reply: " + reply); } } } else { if (bytesRead == -1 && !sessionState.isTerminated()) { throw new UnexpectedEndOfStreamException(); } } }