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

jadex.bdiv3.actions.DropGoalAction Maven / Gradle / Ivy

Go to download

BDIV3 Kernel that supports annotated POJOs and uses byte code manipulation for performance improvements.

There is a newer version: 4.0.267
Show newest version
package jadex.bdiv3.actions;

import jadex.bdiv3.features.impl.IInternalBDIAgentFeature;
import jadex.bdiv3.runtime.impl.RGoal;
import jadex.bridge.IConditionalComponentStep;
import jadex.bridge.IInternalAccess;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;

/**
 * 
 */
public class DropGoalAction implements IConditionalComponentStep
{
	/** The goal. */
	protected RGoal goal;
	
	/**
	 *  Create a new action.
	 */
	public DropGoalAction(RGoal goal)
	{
		this.goal = goal;
	}
	
	/**
	 *  Test if the action is valid.
	 *  @return True, if action is valid.
	 */
	public boolean isValid()
	{
		return RGoal.GoalLifecycleState.DROPPING.equals(goal.getLifecycleState());
	}
	
	/**
	 *  Execute the command.
	 *  @param args The argument(s) for the call.
	 *  @return The result of the command.
	 */
	public IFuture execute(final IInternalAccess ia)
	{
		final Future ret = new Future();
//		BDIAgentInterpreter ip = (BDIAgentInterpreter)((BDIAgent)ia).getInterpreter();
//		goal.unobserveGoal(ia);
		
		goal.callFinishedMethod().addResultListener(new IResultListener()
		{
			public void resultAvailable(Void result)
			{
				cont();
			}
			
			public void exceptionOccurred(Exception exception)
			{
				cont();
			}
			
			protected void cont()
			{
				ia.getComponentFeature(IInternalBDIAgentFeature.class).getCapability().removeGoal(goal);
				goal.setLifecycleState(ia, RGoal.GoalLifecycleState.DROPPED);
				ret.setResult(null);
			}
		});
		
		return ret;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy