use of games.strategy.net.GUID in project triplea by triplea-game.
the class BattleRecords method addRecord.
public void addRecord(final BattleRecords other) {
for (final PlayerID p : other.m_records.keySet()) {
final HashMap<GUID, BattleRecord> currentRecord = m_records.get(p);
if (currentRecord != null) {
// this only comes up if we use edit mode to create an attack for a player who's already had their turn and
// therefore already has
// their record.
final HashMap<GUID, BattleRecord> additionalRecords = other.m_records.get(p);
for (final Entry<GUID, BattleRecord> entry : additionalRecords.entrySet()) {
final GUID guid = entry.getKey();
final BattleRecord br = entry.getValue();
if (currentRecord.containsKey(guid)) {
throw new IllegalStateException("Should not be adding battle record for player " + p.getName() + " when they are already on the record. " + "Trying to add: " + br.toString());
}
currentRecord.put(guid, br);
}
m_records.put(p, currentRecord);
} else {
m_records.put(p, other.m_records.get(p));
}
}
}
use of games.strategy.net.GUID in project triplea by triplea-game.
the class BattleRecords method removeRecord.
public void removeRecord(final BattleRecords other) {
for (final PlayerID p : other.m_records.keySet()) {
final HashMap<GUID, BattleRecord> currentRecord = m_records.get(p);
if (currentRecord == null) {
throw new IllegalStateException("Trying to remove a player records but records do not exist");
}
final HashMap<GUID, BattleRecord> toRemoveRecords = other.m_records.get(p);
for (final Entry<GUID, BattleRecord> entry : toRemoveRecords.entrySet()) {
final GUID guid = entry.getKey();
if (!currentRecord.containsKey(guid)) {
throw new IllegalStateException("Trying to remove a battle record but record does not exist");
}
currentRecord.remove(guid);
}
}
}
use of games.strategy.net.GUID in project triplea by triplea-game.
the class BattlePanel method ensureBattleIsDisplayed.
private boolean ensureBattleIsDisplayed(final GUID battleId) {
if (SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("Wrong threads");
}
GUID displayed = currentBattleDisplayed;
int count = 0;
while (!battleId.equals(displayed)) {
count++;
Interruptibles.sleep(count);
// something is wrong, we shouldnt have to wait this long
if (count > 200) {
ErrorConsole.getConsole().dumpStacks();
new IllegalStateException("battle not displayed, looking for:" + battleId + " showing:" + currentBattleDisplayed).printStackTrace();
return false;
}
displayed = currentBattleDisplayed;
}
return true;
}
use of games.strategy.net.GUID in project triplea by triplea-game.
the class InvocationResults method readExternal.
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
results = new RemoteMethodCallResults();
results.readExternal(in);
methodCallId = new GUID();
methodCallId.readExternal(in);
}
use of games.strategy.net.GUID in project triplea by triplea-game.
the class UnifiedMessenger method messageReceived.
public void messageReceived(final Serializable msg, final INode from) {
if (msg instanceof SpokeInvoke) {
// if this isn't the server, something is wrong
// maybe an attempt to spoof a message
assertIsServer(from);
final SpokeInvoke invoke = (SpokeInvoke) msg;
final EndPoint local;
synchronized (endPointMutex) {
local = localEndPoints.get(invoke.call.getRemoteName());
}
// regardless, the other side is expecting our reply
if (local == null) {
if (invoke.needReturnValues) {
send(new HubInvocationResults(new RemoteMethodCallResults(new RemoteNotFoundException("No implementors for " + invoke.call + ", inode: " + from + ", msg: " + msg)), invoke.methodCallId), from);
}
return;
}
// very important
// we are guaranteed that here messages will be
// read in the same order that they are sent from the client
// however, once we delegate to the thread pool, there is no
// guarantee that the thread pool task will run before
// we get the next message notification
// get the number for the invocation here
final long methodRunNumber = local.takeANumber();
// we don't want to block the message thread, only one thread is
// reading messages per connection, so run with out thread pool
final EndPoint localFinal = local;
threadPool.execute(() -> {
final List<RemoteMethodCallResults> results = localFinal.invokeLocal(invoke.call, methodRunNumber, invoke.getInvoker());
if (invoke.needReturnValues) {
final RemoteMethodCallResults result;
if (results.size() == 1) {
result = results.get(0);
} else {
result = new RemoteMethodCallResults(new IllegalStateException("Invalid result count" + results.size()) + " for end point:" + localFinal);
}
send(new HubInvocationResults(result, invoke.methodCallId), from);
}
});
} else if (msg instanceof SpokeInvocationResults) {
// a remote machine is returning results
// if this isn't the server, something is wrong
// maybe an attempt to spoof a message
assertIsServer(from);
final SpokeInvocationResults spokeInvocationResults = (SpokeInvocationResults) msg;
final GUID methodId = spokeInvocationResults.methodCallId;
// all
synchronized (pendingLock) {
results.put(methodId, spokeInvocationResults.results);
final CountDownLatch latch = pendingInvocations.remove(methodId);
Preconditions.checkNotNull(latch, String.format("method id: %s, was not present in pending invocations: %s, unified messenger addr: %s", methodId, pendingInvocations, super.toString()));
latch.countDown();
}
}
}
Aggregations