use of edu.umass.cs.gigapaxos.interfaces.Request in project GNS by MobilityFirst.
the class ClientAsynchExample method lookForResponses.
// Not saying this is the best way to handle responses, but it works for this example.
private static void lookForResponses(GNSClient client, Set<Long> pendingIds) {
while (true) {
ThreadUtils.sleep(10);
// Loop through all the ones we've sent
for (Long id : pendingIds) {
if (//client.isAsynchResponseReceived(id)
true) {
// arun: disabled
if (true) {
throw new RuntimeException("disabled");
}
pendingIds.remove(id);
//client.removeAsynchResponse(id);
Request removed = null;
if (removed instanceof ResponsePacket) {
ResponsePacket commandResult = ((ResponsePacket) removed);
System.out.println("commandResult for " + id + " is " + (commandResult.getErrorCode().equals(ResponseCode.NO_ERROR) ? commandResult.getReturnValue() : commandResult.getErrorCode().toString()));
}
}
}
}
}
use of edu.umass.cs.gigapaxos.interfaces.Request in project GNS by MobilityFirst.
the class GNSApp method sendToClient.
/**
* Delegates client messaging to gigapaxos.
*
* @param responseJSON
* @throws java.io.IOException
*/
@Override
public void sendToClient(Request response, JSONObject responseJSON) throws IOException {
if (DELEGATE_CLIENT_MESSAGING) {
assert (response instanceof ClientRequest);
Request originalRequest = this.outstanding.remove(((RequestIdentifier) response).getRequestID());
assert (originalRequest != null && originalRequest instanceof BasicPacketWithClientAddress) : ((ClientRequest) response).getSummary();
if (originalRequest != null && originalRequest instanceof BasicPacketWithClientAddress) {
((BasicPacketWithClientAddress) originalRequest).setResponse((ClientRequest) response);
incrResponseCount((ClientRequest) response);
}
GNSConfig.getLogger().log(Level.FINE, "{0} set response {1} for requesting client {2} for request {3}", new Object[] { this, response, ((BasicPacketWithClientAddress) originalRequest).getClientAddress(), originalRequest.getSummary() });
return;
}
// else
}
use of edu.umass.cs.gigapaxos.interfaces.Request in project GNS by MobilityFirst.
the class GNSAppUtil method getRequestStatic.
/**
* This method avoids an unnecessary restringification (as is the case with
* {@link GNSApp#getRequest(String)} above) by decoding the JSON, stamping it with
* the sender information, and then creating a packet out of it.
*
* @param msgBytes
* @param header
* @param unstringer
* @return Request constructed from msgBytes.
* @throws RequestParseException
*/
public static Request getRequestStatic(byte[] msgBytes, NIOHeader header, Stringifiable<String> unstringer) throws RequestParseException {
Request request = null;
try {
long t = System.nanoTime();
if (JSONPacket.couldBeJSON(msgBytes)) {
JSONObject json = new JSONObject(new String(msgBytes, NIOHeader.CHARSET));
MessageExtractor.stampAddressIntoJSONObject(header.sndr, header.rcvr, json);
request = (Request) Packet.createInstance(json, unstringer);
} else {
// parse non-JSON byteified form
return fromBytes(msgBytes);
}
if (Util.oneIn(100)) {
DelayProfiler.updateDelayNano("getRequest." + request.getRequestType(), t);
}
} catch (JSONException | UnsupportedEncodingException e) {
throw new RequestParseException(e);
}
return request;
}
Aggregations