Package org.apache.mina.core.service

Examples of org.apache.mina.core.service.IoHandlerAdapter


        final CountDownLatch latch = new CountDownLatch(2);
        final ConnectFuture[] callbackFuture = new ConnectFuture[1];
       
        int port = AvailablePortFinder.getNextAvailable(4025);
        IoAcceptor acceptor = createAcceptor();
        acceptor.setHandler(new IoHandlerAdapter());
        InetSocketAddress address = new InetSocketAddress(port);
        acceptor.bind(address);

        IoConnector connector = createConnector();
        connector.setHandler(new IoHandlerAdapter() {
           @Override
            public void sessionCreated(IoSession session) throws Exception {
                   assertions[sessionCreatedInvoked] = true;
                   assertions[sessionCreatedInvokedBeforeCallback] = !assertions[callbackInvoked];
                   latch.countDown();
View Full Code Here


        acceptor.setDefaultLocalAddress(null);
    }

    public void testAnonymousBind() throws Exception {
        acceptor.setHandler(new IoHandlerAdapter());
        acceptor.setDefaultLocalAddress(null);
        acceptor.bind();
        Assert.assertNotNull(acceptor.getLocalAddress());
        acceptor.unbind(acceptor.getLocalAddress());
        Assert.assertNull(acceptor.getLocalAddress());
View Full Code Here

    public void testUnbindDisconnectsClients() throws Exception {
        bind(true);
        IoConnector connector = newConnector();
        IoSession[] sessions = new IoSession[5];
        connector.setHandler(new IoHandlerAdapter());
        for (int i = 0; i < sessions.length; i++) {
            ConnectFuture future = connector.connect(createSocketAddress(port));
            future.awaitUninterruptibly();
            sessions[i] = future.getSession();
            Assert.assertTrue(sessions[i].isConnected());
View Full Code Here

        final boolean[] success = {false};
        final Throwable[] exception = {null};
       
        int port = AvailablePortFinder.getNextAvailable(1025);
        IoAcceptor acceptor = createAcceptor();
        acceptor.setHandler(new IoHandlerAdapter() {
            private int index = 0;
            @Override
            public void exceptionCaught(IoSession session, Throwable cause)
                    throws Exception {
                exception[0] = cause;
                session.close();
            }
            @Override
            public void messageReceived(IoSession session, Object message) throws Exception {
                IoBuffer buffer = (IoBuffer) message;
                while (buffer.hasRemaining()) {
                    int x = buffer.getInt();
                    if (x != index) {
                        throw new Exception(String.format("Integer at %d was %d but should have been %d", index, x, index));
                    }
                    index++;
                }
                if (index > FILE_SIZE / 4) {
                    throw new Exception("Read too much data");
                }
                if (index == FILE_SIZE / 4) {
                    success[0] = true;
                    session.close();
                }
            }
        });
        acceptor.bind(new InetSocketAddress(port));
       
        IoConnector connector = createConnector();
        connector.setHandler(new IoHandlerAdapter() {
            @Override
            public void exceptionCaught(IoSession session, Throwable cause)
                    throws Exception {
                exception[0] = cause;
                session.close();
View Full Code Here

    protected abstract IoConnector createConnector();

    public void testConnectFutureSuccessTiming() throws Exception {
        int port = AvailablePortFinder.getNextAvailable(1025);
        IoAcceptor acceptor = createAcceptor();
        acceptor.setHandler(new IoHandlerAdapter());
        acceptor.bind(new InetSocketAddress(port));

        try {
            final StringBuffer buf = new StringBuffer();
            IoConnector connector = createConnector();
            connector.setHandler(new IoHandlerAdapter() {
                @Override
                public void sessionCreated(IoSession session) {
                    buf.append("1");
                }
View Full Code Here

    public void testConnectFutureFailureTiming() throws Exception {
        int port = AvailablePortFinder.getNextAvailable(1025);
        final StringBuffer buf = new StringBuffer();

        IoConnector connector = createConnector();
        connector.setHandler(new IoHandlerAdapter() {
            @Override
            public void sessionCreated(IoSession session) {
                buf.append("X");
            }
View Full Code Here

        final CountDownLatch latch = new CountDownLatch(2);
        final ConnectFuture[] callbackFuture = new ConnectFuture[1];
       
        int port = AvailablePortFinder.getNextAvailable(1025);
        IoAcceptor acceptor = createAcceptor();
        acceptor.setHandler(new IoHandlerAdapter());
        InetSocketAddress address = new InetSocketAddress(port);
        acceptor.bind(address);

        IoConnector connector = createConnector();
        connector.setHandler(new IoHandlerAdapter() {
           @Override
            public void sessionCreated(IoSession session) throws Exception {
                   assertions[sessionCreatedInvoked] = true;
                   assertions[sessionCreatedInvokedBeforeCallback] = !assertions[callbackInvoked];
                   latch.countDown();
View Full Code Here

        //acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );

        IoConnector connector = new VmPipeConnector();
        //connector.getFilterChain().addLast( "logger", new LoggingFilter() );

        acceptor.setHandler(new IoHandlerAdapter() {
            @Override
            public void sessionOpened(IoSession session) throws Exception {
                session.write("B");
            }

            @Override
            public void messageSent(IoSession session, Object message)
                    throws Exception {
                session.close();
            }
        });

        acceptor.bind(new VmPipeAddress(1));

        final StringBuffer actual = new StringBuffer();

        connector.setHandler(new IoHandlerAdapter() {

            @Override
            public void messageReceived(IoSession session, Object message)
                    throws Exception {
                actual.append(message);
View Full Code Here

        IoConnector connector = new VmPipeConnector();
        //connector.getFilterChain().addLast( "logger", new LoggingFilter() );

        final StringBuffer actual = new StringBuffer();

        acceptor.setHandler(new IoHandlerAdapter() {

            @Override
            public void messageReceived(IoSession session, Object message)
                    throws Exception {
                actual.append(message);
            }

            @Override
            public void sessionClosed(IoSession session) throws Exception {
                actual.append("C");
            }

            @Override
            public void sessionOpened(IoSession session) throws Exception {
                actual.append("A");
            }

        });

        acceptor.bind(new VmPipeAddress(1));

        connector.setHandler(new IoHandlerAdapter() {
            @Override
            public void sessionOpened(IoSession session) throws Exception {
                session.write("B");
            }
View Full Code Here

    public void testSessionCreated() throws Exception {
        final Semaphore semaphore = new Semaphore(0);
        final StringBuffer stringBuffer = new StringBuffer();
        VmPipeAcceptor vmPipeAcceptor = new VmPipeAcceptor();
        final VmPipeAddress vmPipeAddress = new VmPipeAddress(12345);
        vmPipeAcceptor.setHandler(new IoHandlerAdapter() {
            @Override
            public void sessionCreated(IoSession session) throws Exception {
                // pretend we are doing some time-consuming work. For
                // performance reasons, you would never want to do time
                // consuming work in sessionCreated.
                // However, this increases the likelihood of the timing bug.
                Thread.sleep(1000);
                stringBuffer.append("A");
            }

            @Override
            public void sessionOpened(IoSession session) throws Exception {
                stringBuffer.append("B");
            }

            @Override
            public void messageReceived(IoSession session, Object message)
                    throws Exception {
                stringBuffer.append("C");
            }
           
            @Override
            public void sessionClosed(IoSession session) throws Exception {
                stringBuffer.append("D");
                semaphore.release();
            }
        });
        vmPipeAcceptor.bind(vmPipeAddress);

        final VmPipeConnector vmPipeConnector = new VmPipeConnector();
        vmPipeConnector.getFilterChain().addLast("executor", new ExecutorFilter());
        vmPipeConnector.setHandler(new IoHandlerAdapter());
        ConnectFuture connectFuture = vmPipeConnector.connect(vmPipeAddress);
        connectFuture.awaitUninterruptibly();
        connectFuture.getSession().write(IoBuffer.wrap(new byte[1]));
        connectFuture.getSession().closeOnFlush().awaitUninterruptibly();
View Full Code Here

TOP

Related Classes of org.apache.mina.core.service.IoHandlerAdapter

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.