Search in sources :

Example 11 with ResponsePacket

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()));
                }
            }
        }
    }
}
Also used : ResponsePacket(edu.umass.cs.gnscommon.packets.ResponsePacket) Request(edu.umass.cs.gigapaxos.interfaces.Request)

Example 12 with ResponsePacket

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()));
}
Also used : ResponsePacket(edu.umass.cs.gnscommon.packets.ResponsePacket) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Aggregations

ResponsePacket (edu.umass.cs.gnscommon.packets.ResponsePacket)12 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)4 JSONObject (org.json.JSONObject)4 Test (org.junit.Test)4 Request (edu.umass.cs.gigapaxos.interfaces.Request)3 ActiveReplicaError (edu.umass.cs.reconfiguration.reconfigurationpackets.ActiveReplicaError)3 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)2 CommandPacket (edu.umass.cs.gnscommon.packets.CommandPacket)2 Callback (edu.umass.cs.gigapaxos.interfaces.Callback)1 ClientRequest (edu.umass.cs.gigapaxos.interfaces.ClientRequest)1 InternalCommandPacket (edu.umass.cs.gnsserver.gnsapp.packet.InternalCommandPacket)1 ReconfiguratorRequest (edu.umass.cs.reconfiguration.interfaces.ReconfiguratorRequest)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 JSONException (org.json.JSONException)1