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