/** method that is called by the event handler whenever the mind initiates a new action */ protected synchronized void receiveActionFromMind(MindAction a) { // create a new entry in the rulesAlreadyTried map ArrayList<CompetencyManagerRule> rulesForThisAction = new ArrayList<CompetencyManagerRule>(); // find a suitable rule CompetencyManagerRule rule = findMatch(a, rulesForThisAction); // check if we have found a rule if (rule != null) { // remember that we tried this rule for this action rulesForThisAction.add(rule); rulesAlreadyTried.put(a, rulesForThisAction); // get an instantiated copy of the plan associated with the rule CompetencyExecutionPlan plan = rule.getExecutionPlan().getInstantiatedCopy(a.getMappings(), a); // and also remember that this execution plan belongs to this action plansCurrentlyExecuted.put(plan, a); // schedule a new request with comeptency execution component architecture.getCompetencyExecution().schedule(new RequestNewCompetencyExecutionPlan(plan)); } else { // we could not find any execution plan, raise an event that the mind action has failed this.raise(new EventMindActionFailed(a)); } }
/** handles unsuccessful competency execution plans */ private synchronized void processPlanFailure(CompetencyExecutionPlan plan) { // check if this is one of the plans currently executed if (plansCurrentlyExecuted.containsKey(plan)) { // obtain the mind action belonging to this execution plan MindAction ma = plansCurrentlyExecuted.get(plan); // remove this plan from our memory plansCurrentlyExecuted.remove(plan); // see if we can find another rule CompetencyManagerRule rule = findMatch(ma, rulesAlreadyTried.get(ma)); // check if we have found a rule if (rule != null) { // remember that we tried this rule for this action rulesAlreadyTried.get(ma).add(rule); // get an instantiated copy of the plan associated with the rule CompetencyExecutionPlan newPlan = rule.getExecutionPlan().getInstantiatedCopy(ma.getMappings(), ma); // and also remember that this execution plan belongs to this action plansCurrentlyExecuted.put(newPlan, ma); // schedule a new request with competency execution component architecture .getCompetencyExecution() .schedule(new RequestNewCompetencyExecutionPlan(newPlan)); } else // we could not find any other plans { // remove what's left of this action from our memory rulesAlreadyTried.remove(ma); // raise an event that the mind action has failed this.raise(new EventMindActionFailed(ma)); } } else { // this was not one of the plans we are waiting for // this should not happen, so print out error System.err.println("CompetencyManager error: received plan failure for unknown plan"); System.err.println("plan steps: " + plan.getNoOfSteps()); for (CompetencyExecutionPlanStep step : plan.getPlanSteps()) System.err.println("step " + step.getCompetencyType()); } }
/** method that is called by the event handler whenever the mind initiates a new action */ protected synchronized void cancelActionFromMind(MindAction a) { // find plans currently executed as a realization of a for (CompetencyExecutionPlan plan : plansCurrentlyExecuted.keySet()) { // check if plan realizes a if ((a != null) && (a.equals(plansCurrentlyExecuted.get(plan)))) { // cancel plan architecture .getCompetencyExecution() .schedule(new RequestCancelCompetencyExecutionPlan(plan)); } } }