Search in sources :

Example 6 with Request

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

Example 7 with Request

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
}
Also used : ReconfigurableRequest(edu.umass.cs.reconfiguration.interfaces.ReconfigurableRequest) Request(edu.umass.cs.gigapaxos.interfaces.Request) ClientRequest(edu.umass.cs.gigapaxos.interfaces.ClientRequest) BasicPacketWithClientAddress(edu.umass.cs.gnsserver.gnsapp.packet.BasicPacketWithClientAddress) ClientRequest(edu.umass.cs.gigapaxos.interfaces.ClientRequest)

Example 8 with Request

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;
}
Also used : RequestParseException(edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException) JSONObject(org.json.JSONObject) Request(edu.umass.cs.gigapaxos.interfaces.Request) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Request (edu.umass.cs.gigapaxos.interfaces.Request)8 ClientRequest (edu.umass.cs.gigapaxos.interfaces.ClientRequest)4 ResponsePacket (edu.umass.cs.gnscommon.packets.ResponsePacket)4 JSONException (org.json.JSONException)4 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)3 CommandPacket (edu.umass.cs.gnscommon.packets.CommandPacket)3 InternalCommandPacket (edu.umass.cs.gnsserver.gnsapp.packet.InternalCommandPacket)3 ReconfigurableRequest (edu.umass.cs.reconfiguration.interfaces.ReconfigurableRequest)3 JSONObject (org.json.JSONObject)3 RequestParseException (edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException)2 IOException (java.io.IOException)2 Callback (edu.umass.cs.gigapaxos.interfaces.Callback)1 RequestIdentifier (edu.umass.cs.gigapaxos.interfaces.RequestIdentifier)1 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)1 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)1 AdminCommandPacket (edu.umass.cs.gnscommon.packets.AdminCommandPacket)1 BasicPacketWithClientAddress (edu.umass.cs.gnsserver.gnsapp.packet.BasicPacketWithClientAddress)1 Packet (edu.umass.cs.gnsserver.gnsapp.packet.Packet)1 PacketType (edu.umass.cs.gnsserver.gnsapp.packet.Packet.PacketType)1 SelectRequestPacket (edu.umass.cs.gnsserver.gnsapp.packet.SelectRequestPacket)1