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. */
}
Aggregations