Beispiel #1
0
        private void ReadNextChunk()
        {
            ChannelBuffer readBuffer = ReadNext();

            /* Header layout:
             * [    ,    ][    ,   x] 0: last chunk in message, 1: there a more chunks after this one
             * [    ,    ][    ,  x ] 0: success, 1: failure
             * [    ,    ][xxxx,xx  ] internal protocol version
             * [xxxx,xxxx][    ,    ] application protocol version */
            sbyte[] header = new sbyte[2];
            readBuffer.readBytes(header);
            _more    = (header[0] & 0x1) != 0;
            _failure = (header[0] & 0x2) != 0;
            AssertSameProtocolVersion(header, _internalProtocolVersion, _applicationProtocolVersion);

            if (!_more && _buffer == null)
            {
                // Optimization: this is the first chunk and it'll be the only chunk
                // in this message.
                _buffer = readBuffer;
            }
            else
            {
                _buffer = _buffer == null?ChannelBuffers.dynamicBuffer() : _buffer;

                DiscardReadBytes();
                _buffer.writeBytes(readBuffer);
            }

            if (_failure)
            {
                ReadAndThrowFailureResponse();
            }
        }
Beispiel #2
0
 protected internal virtual ChannelBuffer MapSlave(Channel channel, RequestContext slave)
 {
     // Checking for machineId -1 excludes the "empty" slave contexts
     // which some communication points pass in as context.
     if (slave != null && slave.MachineId() != RequestContext.Empty.machineId())
     {
         _connectedSlaveChannels.add(channel, slave);
     }
     return(ChannelBuffers.dynamicBuffer());
 }
Beispiel #3
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: protected void handleRequest(org.jboss.netty.buffer.ChannelBuffer buffer, final org.jboss.netty.channel.Channel channel)
        protected internal virtual void HandleRequest(ChannelBuffer buffer, Channel channel)
        {
            sbyte?continuation = ReadContinuationHeader(buffer, channel);

            if (continuation == null)
            {
                return;
            }
            if (continuation.Value == ChunkingChannelBuffer.CONTINUATION_MORE)
            {
                PartialRequest partialRequest = _partialRequests[channel];
                if (partialRequest == null)
                {
                    // This is the first chunk in a multi-chunk request
                    RequestType    type         = GetRequestContext(buffer.readByte());
                    RequestContext context      = ReadContext(buffer);
                    ChannelBuffer  targetBuffer = MapSlave(channel, context);
                    partialRequest            = new PartialRequest(this, type, context, targetBuffer);
                    _partialRequests[channel] = partialRequest;
                }
                partialRequest.Add(buffer);
            }
            else
            {
                PartialRequest partialRequest = _partialRequests.Remove(channel);
                RequestType    type;
                RequestContext context;
                ChannelBuffer  targetBuffer;
                ChannelBuffer  bufferToReadFrom;
                ChannelBuffer  bufferToWriteTo;
                if (partialRequest == null)
                {
                    // This is the one and single chunk in the request
                    type             = GetRequestContext(buffer.readByte());
                    context          = ReadContext(buffer);
                    targetBuffer     = MapSlave(channel, context);
                    bufferToReadFrom = buffer;
                    bufferToWriteTo  = targetBuffer;
                }
                else
                {
                    // This is the last chunk in a multi-chunk request
                    type         = partialRequest.Type;
                    context      = partialRequest.Context;
                    targetBuffer = partialRequest.Buffer;
                    partialRequest.Add(buffer);
                    bufferToReadFrom = targetBuffer;
                    bufferToWriteTo  = ChannelBuffers.dynamicBuffer();
                }

                bufferToWriteTo.clear();
                ChunkingChannelBuffer chunkingBuffer = NewChunkingBuffer(bufferToWriteTo, channel, _chunkSize, InternalProtocolVersion, _applicationProtocolVersion);
                SubmitSilent(_targetCallExecutor, new TargetCaller(this, type, channel, context, chunkingBuffer, bufferToReadFrom));
            }
        }
Beispiel #4
0
            protected internal override ChannelContext create()
            {
                _outerInstance.msgLog.info(threadInfo() + "Trying to open a new channel from " + _outerInstance.origin + " to " + _outerInstance.destination);
                // We must specify the origin address in case the server has multiple IPs per interface
                ChannelFuture channelFuture = _outerInstance.bootstrap.connect(_outerInstance.destination, _outerInstance.origin);

                channelFuture.awaitUninterruptibly(5, TimeUnit.SECONDS);
                if (channelFuture.Success)
                {
                    _outerInstance.msgLog.info(threadInfo() + "Opened a new channel from " + channelFuture.Channel.LocalAddress + " to " + channelFuture.Channel.RemoteAddress);

                    return(new ChannelContext(channelFuture.Channel, ChannelBuffers.dynamicBuffer(), ByteBuffer.allocate(1024 * 1024)));
                }

                Exception cause = channelFuture.Cause;
                string    msg   = _outerInstance.GetType().Name + " could not connect from " + _outerInstance.origin + " to " + _outerInstance.destination;

                _outerInstance.msgLog.debug(msg);
                throw outerInstance.traceComException(new ComException(msg, cause), "Client.start");
            }
Beispiel #5
0
 protected internal virtual ChannelBuffer NewChannelBuffer()
 {
     return(ChannelBuffers.dynamicBuffer(_capacity));
 }
Beispiel #6
0
 private ChunkingChannelBuffer NewChunkingBuffer(Channel channel)
 {
     return(NewChunkingBuffer(ChannelBuffers.dynamicBuffer(), channel, _chunkSize, InternalProtocolVersion, _applicationProtocolVersion));
 }