/** * Wait for ever (is aborted on goal success/failure). */ public void waitForEver() { checkNotInAtomic(); Future<Void> ret = new Future<Void>(); ret.get(); }
/** * Wait for a some time. * @param duration The duration. */ public void waitFor(long timeout) { checkNotInAtomic(); agent.getComponentFeature(IExecutionFeature.class).waitForDelay(timeout).get(); }
/** * Wait for next tick. */ public void waitForTick() { checkNotInAtomic(); agent.getComponentFeature(IExecutionFeature.class).waitForTick().get(); }
checkNotInAtomic(); if(goal==null) throw new IllegalArgumentException("Goal must not null.");
/** * Dispatch a new top-level goal. * @param goal The new goal. */ public void dispatchSubgoalAndWait(IGoal goal, long timeout) { checkNotInAtomic(); dispatchSubgoal(goal); RGoal rgoal = (RGoal)goal; Future<Void> ret = new Future<Void>(); rgoal.addListener(new DelegationResultListener<Void>(ret)); try { ret.get(timeout); } catch(BDIFailureException e) { throw e; } catch(TimeoutException e) { throw e; } catch(Exception e) { throw new GoalFailureException(null, e); } }
/** * 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) { checkNotInAtomic(); IInternalBDIAgentFeature bdif = agent.getComponentFeature(IInternalBDIAgentFeature.class); WaitAbstraction wa = new WaitAbstraction(); wa.addReply((RMessageEvent)me, null); rplan.setWaitAbstraction(wa); sendMessage(me); Future<IMessageEvent> ret = new Future<IMessageEvent>(); try { agent.getComponentFeature(IInternalBDIXMessageFeature.class).registerMessageEvent((RMessageEvent)me); return ret.get(timeout); } finally { agent.getComponentFeature(IInternalBDIXMessageFeature.class).deregisterMessageEvent((RMessageEvent)me); } }
/** * Wait for a goal. * @param type The goal type. * @param timeout The timeout. */ public IGoal waitForGoalFinished(String type, long timeout) { checkNotInAtomic(); final Future<IGoal> ret = new Future<IGoal>(); BDIXModel model = (BDIXModel)agent.getModel().getRawModel(); MGoal mgoal = model.getCapability().getResolvedGoal(rplan.getModelElement().getCapabilityName(), type); WaitAbstraction wa = new WaitAbstraction(); wa.addChangeEventType(ChangeEvent.GOALDROPPED+"."+mgoal.getName()); ChangeEvent res = (ChangeEvent)rplan.getFromWaitqueue(wa); if(res!=null) { return (IGoal)res.getValue(); } else { rplan.setWaitAbstraction(wa); return ret.get(timeout); } }