Exemple #1
0
 internal TargetCaller(Server <T, R> outerInstance, RequestType type, Channel channel, RequestContext context, ChunkingChannelBuffer targetBuffer, ChannelBuffer bufferToReadFrom)
 {
     this._outerInstance   = outerInstance;
     this.Type             = type;
     this.Channel          = channel;
     this.Context          = context;
     this.TargetBuffer     = targetBuffer;
     this.BufferToReadFrom = bufferToReadFrom;
 }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void serializeRequest(org.jboss.netty.channel.Channel channel, org.jboss.netty.buffer.ChannelBuffer buffer, RequestType type, RequestContext ctx, Serializer payload) throws java.io.IOException
        public virtual void SerializeRequest(Channel channel, ChannelBuffer buffer, RequestType type, RequestContext ctx, Serializer payload)
        {
            buffer.clear();
            ChunkingChannelBuffer chunkingBuffer = new ChunkingChannelBuffer(buffer, channel, _chunkSize, _internalProtocolVersion, _applicationProtocolVersion);

            chunkingBuffer.WriteByte(type.Id());
            WriteContext(ctx, chunkingBuffer);
            payload.Write(chunkingBuffer);
            chunkingBuffer.Done();
        }
Exemple #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));
            }
        }
Exemple #4
0
 protected internal virtual void WriteFailureResponse(Exception exception, ChunkingChannelBuffer buffer)
 {
     try
     {
         MemoryStream       bytes = new MemoryStream();
         ObjectOutputStream @out  = new ObjectOutputStream(bytes);
         @out.writeObject(exception);
         @out.close();
         buffer.WriteBytes(bytes.toByteArray());
         buffer.Done();
     }
     catch (IOException)
     {
         _msgLog.warn("Couldn't send cause of error to client", exception);
     }
 }
Exemple #5
0
        public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent @event)
        {
            try
            {
                ChannelBuffer message = ( ChannelBuffer )@event.Message;
                HandleRequest(message, @event.Channel);
            }
            catch (Exception e)
            {
                _msgLog.error("Error handling request", e);

                // Attempt to reply to the client
                ChunkingChannelBuffer buffer = NewChunkingBuffer(@event.Channel);
                buffer.Clear(true);
                WriteFailureResponse(e, buffer);

                ctx.Channel.close();
                TryToCloseChannel(ctx.Channel);
                throw e;
            }
        }