bdi4jade

Hidden AbstractBDIAgent

9/3/2014 7:21:29 PM

Details

diff --git a/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java b/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java
index 84c8305..9ab9085 100644
--- a/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java
+++ b/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java
@@ -77,8 +77,8 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 
 		private static final long serialVersionUID = -6991759791322598475L;
 
-		private BDIInterpreter(AbstractBDIAgent bdiAgent) {
-			super(bdiAgent);
+		private BDIInterpreter(BDIAgent bdiAgent) {
+			super((Agent) bdiAgent);
 		}
 
 		/**
@@ -469,17 +469,16 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 	 * @see BDIAgent#getAllCapabilities()
 	 */
 	@Override
-	public Collection<Capability> getAllCapabilities() {
+	public final Collection<Capability> getAllCapabilities() {
 		synchronized (aggregatedCapabilities) {
 			return capabilities;
 		}
 	}
 
 	/**
-	 * Returns the belief revision strategy of this agent.
-	 * 
-	 * @return the beliefRevisionStrategy.
+	 * @see bdi4jade.core.BDIAgent#getBeliefRevisionStrategy()
 	 */
+	@Override
 	public final AgentBeliefRevisionStrategy getBeliefRevisionStrategy() {
 		return beliefRevisionStrategy;
 	}
@@ -499,22 +498,18 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 	}
 
 	/**
-	 * Returns the capabilities of this agent. It may be a single root
-	 * capability or a set of capabilities.
-	 * 
-	 * @return the set of capabilities of this agent.
+	 * @see bdi4jade.core.BDIAgent#getCapabilities()
 	 */
-	public Set<Capability> getCapabilities() {
+	public final Set<Capability> getCapabilities() {
 		synchronized (aggregatedCapabilities) {
 			return aggregatedCapabilities;
 		}
 	}
 
 	/**
-	 * Returns the deliberation function of this agent.
-	 * 
-	 * @return the deliberationFunction
+	 * @see bdi4jade.core.BDIAgent#getDeliberationFunction()
 	 */
+	@Override
 	public final AgentDeliberationFunction getDeliberationFunction() {
 		return deliberationFunction;
 	}
@@ -577,19 +572,17 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 	}
 
 	/**
-	 * Returns the option generation function of this agent.
-	 * 
-	 * @return the optionGenerationFunction
+	 * @see bdi4jade.core.BDIAgent#getOptionGenerationFunction()
 	 */
+	@Override
 	public final AgentOptionGenerationFunction getOptionGenerationFunction() {
 		return optionGenerationFunction;
 	}
 
 	/**
-	 * Returns the plan selection strategy of this agent.
-	 * 
-	 * @return the planSelectionStrategy
+	 * @see bdi4jade.core.BDIAgent#getPlanSelectionStrategy()
 	 */
+	@Override
 	public final AgentPlanSelectionStrategy getPlanSelectionStrategy() {
 		return planSelectionStrategy;
 	}
@@ -676,7 +669,7 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
 	 * @see BDIAgent#restart()
 	 */
 	@Override
-	public void restart() {
+	public final void restart() {
 		this.bdiInterpreter.restart();
 	}
 
diff --git a/bdi-jade/src/bdi4jade/core/BDIAgent.java b/bdi-jade/src/bdi4jade/core/BDIAgent.java
index 8d5c82f..5f89105 100644
--- a/bdi-jade/src/bdi4jade/core/BDIAgent.java
+++ b/bdi-jade/src/bdi4jade/core/BDIAgent.java
@@ -33,6 +33,10 @@ import bdi4jade.belief.Belief;
 import bdi4jade.event.GoalListener;
 import bdi4jade.goal.Goal;
 import bdi4jade.goal.Softgoal;
+import bdi4jade.reasoning.AgentBeliefRevisionStrategy;
+import bdi4jade.reasoning.AgentDeliberationFunction;
+import bdi4jade.reasoning.AgentOptionGenerationFunction;
+import bdi4jade.reasoning.AgentPlanSelectionStrategy;
 
 /**
  * This interfaces represents a BDIAgent that has a current set of goals, which
@@ -156,6 +160,13 @@ public interface BDIAgent {
 	public Collection<Capability> getAllCapabilities();
 
 	/**
+	 * Returns the belief revision strategy of this agent.
+	 * 
+	 * @return the beliefRevisionStrategy.
+	 */
+	public AgentBeliefRevisionStrategy getBeliefRevisionStrategy();
+
+	/**
 	 * Returns a collection of all beliefs from all capabilities of this agent.
 	 * It may have two equivalent beliefs, i.e. beliefs with the same name.
 	 * 
@@ -164,6 +175,21 @@ public interface BDIAgent {
 	public Collection<Belief<?, ?>> getBeliefs();
 
 	/**
+	 * Returns the capabilities of this agent. It may be a single root
+	 * capability or a set of capabilities.
+	 * 
+	 * @return the set of capabilities of this agent.
+	 */
+	public Set<Capability> getCapabilities();
+
+	/**
+	 * Returns the deliberation function of this agent.
+	 * 
+	 * @return the deliberationFunction
+	 */
+	public AgentDeliberationFunction getDeliberationFunction();
+
+	/**
 	 * Returns all goal listeners.
 	 * 
 	 * @return the goalListeners.
@@ -187,6 +213,20 @@ public interface BDIAgent {
 	public Set<Intention> getIntentions();
 
 	/**
+	 * Returns the option generation function of this agent.
+	 * 
+	 * @return the optionGenerationFunction
+	 */
+	public AgentOptionGenerationFunction getOptionGenerationFunction();
+
+	/**
+	 * Returns the plan selection strategy of this agent.
+	 * 
+	 * @return the planSelectionStrategy
+	 */
+	public AgentPlanSelectionStrategy getPlanSelectionStrategy();
+
+	/**
 	 * Gets all softgoals of this agent.
 	 * 
 	 * @return the set of softgoals.
diff --git a/bdi-jade/src/bdi4jade/core/Capability.java b/bdi-jade/src/bdi4jade/core/Capability.java
index 06f4619..33794bd 100644
--- a/bdi-jade/src/bdi4jade/core/Capability.java
+++ b/bdi-jade/src/bdi4jade/core/Capability.java
@@ -75,7 +75,7 @@ public class Capability implements Serializable {
 	protected final String id;
 	private final Collection<Intention> intentions;
 	protected final Log log;
-	private AbstractBDIAgent myAgent;
+	private BDIAgent myAgent;
 	private OptionGenerationFunction optionGenerationFunction;
 	private final List<Class<? extends Capability>> parentCapabilities;
 	private final Set<Capability> partCapabilities;
@@ -647,7 +647,9 @@ public class Capability implements Serializable {
 
 	private final void resetAgentCapabilities() {
 		if (myAgent != null) {
-			myAgent.resetAllCapabilities();
+			if (myAgent instanceof AbstractBDIAgent) {
+				((AbstractBDIAgent) myAgent).resetAllCapabilities();
+			}
 		}
 	}
 
@@ -694,7 +696,7 @@ public class Capability implements Serializable {
 	 * @param myAgent
 	 *            the myAgent to set
 	 */
-	final synchronized void setMyAgent(AbstractBDIAgent myAgent) {
+	final synchronized void setMyAgent(BDIAgent myAgent) {
 		if (this.myAgent != null && myAgent == null) {
 			takeDown();
 		}
diff --git a/bdi-jade/src/bdi4jade/core/MultipleCapabilityAgent.java b/bdi-jade/src/bdi4jade/core/MultipleCapabilityAgent.java
index 281413d..6895008 100644
--- a/bdi-jade/src/bdi4jade/core/MultipleCapabilityAgent.java
+++ b/bdi-jade/src/bdi4jade/core/MultipleCapabilityAgent.java
@@ -86,14 +86,6 @@ public class MultipleCapabilityAgent extends AbstractBDIAgent {
 	}
 
 	/**
-	 * @see bdi4jade.core.AbstractBDIAgent#getAllCapabilities()
-	 */
-	@Override
-	public final Collection<Capability> getAllCapabilities() {
-		return super.getAllCapabilities();
-	}
-
-	/**
 	 * @see bdi4jade.core.AbstractBDIAgent#removeCapability(bdi4jade.core.Capability)
 	 */
 	@Override
diff --git a/bdi-jade/src/bdi4jade/message/BDIAgentMsgReceiver.java b/bdi-jade/src/bdi4jade/message/BDIAgentMsgReceiver.java
index ebbc865..fe5e5d1 100644
--- a/bdi-jade/src/bdi4jade/message/BDIAgentMsgReceiver.java
+++ b/bdi-jade/src/bdi4jade/message/BDIAgentMsgReceiver.java
@@ -22,6 +22,7 @@
 
 package bdi4jade.message;
 
+import jade.core.Agent;
 import jade.core.behaviours.DataStore;
 import jade.lang.acl.ACLMessage;
 import jade.lang.acl.MessageTemplate;
@@ -31,7 +32,7 @@ import jade.proto.states.MsgReceiver;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import bdi4jade.core.AbstractBDIAgent;
+import bdi4jade.core.BDIAgent;
 
 /**
  * This class extends the {@link MsgReceiver} behavior from the JADE platform
@@ -84,9 +85,9 @@ public class BDIAgentMsgReceiver extends MsgReceiver {
 	 * @param agent
 	 *            the BDI agent that this behavior is associated with.
 	 */
-	public BDIAgentMsgReceiver(AbstractBDIAgent agent) {
-		super(agent, MessageTemplate.MatchAll(), INFINITE, new DataStore(),
-				MSG_KEY);
+	public BDIAgentMsgReceiver(BDIAgent agent) {
+		super((Agent) agent, MessageTemplate.MatchAll(), INFINITE,
+				new DataStore(), MSG_KEY);
 		this.template = new MessageTemplate(new BDIAgentMatchExpression());
 		this.log = LogFactory.getLog(this.getClass());
 	}
@@ -102,8 +103,8 @@ public class BDIAgentMsgReceiver extends MsgReceiver {
 		return false;
 	}
 
-	private AbstractBDIAgent getMyAgent() {
-		return (AbstractBDIAgent) this.myAgent;
+	private BDIAgent getMyAgent() {
+		return (BDIAgent) this.myAgent;
 	}
 
 	/**
diff --git a/bdi-jade/src/bdi4jade/reasoning/AbstractAgentReasoningStrategy.java b/bdi-jade/src/bdi4jade/reasoning/AbstractAgentReasoningStrategy.java
index 83d9aa6..511f2ae 100644
--- a/bdi-jade/src/bdi4jade/reasoning/AbstractAgentReasoningStrategy.java
+++ b/bdi-jade/src/bdi4jade/reasoning/AbstractAgentReasoningStrategy.java
@@ -22,7 +22,7 @@
 
 package bdi4jade.reasoning;
 
-import bdi4jade.core.AbstractBDIAgent;
+import bdi4jade.core.BDIAgent;
 
 /**
  * This class provides an abstract implementation of the
@@ -35,13 +35,13 @@ import bdi4jade.core.AbstractBDIAgent;
 public abstract class AbstractAgentReasoningStrategy implements
 		AgentReasoningStrategy {
 
-	protected AbstractBDIAgent agent;
+	protected BDIAgent agent;
 
 	/**
-	 * @see bdi4jade.reasoning.AgentReasoningStrategy#setAgent(bdi4jade.core.AbstractBDIAgent)
+	 * @see bdi4jade.reasoning.AgentReasoningStrategy#setAgent(bdi4jade.core.BDIAgent)
 	 */
 	@Override
-	public void setAgent(AbstractBDIAgent agent) {
+	public void setAgent(BDIAgent agent) {
 		if (agent != null && this.agent != null && !this.agent.equals(agent)) {
 			throw new IllegalArgumentException(
 					"This reasoning strategy is already associated with another agent.");
diff --git a/bdi-jade/src/bdi4jade/reasoning/AgentReasoningStrategy.java b/bdi-jade/src/bdi4jade/reasoning/AgentReasoningStrategy.java
index 58d6194..9ee68f3 100644
--- a/bdi-jade/src/bdi4jade/reasoning/AgentReasoningStrategy.java
+++ b/bdi-jade/src/bdi4jade/reasoning/AgentReasoningStrategy.java
@@ -22,7 +22,7 @@
 
 package bdi4jade.reasoning;
 
-import bdi4jade.core.AbstractBDIAgent;
+import bdi4jade.core.BDIAgent;
 
 /**
  * This interface defines methods that should be implemented by all agent
@@ -40,6 +40,6 @@ public interface AgentReasoningStrategy {
 	 * @param agent
 	 *            the agent to set.
 	 */
-	public void setAgent(AbstractBDIAgent agent);
+	public void setAgent(BDIAgent agent);
 
 }
diff --git a/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesAction.java b/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesAction.java
index eb56794..8aadc42 100644
--- a/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesAction.java
+++ b/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesAction.java
@@ -1,5 +1,7 @@
 package bdi4jade.examples;
 
+import jade.core.Agent;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -10,7 +12,6 @@ import javax.swing.Action;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import bdi4jade.core.AbstractBDIAgent;
 import bdi4jade.core.SingleCapabilityAgent;
 
 /**
@@ -42,9 +43,9 @@ public abstract class BDI4JADEExamplesAction extends AbstractAction {
 		super.setEnabled(true);
 	}
 
-	public Map<String, AbstractBDIAgent> getAgentMap() {
-		Map<String, AbstractBDIAgent> agentMap = new HashMap<>();
-		for (AbstractBDIAgent agent : getAgents()) {
+	public Map<String, Agent> getAgentMap() {
+		Map<String, Agent> agentMap = new HashMap<>();
+		for (Agent agent : getAgents()) {
 			if (SingleCapabilityAgent.class.equals(agent.getClass())) {
 				SingleCapabilityAgent singleCapAgent = (SingleCapabilityAgent) agent;
 				agentMap.put(singleCapAgent.getCapability().getId() + "Agent",
@@ -56,6 +57,6 @@ public abstract class BDI4JADEExamplesAction extends AbstractAction {
 		return agentMap;
 	}
 
-	public abstract Set<AbstractBDIAgent> getAgents();
+	public abstract Set<Agent> getAgents();
 
 }
diff --git a/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesApp.java b/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesApp.java
index 095738d..9669a15 100644
--- a/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesApp.java
+++ b/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesApp.java
@@ -23,6 +23,7 @@
 package bdi4jade.examples;
 
 import jade.BootProfileImpl;
+import jade.core.Agent;
 import jade.core.ProfileImpl;
 import jade.wrapper.AgentContainer;
 import jade.wrapper.AgentController;
@@ -39,8 +40,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.log4j.PropertyConfigurator;
 
-import bdi4jade.core.AbstractBDIAgent;
-
 /**
  * This class is responsible for initiating the BDI4JADE app. It bootstraps
  * JADE, runs agents of a {@link BDI4JADEExamplesPanel}, and makes a GUI visible
@@ -78,7 +77,7 @@ public class BDI4JADEExamplesApp {
 		PlatformController controller = runtime
 				.createMainContainer(bootProfile);
 
-		Map<String, AbstractBDIAgent> agents = agentTestPanel.getAgents();
+		Map<String, Agent> agents = agentTestPanel.getAgents();
 		for (String agentName : agents.keySet()) {
 			try {
 				AgentController ac = ((AgentContainer) controller)
diff --git a/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesPanel.java b/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesPanel.java
index 60b61d0..f32e796 100644
--- a/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesPanel.java
+++ b/bdi-jade-test/src/bdi4jade/examples/BDI4JADEExamplesPanel.java
@@ -1,5 +1,7 @@
 package bdi4jade.examples;
 
+import jade.core.Agent;
+
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.util.HashMap;
@@ -14,7 +16,6 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.SwingUtilities;
 
-import bdi4jade.core.AbstractBDIAgent;
 import bdi4jade.core.MultipleCapabilityAgent;
 import bdi4jade.core.SingleCapabilityAgent;
 import bdi4jade.event.GoalEvent;
@@ -91,8 +92,8 @@ public class BDI4JADEExamplesPanel extends JPanel {
 		}
 
 		@Override
-		public Set<AbstractBDIAgent> getAgents() {
-			Set<AbstractBDIAgent> agents = new HashSet<>();
+		public Set<Agent> getAgents() {
+			Set<Agent> agents = new HashSet<>();
 			agents.add(blocksWorldAgent);
 			return agents;
 		}
@@ -107,7 +108,7 @@ public class BDI4JADEExamplesPanel extends JPanel {
 			GoalListener {
 		private static final long serialVersionUID = 2100583035268414082L;
 
-		private final AbstractBDIAgent compositeGoalAgent;
+		private final SingleCapabilityAgent compositeGoalAgent;
 
 		public CompositeGoalAction() {
 			super.putValue(Action.NAME, "Composite Goal Agent");
@@ -133,8 +134,8 @@ public class BDI4JADEExamplesPanel extends JPanel {
 		}
 
 		@Override
-		public Set<AbstractBDIAgent> getAgents() {
-			Set<AbstractBDIAgent> agents = new HashSet<>();
+		public Set<Agent> getAgents() {
+			Set<Agent> agents = new HashSet<>();
 			agents.add(compositeGoalAgent);
 			return agents;
 		}
@@ -167,8 +168,8 @@ public class BDI4JADEExamplesPanel extends JPanel {
 		}
 
 		@Override
-		public Set<AbstractBDIAgent> getAgents() {
-			Set<AbstractBDIAgent> agents = new HashSet<>();
+		public Set<Agent> getAgents() {
+			Set<Agent> agents = new HashSet<>();
 			agents.add(helloWorldAgent);
 			return agents;
 		}
@@ -197,8 +198,8 @@ public class BDI4JADEExamplesPanel extends JPanel {
 		}
 
 		@Override
-		public Set<AbstractBDIAgent> getAgents() {
-			Set<AbstractBDIAgent> agents = new HashSet<>();
+		public Set<Agent> getAgents() {
+			Set<Agent> agents = new HashSet<>();
 			agents.add(helloWorldAnnotatedAgent);
 			return agents;
 		}
@@ -230,8 +231,8 @@ public class BDI4JADEExamplesPanel extends JPanel {
 		}
 
 		@Override
-		public Set<AbstractBDIAgent> getAgents() {
-			Set<AbstractBDIAgent> agents = new HashSet<>();
+		public Set<Agent> getAgents() {
+			Set<Agent> agents = new HashSet<>();
 			agents.add(multiCapabilityAgent);
 			return agents;
 		}
@@ -243,8 +244,8 @@ public class BDI4JADEExamplesPanel extends JPanel {
 		public static final String AGENT_2 = "Bob";
 		private static final long serialVersionUID = 2100583035268414082L;
 
-		private final AbstractBDIAgent agent1;
-		private final AbstractBDIAgent agent2;
+		private final SingleCapabilityAgent agent1;
+		private final SingleCapabilityAgent agent2;
 
 		public PingPongAction() {
 			super.putValue(Action.NAME, "Ping Pong Agents");
@@ -260,15 +261,15 @@ public class BDI4JADEExamplesPanel extends JPanel {
 			this.agent2.addGoal(new PingPongCapability.PingGoal());
 		}
 
-		public Map<String, AbstractBDIAgent> getAgentMap() {
-			Map<String, AbstractBDIAgent> agentMap = new HashMap<>();
+		public Map<String, Agent> getAgentMap() {
+			Map<String, Agent> agentMap = new HashMap<>();
 			agentMap.put(AGENT_1, agent1);
 			agentMap.put(AGENT_2, agent2);
 			return agentMap;
 		}
 
 		@Override
-		public Set<AbstractBDIAgent> getAgents() {
+		public Set<Agent> getAgents() {
 			return new HashSet<>(getAgentMap().values());
 		}
 	}
@@ -306,8 +307,8 @@ public class BDI4JADEExamplesPanel extends JPanel {
 		}
 
 		@Override
-		public Set<AbstractBDIAgent> getAgents() {
-			Set<AbstractBDIAgent> agents = new HashSet<>();
+		public Set<Agent> getAgents() {
+			Set<Agent> agents = new HashSet<>();
 			agents.add(planFailureAgent);
 			return agents;
 		}
@@ -328,7 +329,7 @@ public class BDI4JADEExamplesPanel extends JPanel {
 	private class SubgoalCapabilityAction extends BDI4JADEExamplesAction {
 		private static final long serialVersionUID = 2100583035268414082L;
 
-		private final AbstractBDIAgent subgoalCapability;
+		private final SingleCapabilityAgent subgoalCapability;
 
 		public SubgoalCapabilityAction() {
 			super.putValue(Action.NAME, "Subgoal Goal Agent");
@@ -342,8 +343,8 @@ public class BDI4JADEExamplesPanel extends JPanel {
 		}
 
 		@Override
-		public Set<AbstractBDIAgent> getAgents() {
-			Set<AbstractBDIAgent> agents = new HashSet<>();
+		public Set<Agent> getAgents() {
+			Set<Agent> agents = new HashSet<>();
 			agents.add(subgoalCapability);
 			return agents;
 		}
@@ -365,8 +366,8 @@ public class BDI4JADEExamplesPanel extends JPanel {
 		}
 	}
 
-	public Map<String, AbstractBDIAgent> getAgents() {
-		Map<String, AbstractBDIAgent> agents = new HashMap<>();
+	public Map<String, Agent> getAgents() {
+		Map<String, Agent> agents = new HashMap<>();
 		for (BDI4JADEExamplesAction action : actions) {
 			agents.putAll(action.getAgentMap());
 		}