aplib-master/src/main/java/eu/iv4xr/framework/mainConcepts/SyntheticEventsProducer.java
package eu.iv4xr.framework.mainConcepts;

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

import nl.uu.cs.aplib.multiAgentSupport.ComNode;
import nl.uu.cs.aplib.multiAgentSupport.Message;

/**
 * Agents (instances of {@link nl.uu.cs.aplib.mainConcepts.BasicAgent} or its
 * subclasses) are mainly state-based. But sometimes when testing using
 * test-agents we may want to inspect the system-under-test (SUT) in terms of
 * events that happen there. If the SUT itself does produce events, recent
 * events can be either embedded in the observation sent to the test-agent, or
 * sent to the agent as messages through the use of
 * {@link nl.uu.cs.aplib.multiAgentSupport.ComNode}.
 * 
 * <p>
 * When the SUT does not in itself produces events, we can use this class to
 * implement a wrapper that looks into the agent state and produce synthetic
 * events.
 * 
 * <p>This class is abstract, so you need to provide a concrete implementation
 * of it. Then, to use it, you can attach it to a test-agent using the method
 * {@link TestAgent#attachSyntheticEventsProducer(SyntheticEventsProducer)}.
 *
 * @author Wish
 *
 */
public abstract class SyntheticEventsProducer {
	
	/**
	 * The test-agent to which this producer is attached to.
	 */
	public TestAgent agent ;
	
	
	/**
	 * Produced synthetic events will be placed here. Synthetic events are
	 * produced by the method {@link #generateCurrentEvents()}.
	 */
	public List<Message> currentEvents = new LinkedList<>() ;
	
	/**
	 * If not null, produced events will also be sent to this communication node.
	 * Other agents registering to this node will then automatically receive the events.
	 */
	public ComNode communicationNode ;
	
	/**
	 * Return the list of 'current' events. These are the events that are synthetically
	 * generated by the last call to {@link #getCurrentEvents()}.
	 */
	public List<Message> getCurrentEvents() {
		return currentEvents ;
	}
	
	/**
	 * Implement this method to generate synthetic events based on the the current
	 * state of the agent. Generated events are to be put in
	 * {@link SyntheticEventsProducer#currentEvents}; make sure to clear this list
	 * first.
	 */
	abstract public void generateCurrentEvents() ;

}
