/** * Create a new expression. * @param state The state. * @param scope The scope handle. */ public ExpressionNoModel(IOAVState state, Object scope, IParsedExpression expression) { this.state = state; this.scope = scope; this.expression = expression; this.interpreter = BDIInterpreter.getInterpreter(state); }
/** * Create a new fetcher. */ public OAVBDIFetcher(IOAVState state, Object rcapa) { this.state = state; this.adapter = BDIInterpreter.getInterpreter(state).getAgentAdapter(); this.rcapa = rcapa; }
/** * Get a property value. * @param state The state. * @param rcapa The capability. * @param name The name. * @return The property value. */ public static Object getPropertyValue(IOAVState state, Object rcapa, String name) { Map props = BDIInterpreter.getInterpreter(state).getProperties(rcapa); return props!=null ? props.get(name) : null; }
/** * Get the logger. * @return The logger. */ public Logger getLogger() { return BDIInterpreter.getInterpreter(state).getLogger(rcapa); }
/** * Do the waiting, i.e. set the external caller thread to sleep mode. */ public static void doWait(IOAVState state, Object rplan) { IPlanExecutor exe = BDIInterpreter.getInterpreter(state).getPlanExecutor(rplan); exe.eventWaitFor(BDIInterpreter.getInterpreter(state), rplan); }
public void run() { object = BDIInterpreter.getInterpreter(getState())!=null? BDIInterpreter.getInterpreter(getState()).getLogger(getScope()): Logger.getAnonymousLogger(); } };
public void execute(IOAVState state, IVariableAssignments assignments) { Object ragent = assignments.getVariableValue("?ragent"); Object rawmsg = assignments.getVariableValue("?rawmsg"); String agentname = BDIInterpreter.getInterpreter(state).getAgentAdapter().getComponentIdentifier().getLocalName(); BDIInterpreter.getInterpreter(state).getLogger(ragent).severe("Agent has received msg and has found no template: "+agentname+" "+rawmsg); state.removeAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_inbox, rawmsg); } };
/** * Execute the action. */ public void run() { // System.out.println("Timer occurred: "); to[0] = true; EventProcessingRules.schedulePlanInstanceCandidate(state, null, rplan, rcapa); BDIInterpreter.getInterpreter(state).getAgentAdapter().wakeup(); } }
/** * Get the message event type of a message event. */ public static MessageType getMessageEventType(IOAVState state, Object mme) { String mtype = (String)state.getAttributeValue(mme, OAVBDIMetaModel.messageevent_has_type); BDIInterpreter bdii = BDIInterpreter.getInterpreter(state); MessageType ret = bdii.getMessageService().getMessageType(mtype); return ret; } }
/** * Adopt an internal event. * Adds the event to the state (eventbase). * @param state The state * @param rcapa The capability. * @param rgoal The goal. */ public static void adoptInternalEvent(IOAVState state, Object rcapa, Object rinternalevent) { state.addAttributeValue(rcapa, OAVBDIRuntimeModel.capability_has_internalevents, rinternalevent); // Hack!!! Only needed for external access! BDIInterpreter.getInterpreter(state).getAgentAdapter().wakeup(); } }
/** * Add a goal instance to an OAV waitabstraction. */ public static void addGoal(Object wa, ElementFlyweight goal, IOAVState state, Object rcapa) { Collection goals = state.getAttributeValues(wa, OAVBDIRuntimeModel.waitabstraction_has_goals); Object rgoal = goal.getHandle(); if(goals==null || !goals.contains(rgoal)) state.addAttributeValue(wa, OAVBDIRuntimeModel.waitabstraction_has_goals, rgoal); BDIInterpreter.getInterpreter(state).getEventReificator().addObservedElement(rgoal); }
/** * Remove a goal. * @param goal The goal. */ public static void removeGoal(IOAVState state, ElementFlyweight goal, Object wa) { if(wa!=null) { Object rgoal = goal.getHandle(); Collection goals = state.getAttributeValues(wa, OAVBDIRuntimeModel.waitabstraction_has_goals); if(goals!=null && goals.contains(rgoal)) state.removeAttributeValue(wa, OAVBDIRuntimeModel.waitabstraction_has_goals, rgoal); BDIInterpreter.getInterpreter(state).getEventReificator().removeObservedElement(rgoal); } }
/** * Get or create a flyweight. * @return The flyweight. */ public static WaitqueueFlyweight getWaitqueueFlyweight(IOAVState state, Object scope, Object rplan) { Tuple key = new Tuple(rplan, IWaitqueue.class); BDIInterpreter ip = BDIInterpreter.getInterpreter(state); WaitqueueFlyweight ret = (WaitqueueFlyweight)ip.getFlyweightCache(IWaitqueue.class, key); if(ret==null) { ret = new WaitqueueFlyweight(state, scope, rplan); ip.putFlyweightCache(IWaitqueue.class, key, ret); } return ret; }
/** * 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()); }
public void run() { // todo: test if already canceled?! // if(state.containsObject(ragent)) // { // todo: cleanup? or in terminated action? // System.out.println("Forcing termination (timeout): "+interpreter.getAgentAdapter().getComponentIdentifier().getLocalName()); BDIInterpreter.getInterpreter(state).getLogger(ragent).info("Forcing termination (timeout): "+interpreter.getAgentAdapter().getComponentIdentifier().getLocalName()); state.setAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_state, OAVBDIRuntimeModel.AGENTLIFECYCLESTATE_TERMINATED); interpreter.getAgentAdapter().wakeup(); // } } })));
/** * Get or create a flyweight. * @return The flyweight. */ public static GoalbaseFlyweight getGoalbaseFlyweight(IOAVState state, Object scope) { BDIInterpreter ip = BDIInterpreter.getInterpreter(state); GoalbaseFlyweight ret = (GoalbaseFlyweight)ip.getFlyweightCache(IGoalbase.class, new Tuple(IGoalbase.class, scope)); if(ret==null) { ret = new GoalbaseFlyweight(state, scope); ip.putFlyweightCache(IGoalbase.class, new Tuple(IGoalbase.class, scope), ret); } return ret; }
/** * Get or create a flyweight. * @return The flyweight. */ public static EventbaseFlyweight getEventbaseFlyweight(IOAVState state, Object scope) { BDIInterpreter ip = BDIInterpreter.getInterpreter(state); EventbaseFlyweight ret = (EventbaseFlyweight)ip.getFlyweightCache(IEventbase.class, new Tuple(IEventbase.class, scope)); if(ret==null) { ret = new EventbaseFlyweight(state, scope); ip.putFlyweightCache(IEventbase.class, new Tuple(IEventbase.class, scope), ret); } return ret; }
/** * Get or create a flyweight. * @return The flyweight. */ public static WaitAbstractionFlyweight getWaitAbstractionFlyweight(IOAVState state, Object scope, Object handle) { BDIInterpreter ip = BDIInterpreter.getInterpreter(state); WaitAbstractionFlyweight ret = (WaitAbstractionFlyweight)ip.getFlyweightCache(IWaitAbstraction.class, new Tuple(IWaitAbstraction.class, handle)); if(ret==null) { ret = new WaitAbstractionFlyweight(state, scope, handle); ip.putFlyweightCache(IWaitAbstraction.class, new Tuple(IWaitAbstraction.class, handle), ret); } return ret; }
/** * Get or create a flyweight. * @return The flyweight. */ public static BeliefFlyweight getBeliefFlyweight(IOAVState state, Object scope, Object handle) { BDIInterpreter ip = BDIInterpreter.getInterpreter(state); BeliefFlyweight ret = (BeliefFlyweight)ip.getFlyweightCache(IBelief.class, new Tuple(IBelief.class, handle)); if(ret==null) { ret = new BeliefFlyweight(state, scope, handle); ip.putFlyweightCache(IBelief.class, new Tuple(IBelief.class, handle), ret); } return ret; }
/** * Get or create a flyweight. * @return The flyweight. */ public static MessageEventFlyweight getMessageEventFlyweight(IOAVState state, Object scope, Object handle) { BDIInterpreter ip = BDIInterpreter.getInterpreter(state); MessageEventFlyweight ret = (MessageEventFlyweight)ip.getFlyweightCache(IMessageEvent.class, new Tuple(IMessageEvent.class, handle)); if(ret==null) { ret = new MessageEventFlyweight(state, scope, handle); ip.putFlyweightCache(IMessageEvent.class, new Tuple(IMessageEvent.class, handle), ret); } return ret; }