예제 #1
0
        public Receive DoSend(RequestOrResponse request, bool readResponse = true)
        {
            lock (@lock)
            {
                this.VerifyRequest(request);
                this.GetOrMakeConnection();

                Receive response = null;
                try
                {
                    this.blockingChannel.Send(request);
                    if (readResponse)
                    {
                        response = this.blockingChannel.Receive();
                    }
                    else
                    {
                        Logger.Debug("Skipping reading response");
                    }
                }
                catch (IOException)
                {
                    // no way to tell if write succeeded. Disconnect and re-throw exception to let client handle retry
                    this.Disconnect();
                    throw;
                }

                return response;
            }
        }
예제 #2
0
        public BoundedByteBufferSend(RequestOrResponse request) : this(request.SizeInBytes + (request.RequestId.HasValue ? 2 : 0))
        {
            if (request.RequestId.HasValue)
            {
                this.Buffer.PutShort(request.RequestId.Value);
            } 

            request.WriteTo(this.Buffer);
            this.Buffer.Rewind();
        }
예제 #3
0
 private void VerifyRequest(RequestOrResponse request)
 {
     /**
      * This seems a little convoluted, but the idea is to turn on verification simply changing log4j settings
      * Also, when verification is turned on, care should be taken to see that the logs don't fill up with unnecessary
      * Data. So, leaving the rest of the logging at TRACE, while errors should be logged at ERROR level
      */
     if (Logger.IsDebugEnabled)
     {
         var buffer = new BoundedByteBufferSend(request).Buffer;
         Logger.Debug("Verifying sendbuffer of size " + buffer.Limit());
         var requestTypeId = buffer.GetShort();
         if (requestTypeId == RequestKeys.ProduceKey)
         {
             var innerRequest = ProducerRequest.ReadFrom(buffer);
             Logger.Debug(innerRequest.ToString());
         }
     }
 }
예제 #4
0
        private Receive SendRequest(RequestOrResponse request)
        {
            lock (@lock)
            {
                this.GetOrMakeConnection();
                Receive response;
                try
                {
                    this.blockingChannel.Send(request);
                    response = this.blockingChannel.Receive();
                }
                catch (Exception e)
                {
                    Logger.WarnFormat("Reconnect due to socket error {0}", e.Message);

                    // retry once
                    try
                    {
                        this.Reconnect();
                        this.blockingChannel.Send(request);
                        response = this.blockingChannel.Receive();
                    }
                    catch (Exception)
                    {
                        this.Disconnect();
                        throw;
                    }
                }

                return response;
            }
        }
예제 #5
0
        public int Send(RequestOrResponse request)
        {
            if (!this.conneted)
            {
                throw new IOException("Channel is closed!");
            }

            var send = new BoundedByteBufferSend(request);
            return send.WriteCompletely(this.writeChannel);
        }