Search in sources :

Example 1 with RequestParseException

use of edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException in project GNS by MobilityFirst.

the class GNSApp method getRequest.

// For InterfaceApplication
/**
   *
   * @param string
   * @return the request
   * @throws RequestParseException
   */
@Override
public Request getRequest(String string) throws RequestParseException {
    GNSConfig.getLogger().log(Level.FINEST, ">>>>>>>>>>>>>>> GET REQUEST: {0}", string);
    // Special case handling of NoopPacket packets
    if (Request.NO_OP.equals(string)) {
        //new NoopPacket();
        throw new RuntimeException("Should never be here");
    }
    try {
        long t = System.nanoTime();
        JSONObject json = new JSONObject(string);
        if (Util.oneIn(1000)) {
            DelayProfiler.updateDelayNano("jsonificationApp", t);
        }
        Request request = (Request) Packet.createInstance(json, nodeConfig);
        return request;
    } catch (JSONException e) {
        throw new RequestParseException(e);
    }
}
Also used : RequestParseException(edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException) JSONObject(org.json.JSONObject) ReconfigurableRequest(edu.umass.cs.reconfiguration.interfaces.ReconfigurableRequest) Request(edu.umass.cs.gigapaxos.interfaces.Request) ClientRequest(edu.umass.cs.gigapaxos.interfaces.ClientRequest) JSONException(org.json.JSONException)

Example 2 with RequestParseException

use of edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException 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)2 RequestParseException (edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 ClientRequest (edu.umass.cs.gigapaxos.interfaces.ClientRequest)1 ReconfigurableRequest (edu.umass.cs.reconfiguration.interfaces.ReconfigurableRequest)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1