use of games.strategy.engine.message.HubInvoke in project triplea by triplea-game.
the class UnifiedMessenger method invokeAndWaitRemote.
private RemoteMethodCallResults invokeAndWaitRemote(final RemoteMethodCall remoteCall) {
final GUID methodCallId = new GUID();
final CountDownLatch latch = new CountDownLatch(1);
synchronized (pendingLock) {
pendingInvocations.put(methodCallId, latch);
}
// invoke remotely
final Invoke invoke = new HubInvoke(methodCallId, true, remoteCall);
send(invoke, messenger.getServerNode());
Interruptibles.await(latch);
synchronized (pendingLock) {
final RemoteMethodCallResults methodCallResults = results.remove(methodCallId);
if (methodCallResults == null) {
throw new IllegalStateException("No results from remote call. Method returned:" + remoteCall.getMethodName() + " for remote name:" + remoteCall.getRemoteName() + " with id:" + methodCallId);
}
return methodCallResults;
}
}
use of games.strategy.engine.message.HubInvoke in project triplea by triplea-game.
the class ClientMessenger method bareBonesSendMessageToServer.
private void bareBonesSendMessageToServer(final String methodName, final Object... messages) {
final List<Object> args = new ArrayList<>();
final Class<?>[] argTypes = new Class<?>[messages.length];
for (int i = 0; i < messages.length; i++) {
final Object message = messages[i];
args.add(message);
argTypes[i] = args.get(i).getClass();
}
final RemoteName rn = ServerModel.SERVER_REMOTE_NAME;
final RemoteMethodCall call = new RemoteMethodCall(rn.getName(), methodName, args.toArray(), argTypes, rn.getClazz());
final HubInvoke hubInvoke = new HubInvoke(null, false, call);
send(hubInvoke, getServerNode());
}
use of games.strategy.engine.message.HubInvoke in project triplea by triplea-game.
the class UnifiedMessenger method invoke.
/**
* invoke without waiting for remote nodes to respond.
*/
public void invoke(final String endPointName, final RemoteMethodCall call) {
// send the remote invocation
final Invoke invoke = new HubInvoke(null, false, call);
send(invoke, messenger.getServerNode());
// invoke locally
final EndPoint endPoint;
synchronized (endPointMutex) {
endPoint = localEndPoints.get(endPointName);
}
if (endPoint != null) {
final long number = endPoint.takeANumber();
final List<RemoteMethodCallResults> results = endPoint.invokeLocal(call, number, getLocalNode());
for (final RemoteMethodCallResults r : results) {
if (r.getException() != null) {
// don't swallow errors
logger.log(Level.WARNING, r.getException().getMessage(), r.getException());
}
}
}
}
Aggregations