Package org.apache.james.protocols.api

Examples of org.apache.james.protocols.api.ProtocolSession


    @SuppressWarnings("unchecked")
    @Override
    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        List<ConnectHandler> connectHandlers = chain.getHandlers(ConnectHandler.class);
        List<ProtocolHandlerResultHandler> resultHandlers = chain.getHandlers(ProtocolHandlerResultHandler.class);
        ProtocolSession session = (ProtocolSession) ctx.getAttachment();
        session.getLogger().info("Connection established from " + session.getRemoteHost() + " (" + session.getRemoteIPAddress()+ ")");
        if (connectHandlers != null) {
            for (int i = 0; i < connectHandlers.size(); i++) {
                ConnectHandler cHandler = connectHandlers.get(i);
               
                long start = System.currentTimeMillis();
                Response response = connectHandlers.get(i).onConnect(session);
                long executionTime = System.currentTimeMillis() - start;
               
                for (int a = 0; a < resultHandlers.size(); a++) {
                    // Disable till PROTOCOLS-37 is implemented
                    if (response instanceof FutureResponse) {
                        session.getLogger().debug("ProtocolHandlerResultHandler are not supported for FutureResponse yet");
                        break;
                    }
                    resultHandlers.get(a).onResponse(session, response, executionTime, cHandler);
                }
                if (response != null) {
View Full Code Here



    @Override
    public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        List<DisconnectHandler> connectHandlers = chain.getHandlers(DisconnectHandler.class);
        ProtocolSession session = (ProtocolSession) ctx.getAttachment();
        if (connectHandlers != null) {
            for (int i = 0; i < connectHandlers.size(); i++) {
                connectHandlers.get(i).onDisconnect(session);
            }
        }
View Full Code Here

     * Call the {@link LineHandler}
     */
    @SuppressWarnings("unchecked")
    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        ProtocolSession pSession = (ProtocolSession) ctx.getAttachment();
        LinkedList<LineHandler> lineHandlers = chain.getHandlers(LineHandler.class);
        LinkedList<ProtocolHandlerResultHandler> resultHandlers = chain.getHandlers(ProtocolHandlerResultHandler.class);

       
        if (lineHandlers.size() > 0) {
       
            ChannelBuffer buf = (ChannelBuffer) e.getMessage();     
            byte[] line;
           
            if (buf.hasArray()) {
                line = buf.array();
            } else {
                // copy the ChannelBuffer to a byte array to process the LineHandler
                line = new byte[buf.capacity()];
                buf.getBytes(0, line);
            }
           
            LineHandler lHandler=  (LineHandler) lineHandlers.getLast();
            long start = System.currentTimeMillis();           
            Response response = lHandler.onLine(pSession,line);
            long executionTime = System.currentTimeMillis() - start;

            for (int i = 0; i < resultHandlers.size(); i++) {
                // Disable till PROTOCOLS-37 is implemented
                if (response instanceof FutureResponse) {
                    pSession.getLogger().debug("ProtocolHandlerResultHandler are not supported for FutureResponse yet");
                    break;
                }
                response = resultHandlers.get(i).onResponse(pSession, response, executionTime, lHandler);
            }
            if (response != null) {
View Full Code Here

    }


    @Override
    public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        ProtocolSession session = (ProtocolSession) ctx.getAttachment();
        if (session != null) {
            session.getLogger().info("Connection closed for " + session.getRemoteHost() + " (" + session.getRemoteIPAddress()+ ")");
        }
        cleanup(ctx);

        super.channelClosed(ctx, e);
    }
View Full Code Here

     * Cleanup the channel
     *
     * @param channel
     */
    protected void cleanup(ChannelHandlerContext ctx) {
        ProtocolSession session = (ProtocolSession) ctx.getAttachment();
        if (session != null) {
            session.resetState();
            session = null;
        }
    }
View Full Code Here

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
        Channel channel = ctx.getChannel();
        ProtocolSession session = (ProtocolSession) ctx.getAttachment();
        if (e.getCause() instanceof TooLongFrameException) {
            Response r = session.newLineTooLongResponse();
            ProtocolTransport transport = ((AbstractSession)session).getProtocolTransport();
            if (r != null)  {
                transport.writeResponse(r, session);
            }
        } else {
            if (channel.isConnected()) {
                ProtocolTransport transport = ((AbstractSession)session).getProtocolTransport();

                Response r = session.newFatalErrorResponse();
                if (r != null) {
                    transport.writeResponse(r, session);
                }
                transport.writeResponse(Response.DISCONNECT, session);
            }
            if (session != null) {
                session.getLogger().debug("Unable to process request", e.getCause());
            } else {
                logger.debug("Unable to process request", e.getCause());
            }
            cleanup(ctx);           
        }
View Full Code Here

    @SuppressWarnings("unchecked")
    @Override
    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        List<ConnectHandler> connectHandlers = chain.getHandlers(ConnectHandler.class);
        List<ConnectHandlerResultHandler> resultHandlers = chain.getHandlers(ConnectHandlerResultHandler.class);
        ProtocolSession session = (ProtocolSession) attributes.get(ctx.getChannel());
        session.getLogger().info("Connection established from " + session.getRemoteHost() + " (" + session.getRemoteIPAddress()+ ")");
        if (connectHandlers != null) {
            for (int i = 0; i < connectHandlers.size(); i++) {
                ConnectHandler cHandler = connectHandlers.get(i);
               
                long start = System.currentTimeMillis();
View Full Code Here

     * Call the {@link LineHandler}
     */
    @SuppressWarnings("unchecked")
    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        ProtocolSession pSession = (ProtocolSession) attributes.get(ctx.getChannel());
        LinkedList<LineHandler> lineHandlers = chain.getHandlers(LineHandler.class);
        LinkedList<LineHandlerResultHandler> resultHandlers = chain.getHandlers(LineHandlerResultHandler.class);

       
        if (lineHandlers.size() > 0) {
View Full Code Here

    }


    @Override
    public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        ProtocolSession session = (ProtocolSession) attributes.get(ctx.getChannel());
        if (session != null) {
            session.getLogger().info("Connection closed for " + session.getRemoteHost() + " (" + session.getRemoteIPAddress()+ ")");
        }
        cleanup(ctx.getChannel());

        super.channelClosed(ctx, e);
    }
View Full Code Here

     * Cleanup the channel
     *
     * @param channel
     */
    protected void cleanup(Channel channel) {
        ProtocolSession session = (ProtocolSession) attributes.remove(channel);
        if (session != null) {
            session.resetState();
            session = null;
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.james.protocols.api.ProtocolSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.