use of games.strategy.net.INode in project triplea by triplea-game.
the class ModeratorController method boot.
@Override
public void boot(final INode node) {
assertUserIsAdmin();
// You can't boot the server node
if (serverMessenger.getServerNode().equals(node)) {
throw new IllegalStateException("Cannot boot server node");
}
final INode modNode = MessageContext.getSender();
final String mac = getNodeMacAddress(node);
serverMessenger.removeConnection(node);
logger.info(String.format("User was booted from the lobby. Username: %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)));
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class RemoteHostUtils method getConnections.
@Override
public String getConnections() {
if (!MessageContext.getSender().equals(serverNode)) {
return "Not accepted!";
}
if (serverMessenger != null) {
final StringBuilder sb = new StringBuilder("Connected: " + serverMessenger.isConnected() + "\n" + "Nodes: \n");
final Set<INode> nodes = serverMessenger.getNodes();
if (nodes == null) {
sb.append(" null\n");
} else {
for (final INode node : nodes) {
sb.append(" ").append(node).append("\n");
}
}
return sb.toString();
}
return "Not a server.";
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class UnifiedMessengerHub method sendResultsToCaller.
private void sendResultsToCaller(final GUID methodId, final InvocationInProgress invocationInProgress) {
final RemoteMethodCallResults result = invocationInProgress.getResults();
final INode caller = invocationInProgress.getCaller();
final SpokeInvocationResults spokeResults = new SpokeInvocationResults(result, methodId);
send(spokeResults, caller);
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class UnifiedMessengerHub method messageReceived.
@Override
public void messageReceived(final Serializable msg, final INode from) {
if (msg instanceof HasEndPointImplementor) {
synchronized (endPointMutex) {
final HasEndPointImplementor hasEndPoint = (HasEndPointImplementor) msg;
final Collection<INode> nodes = endPoints.computeIfAbsent(hasEndPoint.endPointName, k -> new ArrayList<>());
if (nodes.contains(from)) {
throw new IllegalStateException("Already contained, new" + from + " existing, " + nodes + " name " + hasEndPoint.endPointName);
}
nodes.add(from);
}
} else if (msg instanceof NoLongerHasEndPointImplementor) {
synchronized (endPointMutex) {
final NoLongerHasEndPointImplementor hasEndPoint = (NoLongerHasEndPointImplementor) msg;
final Collection<INode> nodes = endPoints.get(hasEndPoint.endPointName);
if (nodes != null) {
if (!nodes.remove(from)) {
throw new IllegalStateException("Not removed!");
}
if (nodes.isEmpty()) {
endPoints.remove(hasEndPoint.endPointName);
}
}
}
} else if (msg instanceof HubInvoke) {
final HubInvoke invoke = (HubInvoke) msg;
final Collection<INode> endPointCols = new ArrayList<>();
synchronized (endPointMutex) {
if (endPoints.containsKey(invoke.call.getRemoteName())) {
endPointCols.addAll(endPoints.get(invoke.call.getRemoteName()));
}
}
// the node will already have routed messages to local invokers
endPointCols.remove(from);
if (endPointCols.isEmpty()) {
if (invoke.needReturnValues) {
final RemoteMethodCallResults results = new RemoteMethodCallResults(new RemoteNotFoundException("Not found:" + invoke.call.getRemoteName()));
send(new SpokeInvocationResults(results, invoke.methodCallId), from);
}
// no end points, this is ok, we
// we are a channel with no implementors
} else {
invoke(invoke, endPointCols, from);
}
} else if (msg instanceof HubInvocationResults) {
final HubInvocationResults results = (HubInvocationResults) msg;
results(results, from);
}
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class UnifiedMessengerHub method invoke.
private void invoke(final HubInvoke hubInvoke, final Collection<INode> remote, final INode from) {
if (hubInvoke.needReturnValues) {
if (remote.size() != 1) {
throw new IllegalStateException("Too many nodes:" + remote + " for remote name " + hubInvoke.call);
}
final InvocationInProgress invocationInProgress = new InvocationInProgress(remote.iterator().next(), hubInvoke, from);
invocations.put(hubInvoke.methodCallId, invocationInProgress);
}
// invoke remotely
final SpokeInvoke invoke = new SpokeInvoke(hubInvoke.methodCallId, hubInvoke.needReturnValues, hubInvoke.call, from);
for (final INode node : remote) {
send(invoke, node);
}
}
Aggregations