List of usage examples for org.apache.http.nio.reactor IOSession setEvent
void setEvent(int op);
From source file:com.ok2c.lightmtp.impl.protocol.SendQuitCodec.java
@Override public void reset(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { this.parser.reset(); this.writer.reset(); this.codecState = CodecState.QUIT_READY; iosession.setEvent(SelectionKey.OP_WRITE); }
From source file:com.ok2c.lightmtp.impl.protocol.SendRsetCodec.java
@Override public void reset(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { this.parser.reset(); this.writer.reset(); this.codecState = CodecState.RSET_READY; iosession.setEvent(SelectionKey.OP_WRITE); }
From source file:com.ok2c.lightmtp.impl.protocol.SimpleSendHeloCodec.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.setEvent(SelectionKey.OP_READ); }
From source file:com.ok2c.lightmtp.impl.protocol.AuthCodec.java
@Override public void reset(final IOSession iosession, final ClientState state) throws IOException, SMTPProtocolException { this.parser.reset(); this.writer.reset(); this.codecState = CodecState.AUTH_READY; this.lineBuf.clear(); iosession.setEvent(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 {//from w ww .j a v a 2 s.c o m iosession.setEvent(SelectionKey.OP_READ); } }
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); }// w w w . j av 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(); } } }
From source file:com.ok2c.lightmtp.impl.protocol.SendLocalHeloCodec.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.LHLO_READY; iosession.setEvent(SelectionKey.OP_WRITE); } else { this.codecState = CodecState.COMPLETED; sessionState.setReply(reply); }//from w w w .j a v a 2s . c o m break; case LHLO_RESPONSE_EXPECTED: if (reply.getCode() == SMTPCodes.OK) { Set<String> extensions = sessionState.getExtensions(); List<String> lines = reply.getLines(); if (lines.size() > 1) { for (int i = 1; i < lines.size(); i++) { String line = lines.get(i); extensions.add(line.toUpperCase(Locale.US)); } } } 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(); } } }
From source file:com.ok2c.lightmtp.impl.protocol.ExtendedSendHeloCodec.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.EHLO_READY; iosession.setEvent(SelectionKey.OP_WRITE); } else { this.codecState = CodecState.COMPLETED; sessionState.setReply(reply); }/*w w w.j av a 2 s .c o m*/ break; case EHLO_RESPONSE_EXPECTED: if (reply.getCode() == SMTPCodes.OK) { Set<String> extensions = sessionState.getExtensions(); List<String> lines = reply.getLines(); if (lines.size() > 1) { for (int i = 1; i < lines.size(); i++) { String line = lines.get(i); extensions.add(line.toUpperCase(Locale.US)); } } this.codecState = CodecState.COMPLETED; sessionState.setReply(reply); } else if (reply.getCode() == SMTPCodes.ERR_PERM_SYNTAX_ERR_COMMAND) { this.codecState = CodecState.HELO_READY; iosession.setEvent(SelectionKey.OP_WRITE); } else { this.codecState = CodecState.COMPLETED; sessionState.setReply(reply); } 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(); } } }
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 a v a2s . c o 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.SendDataCodec.java
@Override public void reset(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); if (sessionState.getRequest() == null) { throw new IllegalArgumentException("Delivery request may not be null"); }//w w w.j a v a2 s . c om DeliveryRequest request = sessionState.getRequest(); this.parser.reset(); this.contentBuf.clear(); this.lineBuf.clear(); this.recipients.clear(); if (this.mode.equals(DataAckMode.PER_RECIPIENT)) { this.recipients.addAll(request.getRecipients()); } this.content = request.getContent(); this.contentChannel = this.content.channel(); this.contentSent = false; this.codecState = CodecState.CONTENT_READY; iosession.setEvent(SelectionKey.OP_WRITE); }