/** * Get a feature of the component. * @param feature The type of the feature. * @return The feature instance. */ public <T> T getComponentFeature0(Class<? extends T> type) { return access.getComponentFeature0(type); }
/** * Get the current state as events. */ public List<IMonitoringEvent> getCurrentStateEvents() { List<IMonitoringEvent> ret = null; IExecutionFeature exef = getComponent().getComponentFeature0(IExecutionFeature.class); if(exef instanceof ExecutionComponentFeature) ret = ((ExecutionComponentFeature)exef).getCurrentStateEvents(); return ret; } }
@Override public void handleTerminated(Exception reason) { // System.out.println("terminated call: "+fgoal); IBDIAgentFeature bf = agent.getComponentFeature0(IBDIAgentFeature.class); if(bf!=null) { bf.dropGoal(fgoal); } else { ((IGoal)fgoal).drop(); } // ((IBDIAgentFeature)bdif).dropGoal(fgoal); } };
public void intermediateResultAvailable(IExampleService result) { System.out.println("received: "+result+" "+cms.getRootIdentifier().get()+" "+((IService)result).getServiceIdentifier().getProviderId().getRoot()); System.out.println("thread: " + IComponentIdentifier.LOCAL.get() +" on comp thread: " + agent.getComponentFeature0(IExecutionFeature.class).isComponentThread()); if(cms.getRootIdentifier().get().equals(((IService)result).getServiceIdentifier().getProviderId().getRoot())) { num++; } else { System.out.println("Found service that does not come from target platform: "+result); } }
/** * Remove all facts from a belief. */ public void removeFacts() { internalGetValues().clear(); // Push to result, if any. String result = ((BDIXModel)getAgent().getModel()).getCapability().getResultMappings().get(getName()); if(result!=null && getAgent().getComponentFeature0(IArgumentsResultsFeature.class)!=null) { getAgent().getComponentFeature(IArgumentsResultsFeature.class) .getResults().put(result, internalGetValues()); } }
/** * Remove a fact to a belief. * @param fact The new fact. */ public void removeFact(Object fact) { internalGetValues().remove(fact); // Push to result, if any. String result = ((BDIXModel)getAgent().getModel()).getCapability().getResultMappings().get(getName()); if(result!=null && getAgent().getComponentFeature0(IArgumentsResultsFeature.class)!=null) { getAgent().getComponentFeature(IArgumentsResultsFeature.class) .getResults().put(result, internalGetValues()); } }
final IMonitoringComponentFeature mon = getComponent().getComponentFeature0(IMonitoringComponentFeature.class); if(mon!=null)
/** * Remove a belief listener. * @param name The belief name. * @param listener The belief listener. */ public <T> void removeBeliefListener(String name, IBeliefListener<T> listener) { name = capa!=null ? capa+MElement.CAPABILITY_SEPARATOR+name: name; IBDIAgentFeature bdif = agent.getComponentFeature0(IBDIAgentFeature.class); if(bdif!=null) { bdif.removeBeliefListener(capa!=null ? capa+MElement.CAPABILITY_SEPARATOR+name : name, listener); } else { IBDIXAgentFeature bdixf = agent.getComponentFeature0(IBDIXAgentFeature.class); if(bdixf.getBeliefbase().containsBelief(name)) { bdixf.getBeliefbase().getBelief(name).removeBeliefListener(listener); } else { bdixf.getBeliefbase().getBeliefSet(name).removeBeliefSetListener(listener); } } }
/** * Add a belief listener. * @param name The belief name. * @param listener The belief listener. */ public <T> void addBeliefListener(String name, final IBeliefListener<T> listener) { name = capa!=null ? capa+MElement.CAPABILITY_SEPARATOR+name: name; IBDIAgentFeature bdif = agent.getComponentFeature0(IBDIAgentFeature.class); if(bdif!=null) { bdif.addBeliefListener(name, listener); } else { IBDIXAgentFeature bdixf = agent.getComponentFeature0(IBDIXAgentFeature.class); if(bdixf.getBeliefbase().containsBelief(name)) { bdixf.getBeliefbase().getBelief(name).addBeliefListener(listener); } else { bdixf.getBeliefbase().getBeliefSet(name).addBeliefSetListener(listener); } } }
IExecutionFeature exef = getComponent().getComponentFeature0(IExecutionFeature.class); if(exef instanceof ExecutionComponentFeature)
public void customResultAvailable(Object result) { if(step.getPriority()<STEP_PRIORITY_IMMEDIATE && getComponent().getComponentFeature0(IMonitoringComponentFeature.class)!=null && getComponent().getComponentFeature(IMonitoringComponentFeature.class).hasEventTargets(PublishTarget.TOALL, PublishEventLevel.FINE)) { getComponent().getComponentFeature(IMonitoringComponentFeature.class).publishEvent(new MonitoringEvent(getComponent().getComponentIdentifier(), getComponent().getComponentDescription().getCreationTime(), step.getStep().toString(), IMonitoringEvent.EVENT_TYPE_DISPOSAL+"." +IMonitoringEvent.SOURCE_CATEGORY_EXECUTION, null, System.currentTimeMillis(), PublishEventLevel.FINE), PublishTarget.TOALL); // null was step.getCause() } super.customResultAvailable(result); } });
/** * Add a fact to a belief. * @param fact The new fact. */ public void addFact(Object fact) { if(fact!=null) { Class<?> clazz = ((MBelief)getModelElement()).getClazz().getType(getAgent().getClassLoader(), getAgent().getModel().getAllImports()); if(!SReflect.isSupertype(clazz, fact.getClass())) { throw new IllegalArgumentException("Incompatible value for belief set "+getName()+": "+fact); } fact = SReflect.convertWrappedValue(fact, clazz); } internalGetValues().add(fact); // Push to result, if any. String result = ((BDIXModel)getAgent().getModel()).getCapability().getResultMappings().get(getName()); if(result!=null && getAgent().getComponentFeature0(IArgumentsResultsFeature.class)!=null) { getAgent().getComponentFeature(IArgumentsResultsFeature.class) .getResults().put(result, internalGetValues()); } }
/** * Publish a step event. */ public void publishStepEvent(StepInfo step, String type) { if(step.getPriority()<IExecutionFeature.STEP_PRIORITY_IMMEDIATE && getComponent().getComponentFeature0(IMonitoringComponentFeature.class)!=null && getComponent().getComponentFeature(IMonitoringComponentFeature.class).hasEventTargets(PublishTarget.TOALL, PublishEventLevel.FINE)) { MonitoringEvent event = new MonitoringEvent(getComponent().getComponentIdentifier(), getComponent().getComponentDescription().getCreationTime(), step.getStep().toString(), type+"."+TYPE_STEP, null, System.currentTimeMillis(), PublishEventLevel.FINE); // null was step.getCause() event.setProperty("sourcename", SReflect.getUnqualifiedClassName(step.getStep().getClass())); event.setProperty("details", getStepDetails(step)); event.setProperty("id", step.getStepCount()); getComponent().getComponentFeature(IMonitoringComponentFeature.class).publishEvent(event, PublishTarget.TOALL); } }
/** * Init the non-functional properties (todo: move to other location?) */ protected IFuture<Void> initNFProperties() { if(getInternalAccess().getComponentFeature0(INFPropertyComponentFeature.class)!=null) { INFPropertyComponentFeature nfcf = getInternalAccess().getComponentFeature(INFPropertyComponentFeature.class); IProvidedServicesFeature psf = getInternalAccess().getComponentFeature(IProvidedServicesFeature.class); IInternalService ser = (IInternalService)getInternalAccess().getComponentFeature(IProvidedServicesFeature.class).getProvidedService(type); Class<?> impltype = psf.getProvidedServiceRawImpl(ser.getServiceIdentifier())!=null? psf.getProvidedServiceRawImpl(ser.getServiceIdentifier()).getClass(): null; // todo: make internal interface for initProperties return ((NFPropertyComponentFeature)nfcf).initNFProperties(ser, impltype); } else { return IFuture.DONE; } }
if(result!=null && getAgent().getComponentFeature0(IArgumentsResultsFeature.class)!=null)
/** * */ public static void publishToolBeliefEvent(IInternalAccess ia, MBelief mbel)//, String evtype) { if(mbel!=null && ia.getComponentFeature0(IMonitoringComponentFeature.class)!=null && ia.getComponentFeature(IMonitoringComponentFeature.class).hasEventTargets(PublishTarget.TOSUBSCRIBERS, PublishEventLevel.FINE)) { long time = System.currentTimeMillis();//getClockService().getTime(); MonitoringEvent mev = new MonitoringEvent(); mev.setSourceIdentifier(ia.getComponentIdentifier()); mev.setTime(time); BeliefInfo info = BeliefInfo.createBeliefInfo(ia, mbel, ia.getClassLoader()); // mev.setType(evtype+"."+IMonitoringEvent.SOURCE_CATEGORY_FACT); mev.setType(IMonitoringEvent.EVENT_TYPE_MODIFICATION+"."+IMonitoringEvent.SOURCE_CATEGORY_FACT); // mev.setProperty("sourcename", element.toString()); mev.setProperty("sourcetype", info.getType()); mev.setProperty("details", info); mev.setLevel(PublishEventLevel.FINE); ia.getComponentFeature(IMonitoringComponentFeature.class).publishEvent(mev, PublishTarget.TOSUBSCRIBERS); } }
/** * */ public static void publishToolBeliefEvent(IInternalAccess ia, MBelief mbel)//, String evtype) { if(mbel!=null && ia.getComponentFeature0(IMonitoringComponentFeature.class)!=null && ia.getComponentFeature(IMonitoringComponentFeature.class).hasEventTargets(PublishTarget.TOSUBSCRIBERS, PublishEventLevel.FINE)) { long time = System.currentTimeMillis();//getClockService().getTime(); MonitoringEvent mev = new MonitoringEvent(); mev.setSourceIdentifier(ia.getComponentIdentifier()); mev.setTime(time); BeliefInfo info = BeliefInfo.createBeliefInfo(ia, mbel, ia.getClassLoader()); // mev.setType(evtype+"."+IMonitoringEvent.SOURCE_CATEGORY_FACT); mev.setType(IMonitoringEvent.EVENT_TYPE_MODIFICATION+"."+IMonitoringEvent.SOURCE_CATEGORY_FACT); // mev.setProperty("sourcename", element.toString()); mev.setProperty("sourcetype", info.getType()); mev.setProperty("details", info); mev.setLevel(PublishEventLevel.FINE); ia.getComponentFeature(IMonitoringComponentFeature.class).publishEvent(mev, PublishTarget.TOSUBSCRIBERS); } }
/** * Indicate that the fact of this belief was modified. * Calling this method causes an internal fact changed * event that might cause dependent actions. */ public void modified(Object fact) { if(fact!=null) { facts.entryChanged(fact, fact, facts.indexOf(fact)); } else { RuleSystem rs = ((IInternalBDIAgentFeature)getAgent().getComponentFeature(IBDIXAgentFeature.class)).getRuleSystem(); rs.addEvent(new Event(ChangeEvent.BELIEFCHANGED+"."+getName(), new ChangeInfo<Object>(facts, facts, null))); } // Push to result, if any. String result = ((BDIXModel)getAgent().getModel()).getCapability().getResultMappings().get(getName()); if(result!=null && getAgent().getComponentFeature0(IArgumentsResultsFeature.class)!=null) { getAgent().getComponentFeature(IArgumentsResultsFeature.class) .getResults().put(result, internalGetValues()); } }
/** * Publish a tool event. */ public void publishToolPlanEvent(String evtype) { if(getAgent().getComponentFeature0(IMonitoringComponentFeature.class)!=null && getAgent().getComponentFeature(IMonitoringComponentFeature.class).hasEventTargets(PublishTarget.TOSUBSCRIBERS, PublishEventLevel.FINE)) { long time = System.currentTimeMillis();//getClockService().getTime(); MonitoringEvent mev = new MonitoringEvent(); mev.setSourceIdentifier(getAgent().getComponentIdentifier()); mev.setTime(time); PlanInfo info = PlanInfo.createPlanInfo(this); mev.setType(evtype+"."+IMonitoringEvent.SOURCE_CATEGORY_PLAN); // mev.setProperty("sourcename", element.toString()); mev.setProperty("sourcetype", info.getType()); mev.setProperty("details", info); mev.setLevel(PublishEventLevel.FINE); getAgent().getComponentFeature(IMonitoringComponentFeature.class).publishEvent(mev, PublishTarget.TOSUBSCRIBERS); } }
/** * */ public void publishToolGoalEvent(String evtype) { if(getAgent().getComponentFeature0(IMonitoringComponentFeature.class)!=null && getAgent().getComponentFeature(IMonitoringComponentFeature.class).hasEventTargets(PublishTarget.TOSUBSCRIBERS, PublishEventLevel.FINE)) { long time = System.currentTimeMillis();//getClockService().getTime(); MonitoringEvent mev = new MonitoringEvent(); mev.setSourceIdentifier(getAgent().getComponentIdentifier()); mev.setTime(time); GoalInfo info = GoalInfo.createGoalInfo(this); mev.setType(evtype+"."+IMonitoringEvent.SOURCE_CATEGORY_GOAL); // mev.setProperty("sourcename", element.toString()); mev.setProperty("sourcetype", info.getType()); mev.setProperty("details", info); mev.setLevel(PublishEventLevel.FINE); getAgent().getComponentFeature(IMonitoringComponentFeature.class).publishEvent(mev, PublishTarget.TOSUBSCRIBERS); } }