Package net.gleamynode.netty.array

Examples of net.gleamynode.netty.array.ByteArray


            context.sendDownstream(element);
            return;
        }

        // Otherwise, all messages are encrypted.
        ByteArray msg = (ByteArray) e.getMessage();
        PendingWrite pendingWrite =
            new PendingWrite(element.getFuture(), msg.getByteBuffer());
        synchronized (pendingUnencryptedWrites) {
            pendingUnencryptedWrites.offer(pendingWrite);
        }

        wrap(context, element.getChannel());
View Full Code Here


    private ChannelFuture wrap(ChannelHandlerContext context, Channel channel)
            throws SSLException {

        ChannelFuture future = null;
        ByteArray msg;
        ByteBuffer outNetBuf = bufferPool.acquire();
        try {
            loop:
            for (;;) {
                // Acquire a lock to make sure unencrypted data is polled
                // in order and their encrypted counterpart is offered in
                // order.
                synchronized (pendingUnencryptedWrites) {
                    PendingWrite pendingWrite = pendingUnencryptedWrites.peek();
                    if (pendingWrite == null) {
                        break;
                    }

                    ByteBuffer outAppBuf = pendingWrite.outAppBuf;

                    SSLEngineResult result;
                    try {
                        result = engine.wrap(outAppBuf, outNetBuf);
                    } finally {
                        if (!outAppBuf.hasRemaining()) {
                            pendingUnencryptedWrites.remove();
                        }
                    }
                    if (result.bytesProduced() > 0) {
                        outNetBuf.flip();
                        msg = new HeapByteArray(outNetBuf.remaining());
                        msg.set(msg.firstIndex(), outNetBuf.array(), 0, msg.length());
                        outNetBuf.clear();

                        if (pendingWrite.outAppBuf.hasRemaining()) {
                            // pendingWrite's future shouldn't be notified if
                            // only partial data is written.
View Full Code Here

            for (;;) {
                result = engine.wrap(EMPTY_BUFFER, outNetBuf);

                if (result.bytesProduced() > 0) {
                    outNetBuf.flip();
                    ByteArray msg = new HeapByteArray(outNetBuf.remaining());
                    msg.set(msg.firstIndex(), outNetBuf.array(), 0, msg.length());
                    outNetBuf.clear();
                    if (channel.isConnected()) {
                        future = new DefaultChannelFuture(channel, false);
                        ChannelUtil.write(ctx, channel, future, msg);
                    }
View Full Code Here

            }

            outAppBuf.flip();

            if (outAppBuf.hasRemaining()) {
                ByteArray frame = new HeapByteArray(outAppBuf.remaining());
                frame.set(frame.firstIndex(), outAppBuf.array(), 0, frame.length());
                return frame;
            } else {
                return null;
            }
        } catch (SSLException e) {
View Full Code Here

        if (readBytes > 0) {
            // Update the predictor.
            predictor.previousReceiveBufferSize(readBytes);

            // Fire the event.
            ByteArray array;
            if (readBytes == buf.capacity()) {
                array = new HeapByteArray(buf.array());
            } else {
                array = new StaticPartialByteArray(buf.array(), 0, readBytes);
            }
View Full Code Here

                    channel.currentWriteEvent = channel.writeBuffer.poll();
                    channel.currentWriteIndex =
                        ((ByteArray) channel.currentWriteEvent.getMessage()).firstIndex();
                }

                ByteArray a = (ByteArray) channel.currentWriteEvent.getMessage();
                int localWrittenBytes = 0;
                try {
                    for (int i = channel.getConfig().getWriteSpinCount(); i > 0; i --) {
                        localWrittenBytes = a.copyTo(
                            channel.socket,
                            channel.currentWriteIndex,
                            Math.min(maxWrittenBytes - writtenBytes, a.length() - (channel.currentWriteIndex - a.firstIndex())));
                        if (localWrittenBytes != 0) {
                            break;
                        }
                    }
                } catch (Throwable t) {
                    channel.currentWriteEvent.getFuture().setFailure(t);
                    fireExceptionCaught(channel, t);
                }

                writtenBytes += localWrittenBytes;
                channel.currentWriteIndex += localWrittenBytes;
                if (channel.currentWriteIndex == a.endIndex()) {
                    channel.currentWriteEvent.getFuture().setSuccess();
                    channel.currentWriteEvent = null;
                } else if (localWrittenBytes == 0 || writtenBytes < maxWrittenBytes) {
                    addOpWrite = true;
                    break;
View Full Code Here

                    fireExceptionCaught(channel, t);
                }
                break;
            }

            ByteArray array;
            if (readBytes == buf.length) {
                array = new HeapByteArray(buf);
            } else {
                array = new StaticPartialByteArray(buf, 0, readBytes);
            }
View Full Code Here

        firstIndex = 0;
    }

    @Override
    public ByteArray read() {
        ByteArray a;
        if (isReplaying()) {
            a = (ByteArray) replay();
        } else if (empty()) {
            rewind();
            return null;
        } else {
            a = record(super.read());
        }

        firstIndex += a.length();
        return a;
    }
View Full Code Here

        return a;
    }

    @Override
    public ByteArray read(ByteArrayIndexFinder endIndexFinder) {
        ByteArray a;
        if (isReplaying()) {
            a = (ByteArray) replay();
        } else if (super.indexOf(0, endIndexFinder) == NOT_FOUND) {
            rewind();
            return null;
        } else {
            a = record(super.read(endIndexFinder));
        }

        firstIndex += a.length();
        return a;
    }
View Full Code Here

        return a;
    }

    @Override
    public ByteArray read(int length) {
        ByteArray a;
        if (isReplaying()) {
            a = (ByteArray) replay();
            if (a.length() != length) {
                throw new IllegalStateException("mismatching request");
            }
        } else if (length > super.length()) {
            rewind();
            return null;
View Full Code Here

TOP

Related Classes of net.gleamynode.netty.array.ByteArray

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.