/** * Get the capability model. * @return The capability model. */ public MCapability getMCapability() { return (MCapability)getCapability().getModelElement(); }
/** * @param mplaninfo * @param element */ public CandidateInfoPojoPlan(Object pojo, RProcessableElement element, IInternalAccess agent) { this.pojo = pojo; this.element = element; this.agent = agent; MCapability mcapa = (MCapability)agent.getComponentFeature(IInternalBDIAgentFeature.class).getCapability().getModelElement(); this.mplan = mcapa.getPlan(pojo.getClass().getName()); }
/** * Get the mcapa. */ public static MCapability getMCapability(IInternalAccess agent) { return ((MCapability)agent.getComponentFeature(IInternalBDIAgentFeature.class).getCapability().getModelElement()); }
/** * Get all plans of a specified type (=model element name). * @param type The plan type. * @return All plans of the specified type. */ public IPlan[] getPlans(String type) { // Todo: add capability scope type = type.replace(".", MElement.CAPABILITY_SEPARATOR); MCapability mcapa = (MCapability)getCapability().getModelElement(); MPlan mplan = mcapa.getPlan(type); Collection<RPlan> ret = getCapability().getPlans(mplan); return ret.toArray(new IPlan[ret.size()]); }
/** * Get a predefined expression. * Creates a new instance on every call. * @param name The name of an expression defined in the ADF. * @return The expression object. */ public IExpression getExpression(String name) { // Todo: add capability scope name = name.replace(".", MElement.CAPABILITY_SEPARATOR); if(expressions==null || !expressions.containsKey(name)) { RCapability rcapa = agent.getComponentFeature(IInternalBDIAgentFeature.class).getCapability(); MCapability mcapa = (MCapability)rcapa.getModelElement(); UnparsedExpression uexp = mcapa.getExpression(name); if(uexp==null) throw new RuntimeException("Unknown expression: "+name); RExpression rexp = new RExpression(uexp, getAgent()); expressions = new HashMap<String, IExpression>(); expressions.put(name, rexp); } return expressions.get(name); }
/** * Create belief events from a belief name. * For normal beliefs * beliefchanged.belname and factchanged.belname * and for multi beliefs additionally * factadded.belname and factremoved * are created. */ public static void addBeliefEvents(IInternalAccess ia, List<EventType> events, String belname) { addBeliefEvents((MCapability)ia.getComponentFeature(IInternalBDIAgentFeature.class) .getCapability().getModelElement(), events, belname, ia.getClassLoader()); }
/** * Create belief events from a belief name. * For normal beliefs * beliefchanged.belname and factchanged.belname * and for multi beliefs additionally * factadded.belname and factremoved * are created. */ public static void addBeliefEvents(IInternalAccess ia, List<EventType> events, String belname) { events.add(new EventType(new String[]{ChangeEvent.BELIEFCHANGED, belname})); // the whole value was changed events.add(new EventType(new String[]{ChangeEvent.FACTCHANGED, belname})); // property change of a value // BDIAgentInterpreter ip = (BDIAgentInterpreter)((BDIAgent)ia).getInterpreter(); MBelief mbel = ((MCapability)((IInternalBDIAgentFeature)ia.getComponentFeature(IBDIXAgentFeature.class)).getCapability().getModelElement()).getBelief(belname); if(mbel!=null && mbel.isMulti(null)) { events.add(new EventType(new String[]{ChangeEvent.FACTADDED, belname})); events.add(new EventType(new String[]{ChangeEvent.FACTREMOVED, belname})); } }
MCapability mcapa = (MCapability)ip.getCapability().getModelElement(); final MGoal mgoal = mcapa.getGoal(goalname);
/** * Dispatch a goal wait for its result. */ public <T, E> IFuture<E> dispatchTopLevelGoal(final T goal) { final Future<E> ret = new Future<E>(); final MGoal mgoal = ((MCapability)capa.getModelElement()).getGoal(goal.getClass().getName()); if(mgoal==null) throw new RuntimeException("Unknown goal type: "+goal); final RGoal rgoal = new RGoal(getInternalAccess(), mgoal, goal, null); rgoal.addListener(new ExceptionDelegationResultListener<Void, E>(ret) { public void customResultAvailable(Void result) { Object res = RGoal.getGoalResult(goal, mgoal, bdimodel.getClassloader()); ret.setResult((E)res); } }); // System.out.println("adopt goal"); RGoal.adoptGoal(rgoal, getInternalAccess()); return ret; }
/** * Create belief events from a belief name. * For normal beliefs * beliefchanged.belname and factchanged.belname * and for multi beliefs additionally * factadded.belname and factremoved * are created. */ public static void addBeliefEvents(IInternalAccess ia, List<EventType> events, String belname) { events.add(new EventType(new String[]{ChangeEvent.BELIEFCHANGED, belname})); // the whole value was changed events.add(new EventType(new String[]{ChangeEvent.FACTCHANGED, belname})); // property change of a value BDIAgentInterpreter ip = (BDIAgentInterpreter)((BDIAgent)ia).getInterpreter(); MBelief mbel = ((MCapability)ip.getCapability().getModelElement()).getBelief(belname); if(mbel!=null && mbel.isMulti(ia.getClassLoader())) { events.add(new EventType(new String[]{ChangeEvent.FACTADDED, belname})); events.add(new EventType(new String[]{ChangeEvent.FACTREMOVED, belname})); } }
/** * Dispatch a pojo goal wait for its result. * @param goal The pojo goal. * @return The goal result. */ public <T, E> IFuture<E> dispatchTopLevelGoal(final T goal) { final Future<E> ret = new Future<E>(); final MGoal mgoal = ((MCapability)capa.getModelElement()).getGoal(goal.getClass().getName()); if(mgoal==null) throw new RuntimeException("Unknown goal type: "+goal); final RGoal rgoal = new RGoal(getComponent(), mgoal, goal, null, null, null, null); rgoal.addListener(new ExceptionDelegationResultListener<Void, E>(ret) { public void customResultAvailable(Void result) { Object res = RGoal.getGoalResult(rgoal, bdimodel.getClassloader()); ret.setResult((E)res); } }); // System.out.println("adopt goal"); RGoal.adoptGoal(rgoal, getComponent()); return ret; }
/** * */ public static void performInitWrites(BDIAgent agent) { synchronized(initwrites) { List<Object[]> writes = initwrites.remove(agent); if(writes!=null) { for(Object[] write: writes) { // System.out.println("initwrite: "+write[0]+" "+write[1]+" "+write[2]); // agent.writeField(write[0], (String)write[1], write[2]); BDIAgentInterpreter ip = (BDIAgentInterpreter)agent.getInterpreter(); RuleSystem rs = ip.getRuleSystem(); final String belname = (String)write[1]; Object val = write[0]; rs.addEvent(new Event(ChangeEvent.BELIEFCHANGED+"."+belname, val)); MBelief mbel = ((MCapability)ip.getCapability().getModelElement()).getBelief(belname); observeValue(rs, val, (BDIAgentInterpreter)agent.getInterpreter(), ChangeEvent.FACTCHANGED+"."+belname, mbel); } } } }
MCapability mcapa = (MCapability)ip.getCapability().getModelElement();
addBeliefEvents(getComponent(), events, fname); final boolean multi = ((MCapability)getCapability().getModelElement()) .getBelief(fname).isMulti(bdimodel.getClassloader());
addBeliefEvents(getComponent(), events, fname); final boolean multi = ((MCapability)getCapability().getModelElement()) .getBelief(fname).isMulti(((ModelInfo)bdimodel).getClassLoader());
BDIAgentInterpreter.addBeliefEvents(this, events, fname); final boolean multi = ((MCapability)((BDIAgentInterpreter)getInterpreter()).getCapability().getModelElement()) .getBelief(fname).isMulti(getClassLoader());
public void execute(IInternalAccess agent) { RuleSystem rs = agent.getComponentFeature(IInternalBDIAgentFeature.class).getRuleSystem(); EventType etype = new EventType(ChangeEvent.BELIEFCHANGED+"."+name); unobserveObject(agent, oldval, etype, rs); rs.addEvent(new jadex.rules.eca.Event(etype, new ChangeInfo<Object>(val, null, null))); MBelief mbel = ((MCapability)agent.getComponentFeature(IInternalBDIAgentFeature.class).getCapability().getModelElement()).getBelief(name); observeValue(rs, val, agent, ChangeEvent.FACTCHANGED+"."+name, mbel); } }
MBelief mbel = ((MCapability)ip.getCapability().getModelElement()).getBelief(belname);
MBelief mbel = ((MCapability)getComponent().getComponentFeature(IInternalBDIAgentFeature.class).getCapability().getModelElement()).getBelief(belname);
MCapability mcapa = (MCapability)bdif.getCapability().getModelElement();