Package org.apache.mina.core.session

Examples of org.apache.mina.core.session.IoSession


        H handle = boundHandles.get(localAddress);
        if (handle == null) {
            throw new IllegalArgumentException("Unknown local address: " + localAddress);
        }

        IoSession session;
        IoSessionRecycler sessionRecycler = getSessionRecycler();
        synchronized (sessionRecycler) {
            session = sessionRecycler.recycle(localAddress, remoteAddress);
            if (session != null) {
                return session;
            }

            // If a new session needs to be created.
            T newSession = newSession(processor, handle, remoteAddress);
            getSessionRecycler().put(newSession);
            session = newSession;
        }

        initSession(session, null, null);

        try {
            this.getFilterChainBuilder().buildFilterChain(session.getFilterChain());
            getListeners().fireSessionCreated(session);
        } catch (Throwable t) {
            ExceptionMonitor.getInstance().exceptionCaught(t);
        }
View Full Code Here


        IoBuffer readBuf = IoBuffer.allocate(
                getSessionConfig().getReadBufferSize());

        SocketAddress remoteAddress = receive(handle, readBuf);
        if (remoteAddress != null) {
            IoSession session = newSessionWithoutLock(
                    remoteAddress, localAddress(handle));

            readBuf.flip();

            IoBuffer newBuf = IoBuffer.allocate(readBuf.limit());
            newBuf.put(readBuf);
            newBuf.flip();

            session.getFilterChain().fireMessageReceived(newBuf);
        }
    }
View Full Code Here

        if (parent.contains(this)) {
            throw new IllegalArgumentException(
                    "You can't add the same filter instance more than once.  Create another instance and add it.");
        }

        IoSession session = parent.getSession();
        session.setAttribute(RESPONSE_INSPECTOR, responseInspectorFactory
                .getResponseInspector());
        session.setAttribute(REQUEST_STORE, createRequestStore(session));
        session.setAttribute(UNRESPONDED_REQUEST_STORE, createUnrespondedRequestStore(session));
    }
View Full Code Here

    }

    @Override
    public void onPostRemove(IoFilterChain parent, String name,
            NextFilter nextFilter) throws Exception {
        IoSession session = parent.getSession();

        destroyUnrespondedRequestStore(getUnrespondedRequestStore(session));
        destroyRequestStore(getRequestStore(session));

        session.removeAttribute(UNRESPONDED_REQUEST_STORE);
        session.removeAttribute(REQUEST_STORE);
        session.removeAttribute(RESPONSE_INSPECTOR);
    }
View Full Code Here

        if (parent.contains(SslFilter.class)) {
            throw new IllegalStateException(
                    "Only one " + SslFilter.class.getName() + " is permitted.");
        }

        IoSession session = parent.getSession();
        session.setAttribute(NEXT_FILTER, nextFilter);

        // Create an SSL handler and start handshake.
        SslHandler handler = new SslHandler(this, sslContext, session);
        session.setAttribute(SSL_HANDLER, handler);
    }
View Full Code Here

    }

    @Override
    public void onPreRemove(IoFilterChain parent, String name,
            NextFilter nextFilter) throws SSLException {
        IoSession session = parent.getSession();
        stopSsl(session);
        session.removeAttribute(NEXT_FILTER);
        session.removeAttribute(SSL_HANDLER);
    }
View Full Code Here

    }

    public void testUnbindResume() throws Exception {
        bind(true);
        IoConnector connector = newConnector();
        IoSession session = null;
        connector.setHandler(new IoHandlerAdapter());
       
        ConnectFuture future = connector.connect(createSocketAddress(port));
        future.awaitUninterruptibly();
        session = future.getSession();
        assertTrue(session.isConnected());
        assertTrue(session.write(IoBuffer.allocate(1)).awaitUninterruptibly().isWritten());

        // Wait for the server side session to be created.
        Thread.sleep(500);

        Collection<IoSession> managedSession = acceptor.getManagedSessions().values();
        assertEquals(1, managedSession.size());

        acceptor.unbind();

        // Wait for the client side sessions to close.
        Thread.sleep(500);

        assertEquals(0, managedSession.size());
        for (IoSession element : managedSession) {
            assertFalse(element.isConnected());
        }
       
        // Rebind
        bind(true);
       
        // Check again the connection
        future = connector.connect(createSocketAddress(port));
        future.awaitUninterruptibly();
        session = future.getSession();
        assertTrue(session.isConnected());
        assertTrue(session.write(IoBuffer.allocate(1)).awaitUninterruptibly().isWritten());

        // Wait for the server side session to be created.
        Thread.sleep(500);

        managedSession = acceptor.getManagedSessions().values();
View Full Code Here

            }
        });

        ConnectFuture future = connector.connect(
                new InetSocketAddress("127.0.0.1", port)).awaitUninterruptibly();
        IoSession session = future.getSession();
        assertNotNull(session);

        Thread.sleep((INTERVAL + TIMEOUT + 1) * 1000);

        assertFalse("got an exception on the client", gotException.get());

        session.close(true);
        connector.dispose();
    }
View Full Code Here

            }
        });
        ConnectFuture future = connector.connect(new InetSocketAddress("localhost", port));
        future.awaitUninterruptibly();
       
        IoSession session = future.getSession();
        session.write(file);
       
        latch.await();
       
        if (exception[0] != null) {
            throw exception[0];
        }
        assertTrue("Did not complete file transfer successfully", success[0]);
       
        assertEquals("Written messages should be 1 (we wrote one file)", 1, session.getWrittenMessages());
        assertEquals("Written bytes should match file size", FILE_SIZE, session.getWrittenBytes());
       
        connector.dispose();
        acceptor.dispose();
    }
View Full Code Here

    private SocketAddress connectAndWrite(NioSocketConnector connector, int clientNr) {
        ConnectFuture connectFuture = connector.connect(new InetSocketAddress("localhost", port));
        connectFuture.awaitUninterruptibly(TIMEOUT);
        IoBuffer message = IoBuffer.allocate(4).putInt(clientNr).flip();
        IoSession session = connectFuture.getSession();
        session.write(message).awaitUninterruptibly(TIMEOUT);
        return session.getLocalAddress();
    }
View Full Code Here

TOP

Related Classes of org.apache.mina.core.session.IoSession

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.