private void GenerateGetPrototype(RequestOrResponse which, TextGenerator writer) { writer.WriteLine("public pb::IMessage Get{0}Prototype(pbd::MethodDescriptor method) {{", which); writer.Indent(); writer.WriteLine("if (method.Service != Descriptor) {"); writer.WriteLine(" throw new global::System.ArgumentException("); writer.WriteLine(" \"Service.Get{0}Prototype() given method descriptor for wrong service type.\");", which); writer.WriteLine("}"); writer.WriteLine("switch(method.Index) {"); writer.Indent(); foreach (MethodDescriptor method in Descriptor.Methods) { writer.WriteLine("case {0}:", method.Index); writer.WriteLine(" return {0}.DefaultInstance;", GetClassName(which == RequestOrResponse.Request ? method.InputType : method.OutputType)); } writer.WriteLine("default:"); writer.WriteLine(" throw new global::System.InvalidOperationException(\"Can't get here.\");"); writer.Outdent(); writer.WriteLine("}"); writer.Outdent(); writer.WriteLine("}"); writer.WriteLine(); }
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); } }
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 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(); }
public int Send(RequestOrResponse request) { if (!this.conneted) { throw new IOException("Channel is closed!"); } var send = new BoundedByteBufferSend(request); return(send.WriteCompletely(this.writeChannel)); }
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()); } } }