Package org.apache.mina.api

Examples of org.apache.mina.api.IoHandler


    /**
     * {@inheritDoc}
     */
    public void start(int port, final CountDownLatch counter, final byte[] data) throws IOException {
        udpClient = new NioUdpClient();
        udpClient.setIoHandler(new IoHandler() {
            private void sendMessage(IoSession session, byte[] data) {
                ByteBuffer iobuf = ByteBuffer.wrap(data);
                session.write(iobuf);
            }

View Full Code Here


    @Override
    public void start(int port) throws IOException {
        UdpSessionConfig config = new DefaultUdpSessionConfig();
        config.setReadBufferSize(65536);
        udpServer = new NioUdpServer(config);
        udpServer.setIoHandler(new IoHandler() {
            @Override
            public void sessionOpened(IoSession session) {
                session.setAttribute(STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
            }
View Full Code Here

     */
    public void start(int port) throws IOException {
        tcpServer = new NioTcpServer(new FixedSelectorLoopPool("Server", 1), null);
        tcpServer.getSessionConfig().setReadBufferSize(128 * 1024);
        tcpServer.getSessionConfig().setTcpNoDelay(true);
        tcpServer.setIoHandler(new IoHandler() {
            public void sessionOpened(IoSession session) {
                session.setAttribute(STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
            }

            public void messageReceived(IoSession session, Object message) {
View Full Code Here

     */
    public void start(int port, final CountDownLatch counter, final byte[] data) throws IOException {
        client = new NioTcpClient();
        client.getSessionConfig().setSendBufferSize(64 * 1024);
        client.getSessionConfig().setTcpNoDelay(true);
        client.setIoHandler(new IoHandler() {
            private void sendMessage(IoSession session, byte[] data) {
                ByteBuffer iobuf = ByteBuffer.wrap(data);
                session.write(iobuf);
            }

View Full Code Here

    @Override
    public void start(int port) throws IOException {
        UdpSessionConfig config = new DefaultUdpSessionConfig();
        config.setReadBufferSize(65536);
        udpServer = new BioUdpServer(config, null);
        udpServer.setIoHandler(new IoHandler() {
            @Override
            public void sessionOpened(IoSession session) {
                session.setAttribute(STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
            }
View Full Code Here

    protected void processException(Exception t) {
        if (IS_DEBUG) {
            LOG.debug("caught session exception ", t);
        }

        IoHandler handler = getService().getIoHandler();

        if (handler != null) {
            handler.exceptionCaught(this, t);
        }
    }
View Full Code Here

            for (IoFilter filter : chain) {
                filter.sessionOpened(this);
            }

            IoHandler handler = getService().getIoHandler();

            if (handler != null) {
                IoHandlerExecutor executor = getService().getIoHandlerExecutor();

                if (executor != null) {
                    // asynchronous event
                    executor.execute(new OpenEvent(this));
                } else {
                    // synchronous call (in the I/O loop)
                    handler.sessionOpened(this);
                }
            }
        } catch (RuntimeException e) {
            processException(e);
        }
View Full Code Here

        try {
            for (IoFilter filter : chain) {
                filter.sessionClosed(this);
            }

            IoHandler handler = getService().getIoHandler();

            if (handler != null) {
                IoHandlerExecutor executor = getService().getIoHandlerExecutor();
                if (executor != null) {
                    // asynchronous event
                    executor.execute(new CloseEvent(this));
                } else {
                    // synchronous call (in the I/O loop)
                    handler.sessionClosed(this);
                }
            }
        } catch (RuntimeException e) {
            LOG.error("Exception while closing the session : ", e);
        }
View Full Code Here

        try {
            for (IoFilter filter : chain) {
                filter.sessionIdle(this, status);
            }

            IoHandler handler = getService().getIoHandler();

            if (handler != null) {
                IoHandlerExecutor executor = getService().getIoHandlerExecutor();

                if (executor != null) {
                    // asynchronous event
                    executor.execute(new IdleEvent(this, status));
                } else {
                    // synchronous call (in the I/O loop)
                    handler.sessionIdle(this, status);
                }
            }
        } catch (RuntimeException e) {
            processException(e);
        }
View Full Code Here

            if (chain.length < 1) {
                if (IS_DEBUG) {
                    LOG.debug("Nothing to do, the chain is empty");
                }

                IoHandler handler = getService().getIoHandler();

                if (handler != null) {
                    IoHandlerExecutor executor = getService().getIoHandlerExecutor();

                    if (executor != null) {
                        // asynchronous event
                        // copy the bytebuffer
                        if (IS_DEBUG) {
                            LOG.debug("copying bytebuffer before pushing to the executor");
                        }

                        ByteBuffer original = message;
                        ByteBuffer clone = ByteBuffer.allocate(original.capacity());
                        // copy from the beginning
                        original.rewind();
                        clone.put(original);
                        original.rewind();
                        clone.flip();
                        executor.execute(new ReceiveEvent(this, clone));
                    } else {
                        // synchronous call (in the I/O loop)
                        handler.messageReceived(this, message);
                    }
                }

            } else {
                readChainPosition = 0;
View Full Code Here

TOP

Related Classes of org.apache.mina.api.IoHandler

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.