Package net.sf.tweety.agents
Class AbstractProtocol
- java.lang.Object
-
- net.sf.tweety.agents.AbstractProtocol
-
- All Implemented Interfaces:
Protocol
- Direct Known Subclasses:
RigidProtocol
public abstract class AbstractProtocol extends java.lang.Object implements Protocol
A protocol gives instructions in which order agents have to be asked for actions in a multi-agent system. This class encapsulates common functionalities of protocols.- Author:
- Matthias Thimm
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<ProtocolListener>listenerThe listener of this protocol.private MultiAgentSystem<? extends Agent>multiAgentSystemThe multi-agent system this protocol operates on.
-
Constructor Summary
Constructors Constructor Description AbstractProtocol(MultiAgentSystem<? extends Agent> multiAgentSystem)Creates a new protocol for the given multi-agent system.
-
Method Summary
Modifier and Type Method Description voidaddProtocolListener(ProtocolListener listener)Adds the given listener to this protocol.protected abstract java.util.Set<ActionEvent>doStep()Executes one step of the protocol.protected MultiAgentSystem<? extends Agent>getMultiAgentSystem()Returns the multi-agent system this protocol operates on.protected abstract booleanhasTerminated()This method determines if this protocol has terminated, i.e.protected voidnotifyActionPerformed(ActionEvent actionEvent)Notifies every listener about the given event.protected voidnotifyTerminated()Notifies every listener that this protocol has terminated.booleanremoveProtocolListener(ProtocolListener listener)Removes the given protocol listener from this protocol.protected voidstep()Executes one step of the protocol.
-
-
-
Field Detail
-
multiAgentSystem
private MultiAgentSystem<? extends Agent> multiAgentSystem
The multi-agent system this protocol operates on.
-
listener
private java.util.Set<ProtocolListener> listener
The listener of this protocol.
-
-
Constructor Detail
-
AbstractProtocol
public AbstractProtocol(MultiAgentSystem<? extends Agent> multiAgentSystem)
Creates a new protocol for the given multi-agent system.- Parameters:
multiAgentSystem- a multi-agent system.
-
-
Method Detail
-
getMultiAgentSystem
protected MultiAgentSystem<? extends Agent> getMultiAgentSystem()
Returns the multi-agent system this protocol operates on.- Returns:
- the multi-agent system this protocol operates on.
-
hasTerminated
protected abstract boolean hasTerminated()
This method determines if this protocol has terminated, i.e. whether no further actions are possible.- Returns:
- "true" if this protocol system has terminated.
-
step
protected final void step() throws ProtocolTerminatedExceptionExecutes one step of the protocol. This method also performs some administrative tasks.- Throws:
ProtocolTerminatedException- if the protocol has already terminated.
-
doStep
protected abstract java.util.Set<ActionEvent> doStep() throws ProtocolTerminatedException
Executes one step of the protocol.- Returns:
- the set of events that occurred.
- Throws:
ProtocolTerminatedException- if the protocol already terminated
-
addProtocolListener
public void addProtocolListener(ProtocolListener listener)
Description copied from interface:ProtocolAdds the given listener to this protocol.- Specified by:
addProtocolListenerin interfaceProtocol- Parameters:
listener- a protocol listener.
-
removeProtocolListener
public boolean removeProtocolListener(ProtocolListener listener)
Description copied from interface:ProtocolRemoves the given protocol listener from this protocol.- Specified by:
removeProtocolListenerin interfaceProtocol- Parameters:
listener- a protocol listener.- Returns:
- "true" if the listener has been removed.
-
notifyTerminated
protected void notifyTerminated()
Notifies every listener that this protocol has terminated.
-
notifyActionPerformed
protected void notifyActionPerformed(ActionEvent actionEvent)
Notifies every listener about the given event.- Parameters:
actionEvent- an action event.
-
-