Package org.apache.mina.core.session

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


                }
            }
        }

        private IoSession fetchSession() {
            IoSession session = null;
            long currentTime = System.currentTimeMillis();
            long deadline = currentTime + getKeepAliveTime(TimeUnit.MILLISECONDS);
            for (;;) {
                try {
                    long waitTime = deadline - currentTime;
View Full Code Here


    @Override
    protected Object getProperty0(OgnlContext context, Object target,
            String name) throws OgnlException {
        if (target instanceof IoSession && "attributes".equals(name)) {
            Map<String, Object> attributes = new TreeMap<String, Object>();
            IoSession s = (IoSession) target;
            for (Object key: s.getAttributeKeys()) {
                Object value = s.getAttribute(key);
                if (value == null) {
                    continue;
                }
                attributes.put(String.valueOf(key), value);
            }
View Full Code Here

        assertNull(future.getException());

        TestThread thread = new TestThread(future);
        thread.start();

        IoSession session = new DummySession();

        future.setSession(session);
        thread.join();

        assertTrue(thread.success);
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("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

        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

        exchange.getIn().setBody("Hello World");
        producer.process(exchange);

        Field field = producer.getClass().getDeclaredField("session");
        field.setAccessible(true);
        IoSession session = (IoSession) field.get(producer);
        assertFalse("There should NOT be a logger filter", session.getFilterChain().contains("logger"));

        assertMockEndpointsSatisfied();

        producer.stop();
    }
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.