Package org.apache.mina.common

Examples of org.apache.mina.common.ByteBuffer.remaining()


        }

        public void messageReceived(IoSession session, Object message)
                throws Exception {
            ByteBuffer buffer = (ByteBuffer) message;
            byte[] data = new byte[buffer.remaining()];
            buffer.get(data);
            Object lock = session.getAttribute("lock");
            synchronized (lock) {
                StringBuffer sb = (StringBuffer) session
                        .getAttribute("received");
View Full Code Here


        public void messageSent(IoSession session, Object message)
                throws Exception {
            ByteBuffer buffer = (ByteBuffer) message;
            buffer.rewind();
            byte[] data = new byte[buffer.remaining()];
            buffer.get(data);
            StringBuffer sb = (StringBuffer) session.getAttribute("sent");
            sb.append(new String(data, "ASCII"));
        }
View Full Code Here

   
                if (req == null)
                    break;
   
                ByteBuffer buf = (ByteBuffer) req.getMessage();
                if (buf.remaining() == 0) {
                    synchronized (writeRequestQueue) {
                        writeRequestQueue.pop();
                    }
   
                    buf.reset();
View Full Code Here

        };

        encoder.encode(session, "ABC", out);
        Assert.assertEquals(1, out.getBufferQueue().size());
        ByteBuffer buf = (ByteBuffer) out.getBufferQueue().pop();
        Assert.assertEquals(5, buf.remaining());
        Assert.assertEquals('A', buf.get());
        Assert.assertEquals('B', buf.get());
        Assert.assertEquals('C', buf.get());
        Assert.assertEquals('\r', buf.get());
        Assert.assertEquals('\n', buf.get());
View Full Code Here

                    int byteCount = 1;
                    Object messageCopy = message;
                    if (message instanceof ByteBuffer) {
                        ByteBuffer rb = (ByteBuffer) message;
                        rb.mark();
                        byteCount = rb.remaining();
                        ByteBuffer wb = ByteBuffer.allocate(rb.remaining());
                        wb.put(rb);
                        wb.flip();
                        rb.reset();
                        messageCopy = wb;
View Full Code Here

        // SocketIoProcessor.doFlush() will reset it after write is finished
        // because the buffer will be passed with messageSent event.
        ByteBuffer buffer = (ByteBuffer) writeRequest.getMessage();
        buffer.mark();
       
        int remaining = buffer.remaining();
        if (remaining == 0) {
            s.increaseScheduledWriteRequests();           
        } else {
            s.increaseScheduledWriteBytes(buffer.remaining());
        }
View Full Code Here

       
        int remaining = buffer.remaining();
        if (remaining == 0) {
            s.increaseScheduledWriteRequests();           
        } else {
            s.increaseScheduledWriteBytes(buffer.remaining());
        }

        synchronized (writeRequestQueue) {
            writeRequestQueue.push(writeRequest);
        }
View Full Code Here

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

                session.increaseReadBytes( newBuf.remaining() );
                session.getFilterChain().fireMessageReceived( session, newBuf );
            }
        }
        finally
        {
View Full Code Here

            if( req == null )
                break;

            ByteBuffer buf = ( ByteBuffer ) req.getMessage();
            if( buf.remaining() == 0 )
            {
                // pop and fire event
                synchronized( writeRequestQueue )
                {
                    writeRequestQueue.pop();
View Full Code Here

        }

        public void messageReceived( IoSession session, Object message ) throws Exception
        {
            ByteBuffer buffer = ( ByteBuffer ) message;
            byte[] data = new byte[ buffer.remaining() ];
            buffer.get( data );
            Object lock = session.getAttribute( "lock" );
            synchronized ( lock )
            {
                StringBuffer sb = ( StringBuffer ) session.getAttribute( "received" );
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.