use of games.strategy.engine.GameOverException in project triplea by triplea-game.
the class DelegateExecutionManager method createOutboundImplementation.
/**
* Used to create an object the exits delegate execution.
*
* <p>
* Objects on this method will decrement the thread lock count when called, and will increment it again when execution
* is finished.
* </p>
*/
public Object createOutboundImplementation(final Object implementor, final Class<?>[] interfaces) {
assertGameNotOver();
final InvocationHandler ih = (proxy, method, args) -> {
assertGameNotOver();
final boolean threadLocks = currentThreadHasReadLock();
if (threadLocks) {
leaveDelegateExecution();
}
try {
return method.invoke(implementor, args);
} catch (final MessengerException me) {
throw new GameOverException("Game Over!");
} catch (final InvocationTargetException ite) {
assertGameNotOver();
throw ite;
} finally {
if (threadLocks) {
enterDelegateExecution();
}
}
};
return Proxy.newProxyInstance(implementor.getClass().getClassLoader(), interfaces, ih);
}
use of games.strategy.engine.GameOverException in project triplea by triplea-game.
the class DefaultPlayerBridge method getRemoteDelegate.
@Override
public IRemote getRemoteDelegate() {
if (game.isGameOver()) {
throw new GameOverException("Game Over");
}
try {
game.getData().acquireReadLock();
try {
final IDelegate delegate = game.getData().getDelegateList().getDelegate(currentDelegate);
if (delegate == null) {
final String errorMessage = "IDelegate in DefaultPlayerBridge.getRemote() cannot be null. CurrentStep: " + stepName + ", and CurrentDelegate: " + currentDelegate;
// for some reason, client isn't getting or seeing the errors, so make sure we print it to err
// too
System.err.println(errorMessage);
// Veqryn: hope that this suffices...?
throw new IllegalStateException(errorMessage);
}
final RemoteName remoteName;
try {
remoteName = ServerGame.getRemoteName(delegate);
} catch (final Exception e) {
final String errorMessage = "IDelegate IRemote interface class returned null or was not correct interface. CurrentStep: " + stepName + ", and CurrentDelegate: " + currentDelegate;
// for some reason, client isn't getting or seeing the errors, so make sure we print it to err
// too
System.err.println(errorMessage);
ClientLogger.logQuietly(errorMessage, e);
throw new IllegalStateException(errorMessage, e);
}
return getRemoteThatChecksForGameOver(game.getRemoteMessenger().getRemote(remoteName));
} finally {
game.getData().releaseReadLock();
}
} catch (final MessengerException me) {
throw new GameOverException("Game Over!");
}
}
use of games.strategy.engine.GameOverException in project triplea by triplea-game.
the class DefaultPlayerBridge method getRemotePersistentDelegate.
@Override
public IRemote getRemotePersistentDelegate(final String name) {
if (game.isGameOver()) {
throw new GameOverException("Game Over");
}
try {
game.getData().acquireReadLock();
try {
final IDelegate delegate = game.getData().getDelegateList().getDelegate(name);
if (delegate == null) {
final String errorMessage = "IDelegate in DefaultPlayerBridge.getRemote() cannot be null. Looking for delegate named: " + name;
// for some reason, client isn't getting or seeing the errors, so make sure we print it to err
System.err.println(errorMessage);
// too
throw new IllegalStateException(errorMessage);
}
if (!(delegate instanceof IPersistentDelegate)) {
return null;
}
return getRemoteThatChecksForGameOver(game.getRemoteMessenger().getRemote(ServerGame.getRemoteName(delegate)));
} finally {
game.getData().releaseReadLock();
}
} catch (final MessengerException me) {
throw new GameOverException("Game Over!");
}
}
Aggregations