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;
}
}
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);
}
}
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());
}
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);
}
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());
}
}
}
}
Aggregations