Search in sources :

Example 1 with RemoteMethodCallResults

use of games.strategy.engine.message.RemoteMethodCallResults 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 RemoteMethodCallResults

use of games.strategy.engine.message.RemoteMethodCallResults in project triplea by triplea-game.

the class EndPoint method invokeSingle.

private RemoteMethodCallResults invokeSingle(final RemoteMethodCall call, final Object implementor, final INode messageOriginator) {
    call.resolve(remoteClass);
    final Method method;
    try {
        method = implementor.getClass().getMethod(call.getMethodName(), call.getArgTypes());
        method.setAccessible(true);
    } catch (final NoSuchMethodException e) {
        throw new IllegalStateException(e);
    }
    MessageContext.setSenderNodeForThread(messageOriginator);
    try {
        final Object methodRVal = method.invoke(implementor, call.getArgs());
        return new RemoteMethodCallResults(methodRVal);
    } catch (final InvocationTargetException e) {
        return new RemoteMethodCallResults(e.getTargetException());
    } catch (final IllegalAccessException | IllegalArgumentException e) {
        ClientLogger.logQuietly("error in call:" + call, e);
        return new RemoteMethodCallResults(e);
    } finally {
        MessageContext.setSenderNodeForThread(null);
    }
}
Also used : RemoteMethodCallResults(games.strategy.engine.message.RemoteMethodCallResults) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with RemoteMethodCallResults

use of games.strategy.engine.message.RemoteMethodCallResults in project triplea by triplea-game.

the class EndPointTest method testEndPoint.

@Test
public void testEndPoint() {
    final EndPoint endPoint = new EndPoint("", Comparator.class, false);
    endPoint.addImplementor((Comparator<Object>) (o1, o2) -> 2);
    final RemoteMethodCall call = new RemoteMethodCall("", "compare", new Object[] { "", "" }, new Class<?>[] { Object.class, Object.class }, Comparator.class);
    final List<RemoteMethodCallResults> results = endPoint.invokeLocal(call, endPoint.takeANumber(), null);
    assertEquals(1, results.size());
    assertEquals(2, (results.iterator().next()).getRVal());
}
Also used : Test(org.junit.jupiter.api.Test) RemoteMethodCall(games.strategy.engine.message.RemoteMethodCall) List(java.util.List) RemoteMethodCallResults(games.strategy.engine.message.RemoteMethodCallResults) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Comparator(java.util.Comparator) RemoteMethodCall(games.strategy.engine.message.RemoteMethodCall) RemoteMethodCallResults(games.strategy.engine.message.RemoteMethodCallResults) Test(org.junit.jupiter.api.Test)

Example 4 with RemoteMethodCallResults

use of games.strategy.engine.message.RemoteMethodCallResults in project triplea by triplea-game.

the class InvocationResults method readExternal.

@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
    results = new RemoteMethodCallResults();
    results.readExternal(in);
    methodCallId = new GUID();
    methodCallId.readExternal(in);
}
Also used : RemoteMethodCallResults(games.strategy.engine.message.RemoteMethodCallResults) GUID(games.strategy.net.GUID)

Example 5 with RemoteMethodCallResults

use of games.strategy.engine.message.RemoteMethodCallResults 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

RemoteMethodCallResults (games.strategy.engine.message.RemoteMethodCallResults)7 GUID (games.strategy.net.GUID)4 SpokeInvoke (games.strategy.engine.message.SpokeInvoke)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 HubInvoke (games.strategy.engine.message.HubInvoke)2 ConnectionLostException (games.strategy.engine.message.ConnectionLostException)1 HubInvocationResults (games.strategy.engine.message.HubInvocationResults)1 RemoteMethodCall (games.strategy.engine.message.RemoteMethodCall)1 RemoteNotFoundException (games.strategy.engine.message.RemoteNotFoundException)1 SpokeInvocationResults (games.strategy.engine.message.SpokeInvocationResults)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Test (org.junit.jupiter.api.Test)1