// Agent to send? Yes.
else {
if (AgentopiaConstants.SUSTAINER_DEBUG) {
Logger.getLogger().info("Sustainer sending agent to \"" + getTargetId() + "\".");
}
final IAgentopiaAgent agent = transferQueue.get(0);
final ClassedObjectTransmitter transmitter = marketPlace.getClassedObjectTransmitter();
try {
transferQueue.remove(0);
writeInt(AgentopiaConstants.MESSAGE_AGENT_COMING);
transmitter.transferAgentToStream(agent, dataOut);
Logger.getLogger().info("Agent \"" + agent + "\" left the system (" + marketPlace.getHomeId() + ") per Sustainer.");
agent.shutDown();
}
catch (IOException exc) {
// Agent sending failed... But no problem here.
Logger.getLogger().info("Agent \"" + agent + "\" failed to leave to \"" + targetId + "\"... and died.");
}
}
break;
// Incoming agent? Yes.
case AgentopiaConstants.MESSAGE_AGENT_COMING :
if (AgentopiaConstants.SUSTAINER_DEBUG) {
Logger.getLogger().info("Sustainer receiving agent from \"" + getTargetId() + "\".");
}
final ClassedObjectTransmitter transmitter = marketPlace.getClassedObjectTransmitter();
try {
final IAgentopiaAgent agent = (IAgentopiaAgent) transmitter.transferAgentFromStream(dataIn);
Logger.getLogger().info("Agent \"" + agent + "\" entered the system (" + marketPlace.getHomeId() + ") per Sustainer.");
// Indicate to market place that agent is here.
// Run method will be called in next market tick.
marketPlace.agentArrived(agent);
}