Search in sources :

Example 1 with IPersistentDelegate

use of games.strategy.engine.delegate.IPersistentDelegate in project triplea by triplea-game.

the class ServerGame method startPersistentDelegates.

private void startPersistentDelegates() {
    for (final IDelegate delegate : gameData.getDelegateList()) {
        if (!(delegate instanceof IPersistentDelegate)) {
            continue;
        }
        final DefaultDelegateBridge bridge = new DefaultDelegateBridge(gameData, this, new DelegateHistoryWriter(channelMessenger), randomStats, delegateExecutionManager);
        if (delegateRandomSource == null) {
            delegateRandomSource = (IRandomSource) delegateExecutionManager.createOutboundImplementation(randomSource, new Class<?>[] { IRandomSource.class });
        }
        bridge.setRandomSource(delegateRandomSource);
        delegateExecutionManager.enterDelegateExecution();
        try {
            delegate.setDelegateBridgeAndPlayer(bridge);
            delegate.start();
        } finally {
            delegateExecutionManager.leaveDelegateExecution();
        }
    }
}
Also used : IPersistentDelegate(games.strategy.engine.delegate.IPersistentDelegate) DelegateHistoryWriter(games.strategy.engine.history.DelegateHistoryWriter) DefaultDelegateBridge(games.strategy.engine.delegate.DefaultDelegateBridge) IDelegate(games.strategy.engine.delegate.IDelegate)

Example 2 with IPersistentDelegate

use of games.strategy.engine.delegate.IPersistentDelegate 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!");
    }
}
Also used : IPersistentDelegate(games.strategy.engine.delegate.IPersistentDelegate) MessengerException(games.strategy.engine.message.MessengerException) GameOverException(games.strategy.engine.GameOverException) IDelegate(games.strategy.engine.delegate.IDelegate)

Aggregations

IDelegate (games.strategy.engine.delegate.IDelegate)2 IPersistentDelegate (games.strategy.engine.delegate.IPersistentDelegate)2 GameOverException (games.strategy.engine.GameOverException)1 DefaultDelegateBridge (games.strategy.engine.delegate.DefaultDelegateBridge)1 DelegateHistoryWriter (games.strategy.engine.history.DelegateHistoryWriter)1 MessengerException (games.strategy.engine.message.MessengerException)1