Search in sources :

Example 1 with Request

use of edu.umass.cs.gigapaxos.interfaces.Request in project GNS by MobilityFirst.

the class AbstractGNSClient method desktopSendCommmandAndWait.

// arun: changed this to return CommandValueReturnPacket
private ResponsePacket desktopSendCommmandAndWait(JSONObject command) throws IOException {
    Object myMonitor = new Object();
    long id;
    monitorMap.put(id = this.generateNextRequestID(), myMonitor);
    CommandPacket commandPacket = desktopSendCommmandNoWait(command, id);
    // now we wait until the correct packet comes back
    try {
        GNSClientConfig.getLogger().log(Level.FINE, "{0} waiting for query {1}", new Object[] { this, id + "" });
        long monitorStartTime = System.currentTimeMillis();
        if (!USE_GLOBAL_MONITOR) {
            synchronized (myMonitor) {
                while (monitorMap.containsKey(id) && (readTimeout == 0 || System.currentTimeMillis() - monitorStartTime < readTimeout)) {
                    myMonitor.wait(readTimeout);
                }
            }
        } else {
            synchronized (monitor) {
                while (!resultMap.containsKey(id) && (readTimeout == 0 || System.currentTimeMillis() - monitorStartTime < readTimeout)) {
                    monitor.wait(readTimeout);
                }
            }
        }
        if (readTimeout != 0 && System.currentTimeMillis() - monitorStartTime >= readTimeout) {
            return getTimeoutResponse(this, commandPacket);
        }
        GNSClientConfig.getLogger().log(Level.FINE, "Response received for query {0}", new Object[] { id + "" });
    } catch (InterruptedException x) {
        GNSClientConfig.getLogger().severe("Wait for return packet was interrupted " + x);
    }
    //CommandResult 
    Request result = resultMap.remove(id);
    GNSClientConfig.getLogger().log(Level.FINE, "{0} received response {1} ", new Object[] { this, result.getSummary() });
    return result instanceof ResponsePacket ? ((ResponsePacket) result) : new ResponsePacket(result.getServiceName(), id, ResponseCode.ACTIVE_REPLICA_EXCEPTION, ((ActiveReplicaError) result).getResponseMessage());
}
Also used : ResponsePacket(edu.umass.cs.gnscommon.packets.ResponsePacket) Request(edu.umass.cs.gigapaxos.interfaces.Request) JSONObject(org.json.JSONObject) ActiveReplicaError(edu.umass.cs.reconfiguration.reconfigurationpackets.ActiveReplicaError) CommandPacket(edu.umass.cs.gnscommon.packets.CommandPacket)

Example 2 with Request

use of edu.umass.cs.gigapaxos.interfaces.Request in project GNS by MobilityFirst.

the class ActiveGNSClient method read.

@Override
public JSONObject read(InternalRequestHeader header, String targetGUID, String field) throws ClientException, InternalRequestException {
    try {
        Request request = this.executeCommand(GNSCommandInternal.fieldRead(targetGUID, field, header));
        InternalCommandPacket packet = (InternalCommandPacket) request;
        return packet.getResultJSONObject();
    } catch (IOException | JSONException e) {
        throw new ClientException(e);
    }
}
Also used : Request(edu.umass.cs.gigapaxos.interfaces.Request) InternalCommandPacket(edu.umass.cs.gnsserver.gnsapp.packet.InternalCommandPacket) JSONException(org.json.JSONException) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 3 with Request

use of edu.umass.cs.gigapaxos.interfaces.Request in project GNS by MobilityFirst.

the class GNSApp method execute.

/**
   *
   * @param request
   * @param doNotReplyToClient
   * @return true if the command is successfully executed
   */
