List of usage examples for org.apache.http.nio.reactor IOSession clearEvent
void clearEvent(int op);
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;// w ww. ja va 2s . com } 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;/* www . j ava 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.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;/* w w w . j av a2 s .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.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;//from w w w.j ava 2s. c o 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.ok2c.lightmtp.impl.protocol.ExtendedSendHeloCodec.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(); String myHelo = heloName;/*from w w w . java2 s . com*/ if (myHelo == null) { myHelo = AddressUtils.resolveLocalDomain(iosession.getLocalAddress()); } switch (this.codecState) { case EHLO_READY: SMTPCommand ehlo = new SMTPCommand("EHLO", myHelo); this.writer.write(ehlo, buf); this.codecState = CodecState.EHLO_RESPONSE_EXPECTED; break; case HELO_READY: SMTPCommand helo = new SMTPCommand("HELO", myHelo); this.writer.write(helo, buf); this.codecState = CodecState.HELO_RESPONSE_EXPECTED; break; } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }
From source file:com.ok2c.lightmtp.impl.protocol.ReceiveDataCodec.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(); synchronized (sessionState) { if (this.pendingDelivery != null) { if (this.pendingDelivery.isDone()) { deliveryCompleted(sessionState); cleanUp();/*from ww w . j av a 2 s . co m*/ } while (!this.pendingReplies.isEmpty()) { this.writer.write(this.pendingReplies.removeFirst(), buf); } } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { if (sessionState.getDataType() != null) { this.completed = true; sessionState.reset(); } iosession.clearEvent(SelectionKey.OP_WRITE); } } }
From source file:com.ok2c.lightmtp.impl.protocol.PipeliningSendEnvelopCodec.java
@Override public void produceData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); if (sessionState.getRequest() == null) { if (sessionState.isTerminated()) { this.codecState = CodecState.COMPLETED; }//ww w .j av a 2s . co m return; } SessionOutputBuffer buf = this.iobuffers.getOutbuf(); DeliveryRequest request = sessionState.getRequest(); switch (this.codecState) { case MAIL_REQUEST_READY: SMTPCommand mailFrom = new SMTPCommand("MAIL", "FROM:<" + request.getSender() + ">"); this.writer.write(mailFrom, buf); this.recipients.addAll(request.getRecipients()); for (String recipient : request.getRecipients()) { SMTPCommand rcptTo = new SMTPCommand("RCPT", "TO:<" + recipient + ">"); this.writer.write(rcptTo, buf); } SMTPCommand data = new SMTPCommand("DATA"); this.writer.write(data, buf); this.codecState = CodecState.MAIL_RESPONSE_EXPECTED; break; } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }
From source file:com.ok2c.lightmtp.impl.protocol.SimpleSendEnvelopCodec.java
@Override public void produceData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); if (sessionState.getRequest() == null) { if (sessionState.isTerminated()) { this.codecState = CodecState.COMPLETED; }/*from w w w.j ava 2 s.co m*/ return; } SessionOutputBuffer buf = this.iobuffers.getOutbuf(); DeliveryRequest request = sessionState.getRequest(); switch (this.codecState) { case MAIL_REQUEST_READY: SMTPCommand mailFrom = new SMTPCommand("MAIL", "FROM:<" + request.getSender() + ">"); this.writer.write(mailFrom, buf); this.codecState = CodecState.MAIL_RESPONSE_EXPECTED; iosession.setEvent(SelectionKey.OP_READ); break; case RCPT_REQUEST_READY: String recipient = this.recipients.getFirst(); SMTPCommand rcptTo = new SMTPCommand("RCPT", "TO:<" + recipient + ">"); this.writer.write(rcptTo, buf); this.codecState = CodecState.RCPT_RESPONSE_EXPECTED; break; case DATA_REQUEST_READY: SMTPCommand data = new SMTPCommand("DATA"); this.writer.write(data, buf); this.codecState = CodecState.DATA_RESPONSE_EXPECTED; break; } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }
From source file:com.ok2c.lightmtp.impl.protocol.PipeliningReceiveEnvelopCodec.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(); synchronized (sessionState) { if (this.actionFuture != null) { SMTPReply reply = getReply(this.actionFuture); this.actionFuture = null; this.writer.write(reply, buf); }/*from w ww. jav a2 s . c o m*/ if (this.actionFuture == null) { while (!this.pendingActions.isEmpty()) { Action<ServerState> action = this.pendingActions.remove(); Future<SMTPReply> future = action.execute(sessionState, new OutputTrigger<SMTPReply>(sessionState, iosession)); if (future.isDone()) { SMTPReply reply = getReply(future); this.writer.write(reply, buf); } else { this.actionFuture = future; break; } } } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { if (sessionState.getDataType() != null) { this.completed = true; } if (sessionState.isTerminated()) { iosession.close(); } else { iosession.clearEvent(SelectionKey.OP_WRITE); } } } }
From source file:com.ok2c.lightmtp.impl.protocol.SendDataCodec.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 CONTENT_READY: int bytesRead = 0; while (buf.length() < LIMIT) { if (!this.contentBuf.hasData()) { bytesRead = this.contentBuf.fill(this.contentChannel); }//from w w w. j a v a 2 s. co m boolean lineComplete = this.contentBuf.readLine(this.lineBuf, bytesRead == -1); if (this.maxLineLen > 0 && (this.lineBuf.length() > this.maxLineLen || (!lineComplete && this.contentBuf.length() > this.maxLineLen))) { throw new SMTPProtocolException("Maximum line length limit exceeded"); } if (lineComplete) { if (this.lineBuf.length() > 0 && this.lineBuf.charAt(0) == '.') { buf.write(PERIOD); } buf.writeLine(this.lineBuf); this.lineBuf.clear(); } else { bytesRead = this.contentBuf.fill(this.contentChannel); } if (bytesRead == -1 && !this.contentBuf.hasData()) { this.lineBuf.clear(); this.lineBuf.append('.'); buf.writeLine(this.lineBuf); this.lineBuf.clear(); this.content.reset(); this.contentSent = true; this.codecState = CodecState.CONTENT_RESPONSE_EXPECTED; break; } if (bytesRead == 0 && !lineComplete) { break; } } } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData() && this.contentSent) { iosession.clearEvent(SelectionKey.OP_WRITE); } }