List of usage examples for org.apache.http.nio.reactor IOSession close
void close();
From source file:org.wso2.carbon.inbound.endpoint.protocol.hl7.core.MLLPSourceHandler.java
private void shutdownConnection(IOSession session, MLLPContext mllpContext, Exception e) { if (e != null) { log.error("An unexpected error has occurred."); handleException(session, mllpContext, e); }//ww w.j a v a 2s .c om bufferFactory.release(inputBuffer); bufferFactory.release(outputBuffer); session.close(); }
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();// ww w.j a v a 2 s.co 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 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 QUIT_RESPONSE_EXPECTED: iosession.close(); this.codecState = CodecState.COMPLETED; sessionState.setReply(reply); break; default:/*from w w w .j a v a 2 s . com*/ throw new SMTPProtocolException("Unexpected reply: " + reply); } } }
From source file:com.ok2c.lightmtp.impl.protocol.ServiceShutdownCodec.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 ww.j ava 2 s. c om if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { this.completed = true; iosession.close(); } }
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 . j av a2 s . co 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:org.wso2.carbon.inbound.endpoint.protocol.hl7.core.MLLPSourceHandler.java
@Override public void inputReady(IOSession session) { ReadableByteChannel ch = (ReadableByteChannel) session.channel(); MLLPContext mllpContext = (MLLPContext) session.getAttribute(MLLPConstants.MLLP_CONTEXT); inputBuffer.clear();/*ww w . j a va 2 s .co m*/ try { int read; while ((read = ch.read(inputBuffer.getByteBuffer())) > 0) { inputBuffer.flip(); try { mllpContext.getCodec().decode(inputBuffer.getByteBuffer(), mllpContext); } catch (MLLProtocolException e) { handleException(session, mllpContext, e); clearInputBuffers(mllpContext); return; } catch (HL7Exception e) { handleException(session, mllpContext, e); if (mllpContext.isAutoAck()) { mllpContext.setNackMode(true); mllpContext.setHl7Message(HL7MessageUtils.createDefaultNack(e.getMessage())); mllpContext.requestOutput(); } else { hl7Processor.processError(mllpContext, e); } return; } catch (IOException e) { shutdownConnection(session, mllpContext, e); return; } } if (mllpContext.getCodec().isReadComplete()) { if (mllpContext.isAutoAck()) { mllpContext.requestOutput(); bufferFactory.release(inputBuffer); inputBuffer = bufferFactory.getBuffer(); } try { hl7Processor.processRequest(mllpContext); } catch (Exception e) { shutdownConnection(session, mllpContext, e); } } if (read < 0) { clearInputBuffers(mllpContext); session.close(); } } catch (IOException e) { shutdownConnection(session, mllpContext, e); } }