Package net.sf.cindy

Examples of net.sf.cindy.Buffer


                DefaultFuture future) {
            super(packet, priority);
            this.obj = obj;
            this.future = future;

            Buffer content = packet.getContent();
            position = content.position();
            limit = content.limit();
        }
View Full Code Here


                        currentSendPacket = null;
                        future.setSucceeded(false);
                        continue;
                    }

                    Buffer buffer = currentSendPacket.getContent();
                    if (!buffer.hasRemaining() || write(currentSendPacket)) {
                        buffer.limit(currentSendPacket.limit);
                        buffer.position(currentSendPacket.position);
                        buffer.release();
                        final FuturePacket packet = currentSendPacket;
                        currentSendPacket = null;

                        // keep dispatch order
                        dispatch(new Runnable() {
View Full Code Here

            public SelectableChannel[] getChannels() {
                return new SelectableChannel[] { pipe.sink(), pipe.source() };
            }

            protected void read() throws IOException {
                Buffer buffer = BufferFactory.allocate(getReadPacketSize());
                SourceChannel source = pipe.source();
                int n = -1;
                int readCount = 0;

                try {
                    while ((n = buffer.read(source)) >= 0) {
                        if (n == 0)
                            break;
                        readCount += n;
                    }
                } catch (IOException e) {
                    buffer.release();
                    throw e;
                }

                if (readCount > 0) {
                    buffer.flip();
                    getSessionFilterChain(false).packetReceived(
                            new DefaultPacket(buffer));
                }
                if (n < 0) // Connection closed
                    throw new ClosedChannelException();
            }

            protected boolean write(Packet packet) throws IOException {
                Buffer buffer = packet.getContent();
                SinkChannel sink = pipe.sink();
                while (true) {
                    int n = buffer.write(sink);
                    if (!buffer.hasRemaining())
                        return true;
                    else if (n == 0) {
                        // have more data, but the kennel buffer
                        // is full, wait next time to write
                        return false;
View Full Code Here

    }

    protected void recognize(Buffer content, SocketAddress address)
            throws Exception {
        while (content.hasRemaining()) {
            Buffer slice = content.asReadOnlyBuffer().slice();
            Object obj = session.getPacketDecoder().decode(session,
                    new DefaultPacket(slice, address));
            if (obj == null)
                break;
            content.skip(slice.position());
            session.getSessionFilterChain(false).objectReceived(obj);
        }
    }
View Full Code Here

        public void packetReceived(SessionFilterChain filterChain, Packet packet)
                throws Exception {
            if (packet == null || filterChain.getSession() != session)
                super.packetReceived(filterChain, packet);
            else {
                Buffer content = packet.getContent();
                if (content != null)
                    try {
                        recognize(content, packet.getAddress());
                    } finally {
                        content.release();
                    }
            }
        }
View Full Code Here

            synchronized (this) {
                if (content == null) {
                    content = packet.getContent();
                    address = packet.getAddress();
                } else {
                    Buffer recvContent = packet.getContent();
                    if (content.remaining() < recvContent.remaining()) {
                        Buffer newContent = BufferFactory.allocate(
                                content.position() + recvContent.remaining())
                                .put(content.flip());
                        content.release();
                        content = newContent;
                    }
View Full Code Here

TOP

Related Classes of net.sf.cindy.Buffer

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.