/** * 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()); }
/** * A shortcut for dispatching a goal as subgoal of the active goal,, * and waiting for the subgoal to be finished (without timout). * @param subgoal The new subgoal. * @throws GoalFailureException when the goal fails. */ public void dispatchSubgoalAndWait(IGoal subgoal) { dispatchSubgoalAndWait(subgoal, -1); }
/** * 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()); }
/** * Create a new wait abstraction. * @return The wait abstraction. */ public IWaitAbstraction createWaitAbstraction() { return WaitAbstractionFlyweight.getWaitAbstractionFlyweight(getState(), getRCapability(), getState().createObject(OAVBDIRuntimeModel.waitabstraction_type)); }
/** * 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()); }
/** * 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 the result. * @param timeout The timeout. * @return The result. * @throws TimeoutException when result is not available in specified time frame. */ public Object waitForResult(long timeout) { if(!getInterpreter().isPlanThread()) throw new RuntimeException("SyncResultListener may only be used from plan thread."); if(!alreadyresumed) { this.alreadysuspended = true; waitForExternalCondition(this, timeout); } Exception ex = exception; Object res = result; reset(); // if(ex instanceof RuntimeException) // throw (RuntimeException)ex; if(ex!=null) throw new RuntimeException(ex); return res; }
/** * Wait for a clock tick. * todo: @param num The number of ticks? */ public void waitForTick() { PlanRules.waitForWaitAbstraction(null, PlanRules.TICK_TIMER, 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; }
if(!getInterpreter().isPlanThread()) throw new RuntimeException("SyncResultListener may only be used from plan thread."); waitForExternalCondition(lis, timeout); // Don't use waitForResult(), because of exception being thrown.
/** * 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 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()); }
/** * 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 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()); }
/** * 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 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()); }