Package org.apache.mina.common

Examples of org.apache.mina.common.IoSession


    }

    public void onPostRemove( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception
    {
        super.onPostRemove( parent, name, nextFilter );
        IoSession session = parent.getSession();
        if( session == null )
        {
            return;
        }

        Zlib inflater = ( Zlib ) session.getAttribute( INFLATER );
        Zlib deflater = ( Zlib ) session.getAttribute( DEFLATER );
        if( deflater != null )
        {
            deflater.cleanUp();
        }
View Full Code Here


        {
            throw new IllegalArgumentException( "Unknown localAddress: " + localAddress );
        }

        RegistrationRequest req = ( RegistrationRequest ) key.attachment();
        IoSession session;
        IoSessionRecycler sessionRecycler = getSessionRecycler( req );
        synchronized ( sessionRecycler )
        {
            session = sessionRecycler.recycle( localAddress, remoteAddress );
            if( session != null )
View Full Code Here

                    //ignore since this is shutdown time
                }
            }

            for (Iterator iter = polledSessions.iterator(); iter.hasNext();) {
                IoSession session = (IoSession) iter.next();
                session.removeAttribute(KEY);
            }
            polledSessions.clear();
        }
    }
View Full Code Here

        {
            while ( !stop )
            {
                for ( Iterator iter = polledSessions.iterator(); iter.hasNext(); )
                {
                    IoSession session = ( IoSession ) iter.next();
                    IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute( KEY );

                    sessStat.lastByteRead = session.getReadBytes();
                    sessStat.lastByteWrite = session.getWrittenBytes();
                    sessStat.lastMessageRead = session.getReadMessages();
                    sessStat.lastMessageWrite = session.getWrittenMessages();
                }

                // wait polling time
                try
                {
                    Thread.sleep( pollingInterval );
                }
                catch ( InterruptedException e )
                {
                }
               
                float tmpMsgWrittenThroughput = 0f;
                float tmpMsgReadThroughput = 0f;
                float tmpBytesWrittenThroughput = 0f;
                float tmpBytesReadThroughput = 0f;
               
                for ( Iterator iter = polledSessions.iterator(); iter.hasNext(); )
                {
               
                    // upadating individual session statistics
                    IoSession session = ( IoSession ) iter.next();
                    IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute( KEY );

                    sessStat.byteReadThroughput = ( session.getReadBytes() - sessStat.lastByteRead )
                        / ( pollingInterval / 1000f );
                    tmpBytesReadThroughput += sessStat.byteReadThroughput;
                   
                    sessStat.byteWrittenThroughput = ( session.getWrittenBytes() - sessStat.lastByteWrite )
                        / ( pollingInterval / 1000f );
                    tmpBytesWrittenThroughput += sessStat.byteWrittenThroughput;

                    sessStat.messageReadThroughput = ( session.getReadMessages() - sessStat.lastMessageRead )
                        / ( pollingInterval / 1000f );
                    tmpMsgReadThroughput += sessStat.messageReadThroughput;
                   
                    sessStat.messageWrittenThroughput = ( session.getWrittenMessages() - sessStat.lastMessageWrite )
                        / ( pollingInterval / 1000f );
                    tmpMsgWrittenThroughput += sessStat.messageWrittenThroughput;

                    synchronized( StatCollector.this )
                    {
View Full Code Here

        }
    }
   
    private void fireEvent( Event e )
    {
        IoSession session = getSession();
        EventType type = e.getType();
        Object data = e.getData();

        if( type == EventType.RECEIVED )
        {
View Full Code Here

        assertNull( future.getSession() );

        TestThread thread = new TestThread( future );
        thread.start();
       
        IoSession session = new BaseIoSession()
        {
            public IoHandler getHandler()
            {
                return null;
            }
View Full Code Here

        TextLineDecoder decoder =
            new TextLineDecoder(
                    Charset.forName( "UTF-8" ), LineDelimiter.WINDOWS );
       
        CharsetEncoder encoder = Charset.forName( "UTF-8" ).newEncoder();
        IoSession session = new DummySession();
        TestDecoderOutput out = new TestDecoderOutput();
        ByteBuffer in = ByteBuffer.allocate( 16 );
    
        // Test one decode and one output
        in.putString( "ABC\r\n", encoder );
View Full Code Here

        TextLineDecoder decoder =
            new TextLineDecoder(
                    Charset.forName( "UTF-8" ), LineDelimiter.AUTO );
       
        CharsetEncoder encoder = Charset.forName( "UTF-8" ).newEncoder();
        IoSession session = new DummySession();
        TestDecoderOutput out = new TestDecoderOutput();
        ByteBuffer in = ByteBuffer.allocate( 16 );
    
        // Test one decode and one output
        in.putString( "ABC\r\n", encoder );
View Full Code Here

                    "codec",
                    new ProtocolCodecFilter( new ObjectSerializationCodecFactory() ) );
        }
        cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
       
        IoSession session;
        for( ;; )
        {
            try
            {
                ConnectFuture future = connector.connect(
                        new InetSocketAddress( HOSTNAME, PORT ),
                        new ClientSessionHandler( values ), cfg );
               
                future.join();
                session = future.getSession();
                break;
            }
            catch( RuntimeIOException e )
            {
                System.err.println( "Failed to connect." );
                e.printStackTrace();
                Thread.sleep( 5000 );
            }
        }

        // wait until the summation is done
        session.getCloseFuture().join();
    }
View Full Code Here

    public void testEncode() throws Exception
    {
        TextLineEncoder encoder = new TextLineEncoder(
                Charset.forName( "UTF-8" ), LineDelimiter.WINDOWS );
        IoSession session = new DummySession();
        SimpleProtocolEncoderOutput out =
            new SimpleProtocolEncoderOutput()
            {
                protected WriteFuture doFlush( ByteBuffer buf )
                {
View Full Code Here

TOP

Related Classes of org.apache.mina.common.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.