use of edu.umass.cs.gnscommon.packets.ResponsePacket 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.gnscommon.packets.ResponsePacket in project GNS by MobilityFirst.
the class ByteificationComparison method test_14_CommandValueReturnPacket_128B.
/**
*
* @throws UnsupportedEncodingException
* @throws JSONException
*/
@Test
public void test_14_CommandValueReturnPacket_128B() throws UnsupportedEncodingException, JSONException {
ResponsePacket packet = new ResponsePacket(1, ResponseCode.NO_ERROR.getCodeValue(), new String(Util.getRandomAlphanumericBytes(64)), new String(Util.getRandomAlphanumericBytes(64)));
long startTime = System.nanoTime();
for (int i = 0; i < TEST_RUNS; i++) {
byte[] bytes = packet.toBytes();
ResponsePacket.fromBytes(bytes);
}
long endTime = System.nanoTime();
double avg = (endTime - startTime) / (TEST_RUNS);
System.out.println("Average byteification time CommandValueReturnPacket 128B was " + avg + " nanoseconds.");
byte[] bytes = packet.toBytes();
ResponsePacket outputPacket = ResponsePacket.fromBytes(bytes);
assert (packet.toJSONObject().toString().equals(outputPacket.toJSONObject().toString()));
}
Aggregations