/** * Wait for a condition to be satisfied. * @param condition The condition. */ public void waitForCondition(String condition, long timeout) { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addCondition(wa, condition, getState(), getRCapability()); PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Test if a message event has been registered at the waitqueue. * @param msgevent The message event. * @return True, if is registered. */ public boolean isEventRegisteredInWaitqueue(Object rmevent) { boolean ret = false; Object wqwa = getState().getAttributeValue(getRPlan(), OAVBDIRuntimeModel.plan_has_waitqueuewa); if(wqwa!=null) { Collection coll = getState().getAttributeValues(wqwa, OAVBDIRuntimeModel.waitabstraction_has_messageevents); if(coll!=null) ret = coll.contains(rmevent); } return ret; }
/** * Wait for a message event. * @param type The message event type. * @param timeout The timeout. */ public IMessageEvent waitForMessageEvent(String type, long timeout) { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addMessageEvent(wa, type, getState(), getRCapability()); return (IMessageEvent)PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Wait for a goal. * @param type The goal type. * @param timeout The timeout. */ public IGoal waitForGoal(String type, long timeout) { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addGoal(wa, type, getState(), getRCapability()); return (IGoal)PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Wait for an internal event. * @param type The internal event type. * @param timeout The timeout. */ public IInternalEvent waitForInternalEvent(String type, long timeout) { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addInternalEvent(wa, type, getState(), getRCapability()); return (IInternalEvent)PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Wait for an external condition * @param condition The external condition. * @param timeout The timeout. */ public void waitForExternalCondition(IExternalCondition condition, long timeout) { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addExternalCondition(wa, condition, getState(), getRCapability()); PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Halt the plan. The plan will remain in the agent until it is aborted. */ public void waitForEver() { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); PlanRules.waitForWaitAbstraction(wa, -1, getState(), getRCapability(), getRPlan()); }
/** * Wait for a belief (set) fact change. * @param beliefset The belief (set) type. * @param timeout The timeout. * @return The changed fact. */ public Object waitForFactAdded(String beliefset, long timeout) { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addFactAdded(wa, beliefset, getState(), getRCapability()); return PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Wait for a belief (set) fact change. * @param beliefset The belief (set) type. * @param timeout The timeout. * @return The changed fact. */ public Object waitForFactRemoved(String beliefset, long timeout) { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addFactRemoved(wa, beliefset, getState(), getRCapability()); return PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Wait for a belief (set) fact change. * @param belief The belief (set) type. * @param timeout The timeout. * @return The changed fact. */ public Object waitForFactChanged(String belief, long timeout) { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addFactChanged(wa, belief, getState(), getRCapability()); return PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Wait for a belief (set) fact addition or removal. * @param beliefset The belief (set) type. * @param timeout The timeout. * @return The changed fact. */ public Object waitForFactAddedOrRemoved(String beliefset, long timeout) { // Todo: check thread access. // todo: return change event to indicate the type of change Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addFactAdded(wa, beliefset, getState(), getRCapability()); SFlyweightFunctionality.addFactRemoved(wa, beliefset, getState(), getRCapability()); return PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Wait for a message. * @param msgevent The message event. */ public IMessageEvent waitForReply(IMessageEvent msgevent, long timeout) { // Ensure that the message event is registered and waitqueue is established. Otherwise // a message loss could happen. Object rmevent = ((ElementFlyweight)msgevent).getHandle(); if(!MessageEventRules.containsRegisteredMessageEvents(getState(), getRCapability(), rmevent)) throw new RuntimeException("Message event not registered: "+rmevent); if(!isEventRegisteredInWaitqueue(rmevent)) throw new RuntimeException("Messages to be used in waitForReply() have to be registered" + "in the event in the waitqueue before(!) being sent: "+rmevent); // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addReply(wa, (ElementFlyweight)msgevent, getState(), getRCapability()); return (IMessageEvent)PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Wait for a some time. * @param duration The duration. */ public void waitFor(long duration) { // Todo: check thread access. PlanRules.waitForWaitAbstraction(null, duration, getState(), getRCapability(), getRPlan()); }
/** * A shortcut for dispatching a goal as subgoal of the active goal * and waiting for the subgoal to be finished. * Additionally the subgoal will be dropped when finished. * This differs from the dispatchSubgoal implementation. * @param subgoal The new subgoal. * @param timeout The timeout. * @throws GoalFailureException when the goal fails. */ public void dispatchSubgoalAndWait(IGoal subgoal, long timeout) { dispatchSubgoal(subgoal); // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addGoal(wa, (ElementFlyweight)subgoal, getState(), getRCapability()); PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }
/** * Wait for a clock tick. * todo: @param num The number of ticks? */ public void waitForTick() { PlanRules.waitForWaitAbstraction(null, PlanRules.TICK_TIMER, getState(), getRCapability(), getRPlan()); }
/** * Send a message and wait for the answer. * Adds a reply_with entry if not present, for tracking the conversation. * @param me The message event. * @param timeout The timeout. * @return The result event. */ public IMessageEvent sendMessageAndWait(IMessageEvent me, long timeout, byte[] codecids) { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addReply(wa, (ElementFlyweight)me, getState(), getRCapability()); Object[] ret = PlanRules.initializeWait(wa, timeout, getState(), getRCapability(), getRPlan()); sendMessage(me, codecids); if(ret[0]==null) { PlanRules.doWait(getState(), getRPlan()); ret[0] = PlanRules.afterWait(wa, (boolean[])ret[1], getState(), getRCapability(), getRPlan()); } return (IMessageEvent)ret[0]; }
/** * Wait for a goal. * @param goal The goal. * @param timeout The timeout. */ public void waitForGoal(final IGoal goal, long timeout) { if(goal.isFinished()) { // Todo: check thread access. if(OAVBDIRuntimeModel.GOALPROCESSINGSTATE_FAILED.equals( getState().getAttributeValue(((ElementFlyweight)goal).getHandle(), OAVBDIRuntimeModel.goal_has_processingstate))) { throw new GoalFailureException("Goal failed: "+goal); } } else { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addGoal(wa, (ElementFlyweight)goal, getState(), getRCapability()); PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); } }
/** * Wait for a wait abstraction. * @return The dispatched element. */ public Object waitForWaitAbstraction(IWaitAbstraction waitabs, long timeout) { return PlanRules.waitForWaitAbstraction(((ElementFlyweight)waitabs).getHandle(), timeout, getState(), getRCapability(), getRPlan()); }
/** * Get the monitor for waiting. * @return The monitor. */ public Object getMonitor() { BDIInterpreter pi = BDIInterpreter.getInterpreter(getState()); IPlanExecutor exe = pi==null? null: pi.getPlanExecutor(getRPlan()); return exe==null? null: exe.getMonitor(getRPlan()); }