All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jrtps.udds.Entity Maven / Gradle / Ivy

package net.sf.jrtps.udds;

import java.util.LinkedList;
import java.util.List;

import net.sf.jrtps.builtin.DiscoveredData;
import net.sf.jrtps.types.Guid;

/**
 * Entity is a base class for DataReader and DataWriter.
 * 
 * @author mcr70
 * @param  Data type, that this Entity works with
 * @param  Type of the remote entity data, that is tracked by communication listeners of this Entity.
 */
public class Entity {
    private final String topicName;
    private final Participant participant;
    private final Class type;
    private final String typeName;
    private final Guid guid;
    /**
     * A List of communication listeners
     */
    protected final List> communicationListeners = new LinkedList<>();
    
    /**
     * Constructor
     * 
     * @param p
     * @param type Type of the entity
     * @param typeName if type null, typeName is set to be fully qualified class name of type 
     * @param topicName name of the topic this entity is bound to.
     * @param guid 
     */
    protected Entity(Participant p, Class type, String typeName, String topicName, Guid guid) {
        this.participant = p;
        this.type = type;
        if (typeName != null) {
        	this.typeName = typeName;
        }
        else {
        	this.typeName = type.getName();
        }
        this.topicName = topicName;
        this.guid = guid;
    }

    /**
     * Adds a new CommunicationListener to this Entity.
     * @param cl
     */
    public void addCommunicationListener(CommunicationListener cl) {
        communicationListeners.add(cl);
    }
    
    /**
     * Removes a CommunicationListener from this Entity.
     * @param cl
     */
    public void removeCommunicationListener(CommunicationListener cl) {
        communicationListeners.remove(cl);
    }
    

    
    /**
     * Get the name of the topic of this entity.
     * @return topic name
     */
    public String getTopicName() {
        return topicName;
    }

    /**
     * Get the Participant that has created this Entity.
     * @return Participant
     */
    public Participant getParticipant() {
        return participant;
    }

    /**
     * Gets the type associated with this entity.
     * @return Class
     */
    public Class getType() {
        return type;
    }
    
    /**
     * Gets the typeName of this entity.
     * @return typeName
     */
    public String getTypeName() {
    	return typeName;
    }
    
    /**
     * Gets the Guid of this Entity
     * @return guid
     */
    public Guid getGuid() {
        return guid;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy