The Robot Application Programming Interface Delegate Project
RAPID Logo

RapidACKExampleModel.java

/*
 * Copyright (c) 2009 United States Government as represented by the
 * Administrator of the National Aeronautics and Space Administration.
 * All Rights Reserved.
 */

package gov.nasa.rapid.examples.models;

import gov.nasa.rapid.dds.Agent;
import gov.nasa.rapid.event.IRapidEventListener;
import gov.nasa.rapid.examples.DDSExampleSettings;
import gov.nasa.rapid.message.IRapidMessage;
import gov.nasa.rapid.message.MessageType;
import gov.nasa.rapid.message.RapidAckMessage;
import gov.nasa.rapid.utils.RapidMessageUtils;

public class RapidACKExampleModel extends RapidExampleModel {

    public static final String ID = "gov.nasa.rapid.examples.models.RapidACKExampleModel";

    public RapidACKExampleModel() {
        this(DDSExampleSettings.CLIENT_AGENT);
    }

    public RapidACKExampleModel(Agent agent) {
        super(agent);

        setModelName("RapidACKExampleModel");

        registerForMessage(
            RapidMessageUtils.getAvailablePartitionsForSubscribing(),
            MessageType.ACK_TYPE,
            new IRapidEventListener() {

                    public void rapidEventReceived(Agent agent, MessageType type, IRapidMessage msg) {
                        RapidAckMessage ack = null;

                        if (msg instanceof RapidAckMessage)
                            ack = (RapidAckMessage) msg;

                        if (ack == null)
                            return;

                        System.err.println("\n\n\n---- RapidACKExampleModel: "
                                + msg + "\n\n\n\n");
                        setModelName("RapidACKExampleModel");
                        setMessage(ack.toString());
                        setTimeStamp(ack.getHeader().timeStamp);

                        updateModelChangedListeners();
                    }
        });
    }
}

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines