use of edu.umass.cs.gigapaxos.interfaces.RequestIdentifier 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;
}
Aggregations