/** * Allocate fire brigades to disasters for extinguishing fires. */ @Plan public class HandleFireBrigadesExtinguishFiresPlan extends HandleForcesPlan { /** * The body method is called on the * instantiated plan instance from the scheduler. */ @PlanBody public void body() { allocateForces("extinguishfireservices", "fire"); } }
/** * */ protected MPlan createMPlan(BDIModel bdimodel, Plan p, MethodInfo mi, String name, ClassInfo ci, ClassLoader cl, Map<ClassInfo, List<Tuple2<MGoal, String>>> pubs) { Body body = p.body(); ServicePlan sp = body.service(); MPlan mplan = bdimodel.getCapability().getPlan(name); if(mplan==null) { MTrigger mtr = buildPlanTrigger(bdimodel, p.trigger(), cl, pubs); MTrigger wmtr = buildPlanTrigger(bdimodel, p.waitqueue(), cl, pubs); if(ci==null) ci = Object.class.equals(body.value())? null: new ClassInfo(body.value().getName()); // Class<? extends IServiceParameterMapper<Object>> mapperclass = (Class<? extends IServiceParameterMapper<Object>>)(IServiceParameterMapper.class.equals(sp.mapper())? null: sp.mapper()); Class<? extends IServiceParameterMapper<Object>> mapperclass = (Class<? extends IServiceParameterMapper<Object>>)(IServiceParameterMapper.class.getName().equals(sp.mapper().getName())? null: sp.mapper()); MBody mbody = new MBody(mi, ci, sp.name().length()==0? null: sp.name(), sp.method().length()==0? null: sp.method(), mapperclass==null? null: new ClassInfo(mapperclass), body.component().length()==0 ? null : body.component()); mplan = new MPlan(name, mbody, mtr, wmtr, p.priority()); } return mplan; }
Body body = p.body(); ServicePlan sp = body.service(); String component = body.component();
ClassInfo ci, ClassLoader cl, Map<ClassInfo, List<Tuple2<MGoal, String>>> pubs) Body body = p.body(); ServicePlan sp = body.service(); MTrigger mtr = buildPlanTrigger(bdimodel, p.trigger(), cl, pubs); MTrigger wmtr = buildPlanTrigger(bdimodel, p.waitqueue(), cl, pubs); mtr = buildPlanTrigger(bdimodel, pl.trigger(), cl, pubs); wmtr = buildPlanTrigger(bdimodel, pl.waitqueue(), cl, pubs); MBody mbody = new MBody(mi, ci, sp.name().length()==0? null: sp.name(), sp.method().length()==0? null: sp.method(), mapperclass==null? null: new ClassInfo(mapperclass), body.component().length()==0 ? null : body.component()); mplan = new MPlan(name, mbody, mtr, wmtr, p.priority());
Body body = p.body(); ServicePlan sp = body.service(); String component = body.component();
/** * Allocate ambulances to disasters for treating victims. */ @Plan public class HandleAmbulancesPlan extends HandleForcesPlan { /** * The body method is called on the * instantiated plan instance from the scheduler. */ @PlanBody public void body() { allocateForces("treatvictimservices", "victims"); } }
/** * Allocate fire brigades to disasters for clearing chemicals. */ @Plan public class HandleFireBrigadesClearChemicalsPlan extends HandleForcesPlan { /** * The body method is called on the * instantiated plan instance from the scheduler. */ @PlanBody public void body() { allocateForces("clearchemicalsservices", "chemicals"); } }
/** * Translate an English word to German. */ @Plan public String[] translateEnglishGerman() { String eword = "dog"; String gword = wordtable.get(eword); return new String[]{eword, gword}; } }
/** * Translate an English word to German. */ @Plan public void translateEnglishGerman() { String eword = "dog"; String gword = wordtable.get(eword); System.out.println("Translated: "+eword+" - "+gword); } }
/** * The plans responds to the goal being violated and shows a dialog, * that asks the user to move the mouse. */ @Plan(trigger=@Trigger(goals=InUpperLeftCorner.class)) void moveToCorner() { JOptionPane.showMessageDialog(null, "Please move the mouse to the upper left corner."); }
/** * Plan reacts to the automatically created * translation goal. * @param tg The translation goal. */ @Plan(trigger=@Trigger(goals=TranslationGoal.class)) public String translatePlan(String eword) { return wordtable.get(eword); }
/** * Inline plan method that reacts on count goal. */ @Plan(trigger=@Trigger(goals=CountGoal.class)) protected IFuture<Void> inc(CountGoal goal) { counter++; System.out.println("counter is: "+counter); return IFuture.DONE; }
/** * Translate a word. */ @Plan(trigger=@Trigger(goals=Translate.class)) protected String translate(String eword) { return wordtable.get(eword); } }
@Plan protected void notify(IPlan plan) { System.out.println("notify using bean"); mybean.setAlive(true); }
/** * */ @Plan(trigger=@Trigger(goals=ExternalPlanBDI.MyGoal.class)) public class ExternalPlan { @PlanBody public void body() { System.out.println("body"); } }
/** * Plan that prints the time. */ @Plan(trigger=@Trigger(factchangeds="time")) protected void printTime() { System.out.println(formatter.format(time)); }
/** * Translate a word. Plan that translates. */ @Plan(trigger=@Trigger(goals=Translate.class)) protected String translateB(String eword) { System.out.println("Plan B"); return wordtable.get(eword); } }
/** * Plan that reacts on the goals. */ @Plan(trigger=@Trigger(goals={AGoal.class, BGoal.class})) public String plan() { return "result"; } }
@Plan(trigger=@Trigger(goals=SomeGoal.class)) protected void planC(SomeGoal goal) { System.out.println("Plan C"); goal.plans.add("C"); }
@Plan(trigger=@Trigger(goals=SomeGoal.class)) protected void planD(SomeGoal goal) { System.out.println("Plan D"); goal.plans.add("D"); }