Package net.sf.agentopia.util

Examples of net.sf.agentopia.util.ClassedObjectTransmitter$ClassInfo


        // Initialise treasure heap.
        final List<IAgentopiaAgent> registeredAgentList = host.getRegisteredAgents();
        treasureHeap = new TreasureHeap(this, registeredAgentList);

        // Initialise agent transmitter.
        transmitter = new ClassedObjectTransmitter();
    }
View Full Code Here


     * @return The treasure heap memento.
     * @throws IOException If saving failed.
     */
    public String backupToMemento() throws IOException {
        synchronized (treasureMap) {
            final byte[] dataBytes = new ClassedObjectTransmitter().turnClassedObjectToBytes(treasureMap, null);
            final String dataString = new BASE64Encoder().encode(dataBytes);
            final String memento = dataString.replaceAll("\\n", "\t");
            final int treasureCount = this.treasureMap.size();
            if (AgentopiaConstants.TREASURE_DEBUG) {
                Logger.getLogger().info("Saved " + treasureCount + " treasures into memento.");
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public int restoreFromMemento(String memento) throws IOException {
        final String dataString = memento.replaceAll("\\t", "\n");
        final byte[] dataBytes = new BASE64Decoder().decodeBuffer(dataString);
        final Object dataObject = new ClassedObjectTransmitter().turnClassedBytesToObject(dataBytes, null);
        if (dataObject instanceof Map) {
            this.treasureMap = (Map<String, TreasureHeap.Treasure>) dataObject;
            final int treasureCount = this.treasureMap.size();
            if (AgentopiaConstants.TREASURE_DEBUG) {
                Logger.getLogger().info("Restored " + treasureCount + " treasures from memento.");
View Full Code Here

     * @param agent The agent to be transferred.
     * @exception IOException If transfer failed for whatever reason.
     */
    public void transferMe(IAgentopiaAgent agent) throws IOException {
        writeInt(AgentopiaConstants.MESSAGE_AGENT_COMING);
        final ClassedObjectTransmitter transmitter = new ClassedObjectTransmitter();
        transmitter.transferAgentToStream(agent, this.dataOut);
        lastAgentTransferred = agent;
        // Wait up to 24 hour for ack flag.
        final long ONE_DAY = 24L * 60L * 60L * 1000L;
        final int ackFlag = readInt((int) ONE_DAY);
        if (AgentopiaConstants.MESSAGE_TRANSFER_COMPLETED != ackFlag) {
View Full Code Here

            dataOut.flush();
            intFlag = dataIn.readInt();
            if (AgentopiaConstants.MESSAGE_AGENT_COMING != intFlag) {
                throw new IOException("MESSAGE_AGENT_COMING flag expected!");
            }
            final ClassedObjectTransmitter transmitter = marketPlace.getClassedObjectTransmitter();
            agent = (IAgentopiaAgent) transmitter.transferAgentFromStream(dataIn);
            dataOut.writeInt(AgentopiaConstants.MESSAGE_TRANSFER_COMPLETED);
            dataOut.flush();
            try {
                final int ackFlag = dataIn.readInt();
                if (AgentopiaConstants.MESSAGE_TRANSFER_COMPLETED != ackFlag) {
View Full Code Here

                    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);
                    }
View Full Code Here

TOP

Related Classes of net.sf.agentopia.util.ClassedObjectTransmitter$ClassInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.