/** * Create a new fetcher. */ public OAVBDIFetcher(IOAVState state, Object rcapa) { this.state = state; this.adapter = BDIInterpreter.getInterpreter(state).getAgentAdapter(); this.rcapa = rcapa; }
if(microplansteps && getRuleSystem().isInited()) if(monitor_consequences==0 && !isAtomic()) if(agenda_state!=getRuleSystem().getAgenda().getState()) Object rplan = getCurrentPlan(); if(rplan!=null) getPlanExecutor(rplan).interruptPlanStep(rplan);
public void run() { getInterpreter().addNFProperty(nfprop); ret.setResult(null); } });
/** * Extended init procedure including subcapabilities. */ public IFuture init(IModelInfo model,String config) { // assert isAgentThread(); assert !getAgentAdapter().isExternalThread(); return initCapability(this.model, config); }
public IFuture<Void> execute(IInternalAccess ia) { getter = new ServiceGetter<IMonitoringService>(getInternalAccess(), IMonitoringService.class, RequiredServiceInfo.SCOPE_PLATFORM); init(getModel(), config).addResultListener(createResultListener(new DelegationResultListener(inited))); return IFuture.DONE; } });
BDIInterpreter ip = BDIInterpreter.getInterpreter(state); ip.setCurrentPlan(rplan); try interrupted = ip.getPlanExecutor(rplan).executeFailedStep(ip, rplan); // Hack BDIInterpreter.getInterpreter(state).getLogger(rcapa).severe(ip.getAgentAdapter().getComponentIdentifier()+ ": Exception while executing: "+rplan+"\n"+sw); BDIInterpreter.getInterpreter(state).getLogger(rcapa).info(ip.getAgentAdapter().getComponentIdentifier()+ ": Exception while executing: "+rplan+"\n"+sw); ip.setCurrentPlan(null);
if(getInterpreter().getComponentAdapter().isExternalThread()) getInterpreter().getAgentAdapter().invokeLater(new Runnable() Object cs = getState().getAttributeValue(getInterpreter().getAgent(), OAVBDIRuntimeModel.agent_has_state); if(OAVBDIRuntimeModel.AGENTLIFECYCLESTATE_ALIVE.equals(cs)) getInterpreter().startMonitorConsequences(); getInterpreter().killComponent().addResultListener(new DelegationResultListener(ret)); getInterpreter().endMonitorConsequences();
protected void fireComponentChangeEvent(IOAVState state, Object element, Object scope, String type, Object value) BDIInterpreter bdiint = BDIInterpreter.getInterpreter(state); if(bdiint.hasEventTargets(PublishTarget.TOALL, PublishEventLevel.FINE)) long time = bdiint.getClockService().getTime(); event.setSourceIdentifier(bdiint.getAgentAdapter().getComponentIdentifier()); if(scope == null) scope = bdiint.getAgent(); bdiint.publishEvent(event, PublishTarget.TOALL);
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() { // 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(); // } } })));
public void invokeLater(Runnable action) { getAgentAdapter().invokeLater(action); } });
assert !getAgentAdapter().isExternalThread(); if(model==getModel()) init0().addResultListener(createResultListener(new DelegationResultListener(fut)
final SubscriptionIntermediateFuture<IMonitoringEvent> ret = (SubscriptionIntermediateFuture<IMonitoringEvent>)SFuture.getNoTimeoutFuture(SubscriptionIntermediateFuture.class, getInternalAccess()); MonitoringEvent subscribed = new MonitoringEvent(getComponentIdentifier(), getComponentDescription().getCreationTime(), IMonitoringEvent.TYPE_SUBSCRIPTION_START, System.currentTimeMillis(), PublishEventLevel.COARSE); boolean post = false; addSubscription(ret, filter, emitlevel); List<IMonitoringEvent> evs = getCurrentStateEvents(); if(evs!=null && evs.size()>0)
final Future ret = step instanceof IComponentStep<?> ? createStepFuture((IComponentStep)step) : new Future<T>(); if(getComponentAdapter().isExternalThread() || getState().getAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_state)==null) if(getState().containsObject(ragent)) getState().addAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_actions, new Object[]{step, ret, scope!=null ? scope : ragent}); ret.setException(new ComponentTerminatedException(getAgentAdapter().getComponentIdentifier()));
BDIInterpreter interpreter = BDIInterpreter.getInterpreter(state); IArgument[] results = interpreter.getModel().getResults(); for(int i=0; i<results.length; i++) interpreter.setResultValue(results[i].getName(), resultvals.get(results[i].getName())); interpreter.cleanup(); ((Future)((Object[])action)[1]).setException(new ComponentTerminatedException(interpreter.getComponentIdentifier()));
if(hasEventTargets(PublishTarget.TOALL, PublishEventLevel.FINE)) publishEvent(new MonitoringEvent(getComponentIdentifier(), getComponentDescription().getCreationTime(), IMonitoringEvent.EVENT_TYPE_CREATION+"."+IMonitoringEvent.SOURCE_CATEGORY_EXECUTION, System.currentTimeMillis(), PublishEventLevel.FINE), PublishTarget.TOALL); state.getProfiler().stop(IProfiler.TYPE_RULE, act!=null?act.getRule():null); if(hasEventTargets(PublishTarget.TOALL, PublishEventLevel.FINE)) publishEvent(new MonitoringEvent(getComponentIdentifier(), getComponentDescription().getCreationTime(), IMonitoringEvent.EVENT_TYPE_DISPOSAL+"."+IMonitoringEvent.SOURCE_CATEGORY_EXECUTION, System.currentTimeMillis(), PublishEventLevel.FINE), PublishTarget.TOALL); cleanup(); if(e instanceof RuntimeException) throw (RuntimeException)e;
/** * Create a component instance. * @param adapter The component adapter. * @param model The component model. * @param config The name of the configuration (or null for default configuration) * @param arguments The arguments for the agent as name/value pairs. * @param parent The parent component (if any). * @return An instance of a component. */ public Tuple2<IComponentInstance, IComponentAdapter> createComponentInstance(IComponentDescription desc, IComponentAdapterFactory factory, OAVAgentModel amodel, String config, Map<String, Object> arguments, IExternalAccess parent, RequiredServiceBinding[] bindings, boolean copy, boolean realtime, IIntermediateResultListener<Tuple2<String, Object>> resultlistener, Future<Void> ret) { // Create type model for agent instance (e.g. holding dynamically loaded java classes). OAVTypeModel tmodel = new OAVTypeModel(desc.getName().getLocalName()+"_typemodel", amodel.getState().getTypeModel().getClassLoader()); // OAVTypeModel tmodel = new OAVTypeModel(model.getName()+"_typemodel", ((OAVAgentModel)model).getTypeModel().getClassLoader()); tmodel.addTypeModel(amodel.getState().getTypeModel()); tmodel.addTypeModel(OAVBDIRuntimeModel.bdi_rt_model); IOAVState state = OAVStateFactory.createOAVState(tmodel); state.addSubstate(amodel.getState()); // BDIInterpreter bdii = new BDIInterpreter(desc, factory, state, amodel, config, arguments, parent, bindings, getPropertyMap(), copy, realtime, resultlistener, ret); BDIInterpreter bdii = new BDIInterpreter(desc, factory, state, amodel, config, arguments, parent, bindings, myprops, copy, realtime, resultlistener, ret); return new Tuple2<IComponentInstance, IComponentAdapter>(bdii, bdii.getAgentAdapter()); }
/** * 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(); }
/** * Test if the component's execution is currently at one of the * given breakpoints. If yes, the component will be suspended by * the platform. * @param breakpoints An array of breakpoints. * @return True, when some breakpoint is triggered. */ public boolean isAtBreakpoint(String[] breakpoints) { // assert isAgentThread(); assert !getAgentAdapter().isExternalThread(); boolean isatbreakpoint = false; Object cs = state.getAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_state); if(cs!=null && !OAVBDIRuntimeModel.AGENTLIFECYCLESTATE_TERMINATED.equals(cs)) { Set bps = new HashSet(Arrays.asList(breakpoints)); // Todo: cache set across invocations for speed? Iterator it = getRuleSystem().getAgenda().getActivations().iterator(); while(!isatbreakpoint && it.hasNext()) { IRule rule = ((Activation)it.next()).getRule(); isatbreakpoint = bps.contains(rule.getName()); } } // else still in init return isatbreakpoint; }
if(getComponentAdapter().isExternalThread()) getAgentAdapter().invokeLater(new Runnable() if(BDIInterpreter.getInterpreter(state)!=null) getAgentAdapter().getLogger().warning("Executing synchronized code (might lead to deadlocks): "+code); exception.wait(); throw new ComponentTerminatedException(getAgentAdapter().getComponentIdentifier());