Search in sources :

Example 11 with RemoteName

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

the class RemoteMessengerTest method testExceptionThrownWhenUnregisteredRemote.

@Test
public void testExceptionThrownWhenUnregisteredRemote() {
    final TestRemote testRemote = new TestRemote();
    final RemoteName test = new RemoteName(ITestRemote.class, "test");
    remoteMessenger.registerRemote(testRemote, test);
    final ITestRemote remote = (ITestRemote) remoteMessenger.getRemote(test);
    remoteMessenger.unregisterRemote("test");
    try {
        remote.increment(1);
        fail("No exception thrown");
    } catch (final RemoteNotFoundException rme) {
    // this is what we expect
    }
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) RemoteNotFoundException(games.strategy.engine.message.RemoteNotFoundException) Test(org.junit.jupiter.api.Test)

Example 12 with RemoteName

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

the class RemoteMessengerTest method testMethodReturnsOnWait.

@Test
public void testMethodReturnsOnWait() throws Exception {
    // when the client shutdown, remotes created
    // on the client should not be visible on server
    final RemoteName test = new RemoteName(IFoo.class, "test");
    ServerMessenger server = null;
    ClientMessenger client = null;
    try {
        server = new ServerMessenger("server", 0);
        server.setAcceptNewConnections(true);
        final int serverPort = server.getLocalNode().getSocketAddress().getPort();
        final String mac = MacFinder.getHashedMacAddress();
        client = new ClientMessenger("localhost", serverPort, "client", mac);
        final UnifiedMessenger serverUnifiedMessenger = new UnifiedMessenger(server);
        final RemoteMessenger serverRemoteMessenger = new RemoteMessenger(serverUnifiedMessenger);
        final RemoteMessenger clientRemoteMessenger = new RemoteMessenger(new UnifiedMessenger(client));
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicBoolean started = new AtomicBoolean(false);
        final IFoo foo = new IFoo() {

            @Override
            public void foo() {
                started.set(true);
                Interruptibles.await(latch);
            }
        };
        clientRemoteMessenger.registerRemote(foo, test);
        serverUnifiedMessenger.getHub().waitForNodesToImplement(test.getName());
        assertTrue(serverUnifiedMessenger.getHub().hasImplementors(test.getName()));
        final AtomicReference<ConnectionLostException> rme = new AtomicReference<>(null);
        final Thread t = new Thread(() -> {
            try {
                final IFoo remoteFoo = (IFoo) serverRemoteMessenger.getRemote(test);
                remoteFoo.foo();
            } catch (final ConnectionLostException e) {
                rme.set(e);
            }
        });
        t.start();
        // wait for the thread to start
        while (started.get() == false) {
            Interruptibles.sleep(1);
        }
        Interruptibles.sleep(20);
        // TODO: we are getting a RemoteNotFoundException because the client is disconnecting before the invoke goes out
        // completely
        // Perhaps this situation should be changed to a ConnectionLostException or something else?
        client.shutDown();
        // when the client shutdowns, this should wake up.
        // and an error should be thrown
        // give the thread a chance to execute
        t.join(200);
        latch.countDown();
        assertNotNull(rme.get());
    } finally {
        shutdownServerAndClient(server, client);
    }
}
Also used : RemoteMessenger(games.strategy.engine.message.RemoteMessenger) ConnectionLostException(games.strategy.engine.message.ConnectionLostException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RemoteName(games.strategy.engine.message.RemoteName) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) ClientMessenger(games.strategy.net.ClientMessenger) Test(org.junit.jupiter.api.Test)

Example 13 with RemoteName

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

the class ModeratorController method getHeadlessHostBotSalt.

@Override
public String getHeadlessHostBotSalt(final INode node) {
    assertUserIsAdmin();
    if (serverMessenger.getServerNode().equals(node)) {
        throw new IllegalStateException("Cannot do this for server node");
    }
    final INode modNode = MessageContext.getSender();
    final String mac = getNodeMacAddress(node);
    logger.info(String.format("Getting salt for Headless HostBot. Host: %s IP: %s Mac: %s Mod Username: %s Mod IP: %s Mod Mac: %s", node.getName(), node.getAddress().getHostAddress(), mac, modNode.getName(), modNode.getAddress().getHostAddress(), getNodeMacAddress(modNode)));
    final RemoteName remoteName = RemoteHostUtils.getRemoteHostUtilsName(node);
    final IRemoteHostUtils remoteHostUtils = (IRemoteHostUtils) allMessengers.getRemoteMessenger().getRemote(remoteName);
    return remoteHostUtils.getSalt();
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) INode(games.strategy.net.INode)

