Package org.apache.mina.core.session

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


        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


     * {@inheritDoc}
     */
    @Override
    public void proxySessionOpened(IoSession session) throws Exception {
        logger.debug("CLIENT - Session opened: " + session);
        final IoSession _session = session;
        // Enter typing loop
        new Thread(new Runnable() {
            public void run() {
                InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(isr);

                while (!_session.isClosing()) {
                    try {
                        String line = br.readLine();
                        if (line != null) {
                            _session.write(line);
                        }
                    } catch (Exception e) {
                        break;
                    }
                }

                _session.close(true);
            }

        }).start();
    }
View Full Code Here

    @Override
    public List<Runnable> shutdownNow() {
        shutdown();

        List<Runnable> answer = new ArrayList<Runnable>();
        IoSession session;
        while ((session = waitingSessions.poll()) != null) {
            if (session == EXIT_SIGNAL) {
                waitingSessions.offer(EXIT_SIGNAL);
                Thread.yield(); // Let others take the signal.
                continue;
            }

            SessionBuffer buf = (SessionBuffer) session.getAttribute(BUFFER);
            synchronized (buf.queue) {
                for (Runnable task: buf.queue) {
                    getQueueHandler().polled(this, (IoEvent) task);
                    answer.add(task);
                }
View Full Code Here

        }

        checkTaskType(task);

        IoEvent e = (IoEvent) task;
        IoSession s = e.getSession();
        SessionBuffer buf = getSessionBuffer(s);
        Queue<Runnable> queue = buf.queue;
        boolean offerSession;
        boolean offerEvent = queueHandler.accept(this, e);
        if (offerEvent) {
View Full Code Here

    @Override
    public boolean remove(Runnable task) {
        checkTaskType(task);
        IoEvent e = (IoEvent) task;
        IoSession s = e.getSession();
        SessionBuffer buffer = (SessionBuffer) s.getAttribute(BUFFER);
        if (buffer == null) {
            return false;
        }

        boolean removed;
View Full Code Here

        public void run() {
            thread = Thread.currentThread();

            try {
                for (;;) {
                    IoSession session = fetchSession();

                    idleWorkers.decrementAndGet();

                    if (session == null) {
                        synchronized (workers) {
View Full Code Here

                }
            }
        }

        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

     * @param nextFilter the next filter
     */
    @Override
    public void onPreRemove(final IoFilterChain chain, final String name,
            final NextFilter nextFilter) {
        IoSession session = chain.getSession();
        session.removeAttribute(ProxyIoSession.PROXY_SESSION);
    }
View Full Code Here

        // ---- extract password from JNDI environment
        byte[] credentials = bindContext.getCredentials();

        LdapPrincipal principal = getStoredPassword( bindContext );

        IoSession session = bindContext.getIoSession();

        if ( session != null )
        {
            SocketAddress clientAddress = session.getRemoteAddress();
            principal.setClientAddress( clientAddress );
            SocketAddress serverAddress = session.getServiceAddress();
            principal.setServerAddress( serverAddress );
        }

        // Get the stored password, either from cache or from backend
        byte[][] storedPasswords = principal.getUserPasswords();
View Full Code Here

        testConnector(connector, true);
    }

    private void testConnector(IoConnector connector, boolean useLocalAddress)
            throws Exception {
        IoSession session = null;
        if (!useLocalAddress) {
            ConnectFuture future = connector.connect(new InetSocketAddress(
                    "127.0.0.1", port));
            future.awaitUninterruptibly();
            session = future.getSession();
        } else {
            int clientPort = port;
            for (int i = 0; i < 65536; i++) {
                clientPort = AvailablePortFinder
                        .getNextAvailable(clientPort + 1);
                try {
                    ConnectFuture future = connector.connect(
                            new InetSocketAddress("127.0.0.1", port),
                            new InetSocketAddress(clientPort));
                    future.awaitUninterruptibly();
                    session = future.getSession();
                    break;
                } catch (RuntimeIoException e) {
                    // Try again until we succeed to bind.
                }
            }

            if (session == null) {
                Assert.fail("Failed to find out an appropriate local address.");
            }
        }

        // Run a basic connector test.
        testConnector0(session);

        // Send closeNotify to test TLS closure if it is TLS connection.
        if (useSSL) {
            connectorSSLFilter.stopSsl(session).awaitUninterruptibly();

            System.out
                    .println("-------------------------------------------------------------------------------");
            // Test again after we finished TLS session.
            testConnector0(session);

            System.out
                    .println("-------------------------------------------------------------------------------");

            // Test if we can enter TLS mode again.
            //// Send StartTLS request.
            handler.readBuf.clear();
            IoBuffer buf = IoBuffer.allocate(1);
            buf.put((byte) '.');
            buf.flip();
            session.write(buf).awaitUninterruptibly();

            //// Wait for StartTLS response.
            waitForResponse(handler, 1);

            handler.readBuf.flip();
            Assert.assertEquals(1, handler.readBuf.remaining());
            Assert.assertEquals((byte) '.', handler.readBuf.get());

            // Now start TLS connection
            Assert.assertTrue(connectorSSLFilter.startSsl(session));
            testConnector0(session);
        }

        session.close(true).awaitUninterruptibly();
    }
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.