Search in sources :

Example 1 with Callback

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

Callback (edu.umass.cs.gigapaxos.interfaces.Callback)1 ClientRequest (edu.umass.cs.gigapaxos.interfaces.ClientRequest)1 Request (edu.umass.cs.gigapaxos.interfaces.Request)1 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)1 CommandPacket (edu.umass.cs.gnscommon.packets.CommandPacket)1 ResponsePacket (edu.umass.cs.gnscommon.packets.ResponsePacket)1 InternalCommandPacket (edu.umass.cs.gnsserver.gnsapp.packet.InternalCommandPacket)1 ReconfiguratorRequest (edu.umass.cs.reconfiguration.interfaces.ReconfiguratorRequest)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1