public IFuture <HttpQueryResponse> ProcessQuery(string name, IDictionary <string, string> options, AsyncCallback callback, object state) { QueryRequestMessage request = new QueryRequestMessage.Builder() .SetName(name) .AddRangeOptions(GetQueryOptions(options)) .Build(); RubyMessagePacket packet = GetMessagePacket(GetNextRequestId(), request.ToByteString()); try { QueryFuture future = new SettableFuture <HttpQueryResponse>(state); Tuple <AsyncCallback, QueryFuture> tuple = Tuple.Create(callback, future); futures_.Add(request_id_, tuple); // Send the request and wait for the response. The request should // follow the REQ/REP pattern, which contains the following parts: // 1. [EMPTY FRAME] // 2. [MESSAGE] // socket_.SendMore(); socket_.Send(packet.ToByteArray()); return(future); } catch (ZMQ.Exception zmqe) { return (Futures.ImmediateFuture( GetExceptionResponse(name, HttpStatusCode.InternalServerError, zmqe))); } catch (System.Exception e) { return (Futures.ImmediateFuture( GetExceptionResponse(name, HttpStatusCode.InternalServerError, e))); } }
void ProcessResponse(byte[] response) { try { var packet = RubyMessagePacket.ParseFrom(response); Tuple <AsyncCallback, QueryFuture> tuple; int request_id = packet.Message.Id.ToByteArray().AsInt(); if (futures_.TryGetValue(request_id, out tuple)) { SettableFuture <HttpQueryResponse> future = tuple.Item2; switch (packet.Message.Type) { case (int)MessageType.kQueryResponseMessage: future.Set(GetQueryResponse(packet.Message), false); break; case (int)NodeMessageType.kNodeError: future.Set(GetError(packet.Message), false); break; } tuple.Item1(tuple.Item2); futures_.Remove(request_id_); } } catch (System.Exception exception) { logger_.Error( string.Format(StringResources.Log_MethodThrowsException, "ProcessResponse", kClassName), exception); } }