Search in sources :

Example 1 with HubInvoke

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;
    }
}
Also used : RemoteMethodCallResults(games.strategy.engine.message.RemoteMethodCallResults) GUID(games.strategy.net.GUID) CountDownLatch(java.util.concurrent.CountDownLatch) SpokeInvoke(games.strategy.engine.message.SpokeInvoke) HubInvoke(games.strategy.engine.message.HubInvoke) HubInvoke(games.strategy.engine.message.HubInvoke)

Example 2 with HubInvoke

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());
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) RemoteMethodCall(games.strategy.engine.message.RemoteMethodCall) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HubInvoke(games.strategy.engine.message.HubInvoke)

Example 3 with HubInvoke

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());
            }
        }
    }
}
Also used : RemoteMethodCallResults(games.strategy.engine.message.RemoteMethodCallResults) SpokeInvoke(games.strategy.engine.message.SpokeInvoke) HubInvoke(games.strategy.engine.message.HubInvoke) HubInvoke(games.strategy.engine.message.HubInvoke)

Aggregations

HubInvoke (games.strategy.engine.message.HubInvoke)3 RemoteMethodCallResults (games.strategy.engine.message.RemoteMethodCallResults)2 SpokeInvoke (games.strategy.engine.message.SpokeInvoke)2 RemoteMethodCall (games.strategy.engine.message.RemoteMethodCall)1 RemoteName (games.strategy.engine.message.RemoteName)1 GUID (games.strategy.net.GUID)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1