@SuppressWarnings("unchecked")
// we explicitly check type
@Override
public boolean execute(Request request, boolean doNotReplyToClient) {
    boolean executed = false;
    if (executeNoop(request)) {
        return true;
    }
    try {
        Packet.PacketType packetType = request.getRequestType() instanceof Packet.PacketType ? (Packet.PacketType) request.getRequestType() : null;
        GNSConfig.getLogger().log(Level.FINE, "{0} starting execute({1}) doNotReplyToClient={2}", new Object[] { this, request.getSummary(), doNotReplyToClient });
        Request prev = null;
        // arun: enqueue request, dequeue before returning
        if (request instanceof RequestIdentifier) {
            if (enqueueCommand()) {
                prev = this.outstanding.putIfAbsent(((RequestIdentifier) request).getRequestID(), request);
            }
        } else {
            assert (false) : this + " should not be getting requests that do not implement " + RequestIdentifier.class;
        }
        switch(packetType) {
            case SELECT_REQUEST:
                Select.handleSelectRequest((SelectRequestPacket) request, this);
                break;
            case SELECT_RESPONSE:
                Select.handleSelectResponse((SelectResponsePacket) request, this);
                break;
            case COMMAND:
                CommandHandler.handleCommandPacket((CommandPacket) request, doNotReplyToClient, this);
                break;
            case ADMIN_COMMAND:
                CommandHandler.handleCommandPacket((AdminCommandPacket) request, doNotReplyToClient, this);
                break;
            default:
                assert (false) : (this + " should not be getting packets of type " + packetType + "; exiting");
                GNSConfig.getLogger().log(Level.SEVERE, " Packet type not found: {0}", request.getSummary());
                return false;
        }
        executed = true;
        // arun: always clean up all created state upon exiting
        if (request instanceof RequestIdentifier && prev == null) {
            GNSConfig.getLogger().log(Level.FINE, "{0} finished execute({1})  ->  {2}", new Object[] { this, request.getSummary(), request instanceof ClientRequest && ((ClientRequest) request).getResponse() != null ? ((ClientRequest) request).getResponse().getSummary() : null });
            this.outstanding.remove(((RequestIdentifier) request).getRequestID());
        }
    } catch (JSONException | IOException | ClientException | InternalRequestException e) {
        e.printStackTrace();
    } catch (FailedDBOperationException e) {
        // all database operations throw this exception, therefore we keep
        // throwing this exception upwards and catch this
        // here.
        // A database operation error would imply that the application
        // hasn't been able to successfully execute
        // the request. therefore, this method returns 'false', hoping that
        // whoever calls handleDecision would retry
        // the request.
        GNSConfig.getLogger().log(Level.SEVERE, "Error handling request: {0}", request.toString());
        e.printStackTrace();
    }
    return executed;
}
Also used : Packet(edu.umass.cs.gnsserver.gnsapp.packet.Packet) InternalCommandPacket(edu.umass.cs.gnsserver.gnsapp.packet.InternalCommandPacket) CommandPacket(edu.umass.cs.gnscommon.packets.CommandPacket) ResponsePacket(edu.umass.cs.gnscommon.packets.ResponsePacket) SelectRequestPacket(edu.umass.cs.gnsserver.gnsapp.packet.SelectRequestPacket) SelectResponsePacket(edu.umass.cs.gnsserver.gnsapp.packet.SelectResponsePacket) AdminCommandPacket(edu.umass.cs.gnscommon.packets.AdminCommandPacket) InternalRequestException(edu.umass.cs.gnscommon.exceptions.server.InternalRequestException) 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) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) PacketType(edu.umass.cs.gnsserver.gnsapp.packet.Packet.PacketType) ClientRequest(edu.umass.cs.gigapaxos.interfaces.ClientRequest) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) RequestIdentifier(edu.umass.cs.gigapaxos.interfaces.RequestIdentifier)

Example 4 with Request

use of edu.umass.cs.gigapaxos.interfaces.Request 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 5 with Request

use of edu.umass.cs.gigapaxos.interfaces.Request in project GNS by MobilityFirst.

the class GNSClient method sendSyncInternal.

/**
	 * All sync sends come here, which in turn calls
	 * {@link #sendAsync(CommandPacket, Callback)}{@code .get(timeout)}.
	 * 
	 * @param packet
	 * @param timeout
	 * @return
	 * @throws IOException
	 * @throws ClientException
	 */
private ResponsePacket sendSyncInternal(CommandPacket packet, final long timeout) throws IOException, ClientException {
    ResponsePacket[] processed = new ResponsePacket[1];
    Callback<Request, CommandPacket> future = new Callback<Request, CommandPacket>() {

        @Override
        public CommandPacket processResponse(Request response) {
            GNSClientConfig.getLogger().log(Level.FINE, "{0} received response {1} for request {2}", new Object[] { GNSClient.this, packet.getSummary(), response.getSummary() });
            processed[0] = defaultHandleResponse(response);
            return packet;
        }
    };
    try {
        this.sendAsync(packet, future).get(timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new ClientException(e);
    }
    return processed[0];
/* We could also simply have used gigapaxos' sync send above, but using
		 * the async code above avoids the redundancy with sendAsync on checking
		 * for anycast/proxy/default. */
}
Also used : Callback(edu.umass.cs.gigapaxos.interfaces.Callback) ResponsePacket(edu.umass.cs.gnscommon.packets.ResponsePacket) Request(edu.umass.cs.gigapaxos.interfaces.Request) ReconfiguratorRequest(edu.umass.cs.reconfiguration.interfaces.ReconfiguratorRequest) ClientRequest(edu.umass.cs.gigapaxos.interfaces.ClientRequest) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) ExecutionException(java.util.concurrent.ExecutionException) InternalCommandPacket(edu.umass.cs.gnsserver.gnsapp.packet.InternalCommandPacket) CommandPacket(edu.umass.cs.gnscommon.packets.CommandPacket) TimeoutException(java.util.concurrent.TimeoutException)

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