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; } }
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(); }
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()); } } }
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; } }
public int Send(RequestOrResponse request) { if (!this.conneted) { throw new IOException("Channel is closed!"); } var send = new BoundedByteBufferSend(request); return send.WriteCompletely(this.writeChannel); }