Example 14 with RemoteName

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

the class ModeratorController method stopGameHeadlessHostBot.

@Override
public String stopGameHeadlessHostBot(final INode node, final String hashedPassword, final String salt) {
    assertUserIsAdmin();
    if (serverMessenger.getServerNode().equals(node)) {
        throw new IllegalStateException("Cannot do this for server node");
    }
    final INode modNode = MessageContext.getSender();
    final String mac = getNodeMacAddress(node);
    final RemoteName remoteName = RemoteHostUtils.getRemoteHostUtilsName(node);
    final IRemoteHostUtils remoteHostUtils = (IRemoteHostUtils) allMessengers.getRemoteMessenger().getRemote(remoteName);
    final String response = remoteHostUtils.stopGameHeadlessHostBot(hashedPassword, salt);
    logger.info(String.format((response == null ? "Successful" : "Failed (" + response + ")") + " Remote Stopgame of Headless HostBot. Host: %s IP: %s Mac: %s Mod Username: %s Mod IP: %s Mod Mac: %s", node.getName(), node.getAddress().getHostAddress(), mac, modNode.getName(), modNode.getAddress().getHostAddress(), getNodeMacAddress(modNode)));
    return response;
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) INode(games.strategy.net.INode)

Example 15 with RemoteName

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

the class ModeratorController method bootPlayerHeadlessHostBot.

@Override
public String bootPlayerHeadlessHostBot(final INode node, final String playerNameToBeBooted, final String hashedPassword, final String salt) {
    assertUserIsAdmin();
    if (serverMessenger.getServerNode().equals(node)) {
        throw new IllegalStateException("Cannot do this for server node");
    }
    final INode modNode = MessageContext.getSender();
    final String mac = getNodeMacAddress(node);
    final RemoteName remoteName = RemoteHostUtils.getRemoteHostUtilsName(node);
    final IRemoteHostUtils remoteHostUtils = (IRemoteHostUtils) allMessengers.getRemoteMessenger().getRemote(remoteName);
    final String response = remoteHostUtils.bootPlayerHeadlessHostBot(playerNameToBeBooted, hashedPassword, salt);
    logger.info(String.format((response == null ? "Successful" : "Failed (" + response + ")") + " Remote Boot of " + playerNameToBeBooted + " In Headless HostBot. Host: %s IP: %s Mac: %s Mod Username: %s Mod IP: %s Mod Mac: %s", node.getName(), node.getAddress().getHostAddress(), mac, modNode.getName(), modNode.getAddress().getHostAddress(), getNodeMacAddress(modNode)));
    return response;
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) INode(games.strategy.net.INode)

Aggregations

RemoteName (games.strategy.engine.message.RemoteName)28 Test (org.junit.jupiter.api.Test)14 INode (games.strategy.net.INode)7 ClientMessenger (games.strategy.net.ClientMessenger)5 IChannelSubscribor (games.strategy.engine.message.IChannelSubscribor)4 RemoteMessenger (games.strategy.engine.message.RemoteMessenger)4 RemoteNotFoundException (games.strategy.engine.message.RemoteNotFoundException)4 IServerMessenger (games.strategy.net.IServerMessenger)4 ServerMessenger (games.strategy.net.ServerMessenger)4 ConnectionLostException (games.strategy.engine.message.ConnectionLostException)2 RemoteMethodCall (games.strategy.engine.message.RemoteMethodCall)2 GameOverException (games.strategy.engine.GameOverException)1 PlayerID (games.strategy.engine.data.PlayerID)1 PlayerList (games.strategy.engine.data.PlayerList)1 IDelegate (games.strategy.engine.delegate.IDelegate)1 DefaultPlayerBridge (games.strategy.engine.gamePlayer.DefaultPlayerBridge)1 IGamePlayer (games.strategy.engine.gamePlayer.IGamePlayer)1 IPlayerBridge (games.strategy.engine.gamePlayer.IPlayerBridge)1 ChannelMessenger (games.strategy.engine.message.ChannelMessenger)1 HubInvoke (games.strategy.engine.message.HubInvoke)1