/** * Create a new fetcher. */ public OAVBDIFetcher(IOAVState state, Object rcapa) { this.state = state; this.adapter = BDIInterpreter.getInterpreter(state).getAgentAdapter(); this.rcapa = rcapa; }
/** * Get the agent identifier. * @return The agent identifier. */ public IComponentIdentifier getComponentIdentifier() { return interpreter.getAgentAdapter().getComponentIdentifier(); }
public void invokeLater(Runnable action) { getAgentAdapter().invokeLater(action); } });
/** * Get the agent description. * @return The agent description. */ public IComponentDescription getComponentDescription() { return interpreter.getAgentAdapter().getDescription(); }
/** * Get the platform specific agent object. * Allows to do platform specific things. * @return The agent object. */ public Object getPlatformComponent() { return getInterpreter().getAgentAdapter(); }
/** * Called when the agent is removed from the platform. */ public void cleanup() { // System.err.println("Cleanup: "+getComponentIdentifier()); BDIInterpreter.interpreters.remove(state); for(Iterator it=externalthreads.iterator(); it.hasNext(); ) { Throwable[] exception = (Throwable[])it.next(); synchronized(exception) { exception[0] = new ComponentTerminatedException(getAgentAdapter().getComponentIdentifier()); exception[0].fillInStackTrace(); exception.notify(); it.remove(); } } // System.out.println(BDIInterpreter.interpreters.size()); }
/** * Second init step of agent. */ protected IFuture init1() { // assert isAgentThread(); assert !getAgentAdapter().isExternalThread(); return AgentRules.initializeCapabilityInstance(state, ragent); }
/** * Extended init procedure including subcapabilities. */ public IFuture init(IModelInfo model,String config) { // assert isAgentThread(); assert !getAgentAdapter().isExternalThread(); return initCapability(this.model, config); }
/** * Get a string representation. */ public String toString() { return interpreter.getAgentAdapter().getComponentIdentifier().getLocalName() + ": " + action; } }
/** * Test if current thread is external thread. * @return True if the current thread is not the component thread. */ public boolean isExternalThread() { return getInterpreter().getAgentAdapter().isExternalThread(); }
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(); // } } })));
/** * 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(); } }
/** * 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(); } }
/** * Adopt a goal. * Adds the goal to the state (goalbase). * @param state The state * @param rcapa The capability. * @param rgoal The goal. */ public static void adoptGoal(IOAVState state, Object rcapa, Object rgoal) { Collection coll = state.getAttributeValues(rcapa, OAVBDIRuntimeModel.capability_has_goals); if(coll!=null && coll.contains(rgoal)) throw new RuntimeException("Cannot adopt already adopted goal: "+rgoal); state.setAttributeValue(rgoal, OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ADOPTED); // for listeners state.setAttributeValue(rgoal, OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_OPTION); state.addAttributeValue(rcapa, OAVBDIRuntimeModel.capability_has_goals, rgoal); // Hack!!! Only needed for external access! BDIInterpreter.getInterpreter(state).getAgentAdapter().wakeup(); }
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); } };
/** * Send a message after some delay. * @param me The message event. * @return The filter to wait for an answer. */ public static IFuture sendMessage(IOAVState state, Object rcapa, Object rmessageevent, byte[] codecids) { Future ret = new Future(); state.setAttributeValue(rmessageevent, OAVBDIRuntimeModel.messageevent_has_sendfuture, ret); if(codecids!=null) state.setAttributeValue(rmessageevent, OAVBDIRuntimeModel.messageevent_has_codecids, codecids); state.addAttributeValue(rcapa, OAVBDIRuntimeModel.capability_has_outbox, rmessageevent); // Hack!!! Only needed for external access! BDIInterpreter.getInterpreter(state).getAgentAdapter().wakeup(); return ret; }
/** * Create a new capability flyweight. * @param state The state. * @param scope The scope handle. * @param adapter The adapter. */ public ExternalAccessFlyweight(IOAVState state, Object scope) { super(state, scope, scope); this.provider = getInterpreter().getServiceProvider(); this.cid = getInterpreter().getAgentAdapter().getComponentIdentifier(); this.parent = getInterpreter().getParent().getComponentIdentifier(); }
public void execute(IOAVState state, IVariableAssignments assignments) { Object mcond = assignments.getVariableValue("?mcondition"); Object rcapa = assignments.getVariableValue("?rcapa"); Object rplan = assignments.getVariableValue("?rplan"); // System.out.println("WFC: Setting plan to ready: "+rplan); // todo: Should be a rule triggered event with variable values EventProcessingRules.schedulePlanInstanceCandidate(state, mcond, rplan, rcapa); // // state.setAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_processingstate, // OAVBDIRuntimeModel.PLANPROCESSINGTATE_READY); // // PlanRules.cleanupPlanWait(state, rcapa, rplan, false); // // todo: provide activation resp. variable bindings // state.setAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_dispatchedelement, null); BDIInterpreter.getInterpreter(state).getAgentAdapter().wakeup(); } };
public void run() { Object exp = state.getAttributeValue(mparamset, OAVBDIMetaModel.parameterset_has_valuesexpression); try { Object values = AgentRules.evaluateExpression(state, exp, fet); BeliefRules.updateBeliefSet(state, rparamset, values, rcapa); } catch(Exception e) { String name = BDIInterpreter.getInterpreter(state).getAgentAdapter().getComponentIdentifier().getName(); BDIInterpreter.getInterpreter(state).getLogger(rcapa).severe("Could not evaluate parameterset expression: "+name+" "+state.getAttributeValue(exp, OAVBDIMetaModel.expression_has_parsed)); } // changed *.class to *.TYPE due to javaflow bug state.setAttributeValue(rparamset, OAVBDIRuntimeModel.typedelement_has_timer, BDIInterpreter.getInterpreter(state).getClockService().createTimer(update.longValue(), to[0])); } });
public void run() { Object exp = state.getAttributeValue(mparam, OAVBDIMetaModel.parameter_has_value); try { Object value = AgentRules.evaluateExpression(state, exp, fet); BeliefRules.setParameterValue(state, rparam, value); } catch(Exception e) { String name = BDIInterpreter.getInterpreter(state).getAgentAdapter().getComponentIdentifier().getName(); BDIInterpreter.getInterpreter(state).getLogger(rcapa).severe("Could not evaluate parameter expression: "+name +" "+state.getAttributeValue(exp, OAVBDIMetaModel.expression_has_parsed)); } // // changed *.class to *.TYPE due to javaflow bug state.setAttributeValue(rparam, OAVBDIRuntimeModel.typedelement_has_timer, BDIInterpreter.getInterpreter(state).getClockService().createTimer(update.longValue(), to[0])); }