Changeset 912


Ignore:
Timestamp:
02/02/2011 02:48:43 PM (8 years ago)
Author:
michael.kriegel
Message:

Cmion now supports the cancellation of ongoing execution plans. See documentation for details. Also contains some small changes to allow compatibility with new modular version of FAtiMA (again see documentation).

Location:
libs/cmion
Files:
8 added
13 edited

Legend:

Unmodified
Added
Removed
  • libs/cmion/cmionMain/src/cmion/level2/Competency.java

    r580 r912  
    3333import ion.Meta.Request; 
    3434import ion.Meta.RequestHandler; 
    35 import ion.Meta.Simulation; 
    3635import ion.Meta.TypeSet; 
    3736 
     
    106105         * @return the return value of this method should indicate, whether the competency  
    107106         * execution was a success (true) or failure (false) */  
    108         protected abstract boolean competencyCode(HashMap<String, String> parameters); 
     107        protected abstract boolean competencyCode(HashMap<String, String> parameters) throws CompetencyCancelledException; 
    109108         
    110109        /** custom competency initialisation code should go in here */ 
     
    116115        { 
    117116                // start competency code and when finished store the return value 
    118                 boolean succeeded = competencyCode(parameters); 
     117                boolean succeeded = false; 
     118                boolean cancelled = false; 
     119                try 
     120                { 
     121                        succeeded = competencyCode(parameters); 
     122                } 
     123                catch (CompetencyCancelledException e) 
     124                { 
     125                        cancelled = true; 
     126                } 
    119127                 
    120128                // competency code has executed, now that it has finished  
     
    122130                synchronized(this) 
    123131                {                        
    124                         if (succeeded)  
     132                        if (cancelled) 
     133                                this.raise(new EventCompetencyCancelled(this, parameters)); 
     134                        else if (succeeded)  
    125135                                this.raise(new EventCompetencySucceeded(this, parameters)); 
    126136                        else  
     
    168178                }                
    169179        } 
     180 
     181        /** Competencies can (and should) override this method to allow the execution 
     182         *  system to cancel them. When this method is called the competency should stop 
     183         *  its execution as quickly as possible by throwing a CompetencyCancelledException 
     184         *  in the comptencyCode method*/ 
     185        public void cancel() {} 
     186 
    170187         
    171188        /** registers request and event handlers of the competency execution system, 
     
    199216        public void setAdditionalData(Object data) 
    200217        {} 
     218 
    201219         
    202220} 
  • libs/cmion/cmionMain/src/cmion/level2/CompetencyExecution.java

    r248 r912  
    5252        private ArrayList<CompetencyExecutionPlan> currentPlans; 
    5353         
     54        /** store all plans that we are currently cancelling */ 
     55        private ArrayList<CompetencyExecutionPlan> plansToCancel; 
     56         
     57        /** store all competencies that we are currently running indexing the plan they belong to */ 
     58        private HashMap<Competency, CompetencyExecutionPlan> runningCompetencies; 
     59         
    5460        /** create a new Competency Execution Component */ 
    5561        public CompetencyExecution(IArchitecture architecture) 
     
    5763                super(architecture); 
    5864                currentPlans = new ArrayList<CompetencyExecutionPlan>(); 
     65                plansToCancel = new ArrayList<CompetencyExecutionPlan>(); 
     66                runningCompetencies = new HashMap<Competency, CompetencyExecutionPlan>(); 
    5967        } 
    6068         
     
    7684        } 
    7785 
     86        /** cancel the execution of a currently executing competency execution plan */ 
     87        private synchronized void cancelPlan(CompetencyExecutionPlan cep) 
     88        { 
     89                // check if the plan is instantiated and already being executed 
     90                if (cep.isInstantiated() && cep.isCurrentlyExecuting()) 
     91                { 
     92                        // remember this as one of the plans to cancel 
     93                        plansToCancel.add(cep); 
     94                         
     95                        // cancel all competencies currently executing in this plan  
     96                        for (Competency c: runningCompetencies.keySet()) 
     97                        { 
     98                                // cancel this competency if it belongs to the plan we want to cancel 
     99                                if (runningCompetencies.get(c).equals(cep)) 
     100                                        c.cancel(); 
     101                        } 
     102                } 
     103        }        
     104         
    78105        /** checks pre conditions of provided plan and if possible either executes the next batch 
    79106         *  of steps or if all steps are finished raises a plan success event */ 
    80107        private synchronized void updatePlanProgress(CompetencyExecutionPlan cep) 
    81108        {                
     109                if (plansToCancel.contains(cep)) 
     110                { 
     111                        checkPlanCancelled(cep); 
     112                        return; 
     113                } 
     114                 
    82115                // build a list of plan steps that are neither completed yet nor executed currently 
    83116                ArrayList<CompetencyExecutionPlanStep>  stepsLeft = new ArrayList<CompetencyExecutionPlanStep>(); 
     
    132165        private synchronized void executeStep(CompetencyExecutionPlanStep step, CompetencyExecutionPlan cep) 
    133166        { 
     167                if (plansToCancel.contains(cep)) 
     168                { 
     169                        checkPlanCancelled(cep); 
     170                        return; 
     171                } 
     172                 
    134173                // find a competency from the library that can execute this step 
    135174                ArrayList<Competency> competencies = architecture.getCompetencyLibrary().getCompetencies(step.getCompetencyType()); 
     
    152191                                cep.getStepsCurrentlyExecuted().add(step); 
    153192                                 
     193                                // also remember that this is one of the competencies currently executing 
     194                                runningCompetencies.put(competency,cep); 
     195                                 
    154196                                // request the competency to start 
    155197                                competency.requestStartCompetency(step.getCompetencyParameters()); 
     
    165207        private synchronized void planFailed(CompetencyExecutionPlan cep) 
    166208        { 
    167                 // mark the plan as not anymore executing 
    168                 cep.stopExecution(); 
    169                  
    170                 // remove this plan from our current plans 
    171                 currentPlans.remove(cep); 
    172                  
    173                 // raise an event that the plan has failed 
    174                 this.raise(new EventCompetencyExecutionPlanFailed(cep));                 
     209                // check if the plan is actually still current 
     210                if (currentPlans.contains(cep)) 
     211                { 
     212                        // mark the plan as not anymore executing 
     213                        cep.stopExecution(); 
     214                 
     215                        // remove this plan from our current plans 
     216                        currentPlans.remove(cep); 
     217                 
     218                        // raise an event that the plan has failed 
     219                        this.raise(new EventCompetencyExecutionPlanFailed(cep)); 
     220                } 
     221        } 
     222 
     223         
     224        private synchronized void checkPlanCancelled(CompetencyExecutionPlan cep) 
     225        { 
     226                // check that this is a plan we want to cancel and all its steps have finished 
     227                if (plansToCancel.contains(cep) && (cep.getStepsCurrentlyExecuted().size()==0)) 
     228                { 
     229                        // ok ready to cancel 
     230                        cep.stopExecution(); 
     231                         
     232                        // remove this plan from our current plans 
     233                        currentPlans.remove(cep); 
     234                         
     235                        // raise an event that the plan was cancelled 
     236                        this.raise(new EventCompetencyExecutionPlanCancelled(cep));              
     237 
     238                } 
     239                 
     240                 
    175241        } 
    176242         
     
    178244        private synchronized void processCompetencySuccess(Competency competency, HashMap<String,String> parameters) 
    179245        { 
    180                  
    181                 // find the plans and plan steps that correspond to this competency 
    182                 ArrayList<CompetencyExecutionPlan> plans = new ArrayList<CompetencyExecutionPlan>(); 
    183                 ArrayList<CompetencyExecutionPlanStep> steps = new ArrayList<CompetencyExecutionPlanStep>(); 
    184                  
    185                 for (CompetencyExecutionPlan cep: currentPlans) 
    186                         for (CompetencyExecutionPlanStep step : cep.getStepsCurrentlyExecuted()) 
    187                                 if (step.getCompetencyType().equals(competency.getCompetencyType())) 
    188                                         // compare parameters to make sure this competency has performed what the plan step required 
    189                                         if (parameters.equals(step.getCompetencyParameters())) 
    190                                         { 
    191                                                 // we have found a plan and a step of this plan that was completed through this competency 
    192                                                 plans.add(cep); 
    193                                                 steps.add(step);                                                 
    194                                         } 
    195                  
    196                 // now process the found matches (note: this is in a seperate loop from above, because the processing  
    197                 // modifies the collection we iterate over above) 
    198                 for (int i = 0; i<plans.size(); i++) 
    199                 { 
    200                         // remove the step from the plans executed steps list and add it to the completed steps list instead 
    201                         plans.get(i).getStepsCurrentlyExecuted().remove(steps.get(i)); 
    202                         plans.get(i).getStepsAlreadyCompleted().add(steps.get(i)); 
     246                // get the plan that this competency is part of realizing 
     247                CompetencyExecutionPlan plan = runningCompetencies.get(competency); 
     248                 
     249                // mark the competency as not executing anymore 
     250                runningCompetencies.remove(competency); 
     251                                 
     252                CompetencyExecutionPlanStep s=null; 
     253                 
     254                // find the plan step that has completed                 
     255                for (CompetencyExecutionPlanStep step : plan.getStepsCurrentlyExecuted()) 
     256                        if (step.getCompetencyType().equals(competency.getCompetencyType())) 
     257                                // compare parameters to make sure this competency was what the plan step required 
     258                                if (parameters.equals(step.getCompetencyParameters())) 
     259                                { 
     260                                        s = step; 
     261                                } 
     262         
     263                if (s!=null) 
     264                { 
     265                        // remove the step from the plan's executed steps list                   
     266                        plan.getStepsCurrentlyExecuted().remove(s);                                      
     267                        plan.getStepsAlreadyCompleted().add(s); 
    203268                         
    204269                        // update the plan progress 
    205                         updatePlanProgress(plans.get(i)); 
    206                 } 
    207          
     270                        updatePlanProgress(plan);        
     271                } 
    208272        } 
    209273 
     
    211275        private synchronized void processCompetencyFailure(Competency competency, HashMap<String,String> parameters) 
    212276        { 
    213                 // find the plans and plan steps that have (possibly) failed because this competency has failed 
    214                 ArrayList<CompetencyExecutionPlan> plans = new ArrayList<CompetencyExecutionPlan>(); 
    215                 ArrayList<CompetencyExecutionPlanStep> steps = new ArrayList<CompetencyExecutionPlanStep>(); 
    216                  
    217                 for (CompetencyExecutionPlan cep: currentPlans) 
    218                         for (CompetencyExecutionPlanStep step : cep.getStepsCurrentlyExecuted()) 
    219                                 if (step.getCompetencyType().equals(competency.getCompetencyType())) 
    220                                         // compare parameters to make sure this competency was what the plan step required 
    221                                         if (parameters.equals(step.getCompetencyParameters())) 
    222                                         { 
    223                                                 // we have found a plan and a step of this plan that has (possibly) failed through this competency 
    224                                                 plans.add(cep); 
    225                                                 steps.add(step);                                                 
    226                                         } 
    227                  
    228                 // now process the found matches (note: this is in a seperate loop from above, because the processing  
    229                 // modifies the collection we iterate over above) 
    230                 for (int i = 0; i<plans.size(); i++) 
    231                 { 
    232                         // remove the step from the plans executed steps list 
    233                         plans.get(i).getStepsCurrentlyExecuted().remove(steps.get(i)); 
    234  
    235                         // check if the plan is still one of our current plans (this could not be the case if i>0 and 
    236                         // one of the previous steps has already failed the plan 
    237                         if (currentPlans.contains(plans.get(i)))  
     277                // get the plan that this competency is part of realizing 
     278                CompetencyExecutionPlan plan = runningCompetencies.get(competency); 
     279                 
     280                // mark the competency as not executing anymore 
     281                runningCompetencies.remove(competency); 
     282                CompetencyExecutionPlanStep s=null; 
     283                 
     284                // find the plan step that has failed because this competency has failed                 
     285                for (CompetencyExecutionPlanStep step : plan.getStepsCurrentlyExecuted()) 
     286                        if (step.getCompetencyType().equals(competency.getCompetencyType())) 
     287                                // compare parameters to make sure this competency was what the plan step required 
     288                                if (parameters.equals(step.getCompetencyParameters())) 
     289                                { 
     290                                        s = step; 
     291                                } 
     292 
     293                if (s!=null) 
     294                { 
     295                        // remove the step from the plan's executed steps list                   
     296                        plan.getStepsCurrentlyExecuted().remove(s);                                      
     297 
     298                        // check if the plan is still one of our current plans  
     299                        if (currentPlans.contains(plan))  
    238300                                // ok, it is still a current plan, so try if we can execute the step still (through another competency) 
    239                                 executeStep(steps.get(i),plans.get(i));                  
    240                 } 
    241                  
    242         } 
     301                                executeStep(s,plan);     
     302                         
     303                }                
     304        } 
     305 
     306        /** process the cancelation of a competency*/ 
     307        private synchronized void processCompetencyCancel(Competency competency, HashMap<String,String> parameters) 
     308        { 
     309                // get the plan that this competency is part of realizing 
     310                CompetencyExecutionPlan plan = runningCompetencies.get(competency); 
     311                 
     312                // mark the competency as not executing anymore 
     313                runningCompetencies.remove(competency); 
     314                                 
     315                CompetencyExecutionPlanStep s=null; 
     316                 
     317                // find the plan step that was cancelled                 
     318                for (CompetencyExecutionPlanStep step : plan.getStepsCurrentlyExecuted()) 
     319                        if (step.getCompetencyType().equals(competency.getCompetencyType())) 
     320                                // compare parameters to make sure this competency was what the plan step required 
     321                                if (parameters.equals(step.getCompetencyParameters())) 
     322                                { 
     323                                        s = step; 
     324                                } 
     325         
     326                if (s!=null) 
     327                { 
     328                        // remove the step from the plan's executed steps list                   
     329                        plan.getStepsCurrentlyExecuted().remove(s);                                      
     330                         
     331                        // check if we can already cancel the plan or if we need to wait for other competencies  
     332                        checkPlanCancelled(plan);        
     333                } 
     334 
     335        } 
     336 
    243337         
    244338        /** registers request and event handlers of the competency execution system*/ 
    245339        @Override 
    246340        public final void registerHandlers() { 
    247                 // register request handler for new competency execution plan requests with this 
     341                // register request handler for new and cancelled competency execution plan requests with this 
    248342                this.getRequestHandlers().add(new HandleNewCompetencyExecutionPlan()); 
    249                 // register event handlers for failed and suceeded competencies 
     343                this.getRequestHandlers().add(new HandleCancelCompetencyExecutionPlan()); 
     344 
     345                // register event handlers for failed, suceeded and cancelled competencies 
    250346                // since they could come from many different competencies, register with the whole simulation 
    251347                Simulation.instance.getEventHandlers().add(new HandleCompetencySucceeded()); 
    252348                Simulation.instance.getEventHandlers().add(new HandleCompetencyFailed()); 
     349                Simulation.instance.getEventHandlers().add(new HandleCompetencyCancelled()); 
    253350        } 
    254351         
     
    270367            } 
    271368        } 
     369 
     370        /** internal event handler class for handling new competency execution plan requests */ 
     371        private class HandleCancelCompetencyExecutionPlan extends RequestHandler { 
     372 
     373            public HandleCancelCompetencyExecutionPlan() { 
     374                super(new TypeSet(RequestCancelCompetencyExecutionPlan.class)); 
     375            } 
     376 
     377            @Override 
     378            public void invoke(IReadOnlyQueueSet<Request> requests) { 
     379                // since this is a request handler only for type RequestCancelCompetencyExecutionPlan the following cast always works 
     380                for (RequestCancelCompetencyExecutionPlan request : requests.get(RequestCancelCompetencyExecutionPlan.class)) 
     381                { 
     382                        cancelPlan(request.getCompetencyExecutionPlan()); 
     383                }        
     384            } 
     385        } 
    272386         
    273387        /** internal event handler class for listening to competency succeeded events */ 
     
    303417        } 
    304418 
     419        /** internal event handler class for listening to competency cancelled events */ 
     420        private class HandleCompetencyCancelled extends EventHandler { 
     421 
     422            public HandleCompetencyCancelled() { 
     423                super(EventCompetencyCancelled.class); 
     424            } 
     425 
     426            @Override 
     427            public void invoke(IEvent evt) { 
     428                // since this is an event handler only for type EventCompetencyCancelled the following casts always work 
     429                Competency competency = ((EventCompetencyCancelled)evt).getCompetency(); 
     430                HashMap<String,String> parameters = ((EventCompetencyCancelled)evt).getParameters(); 
     431                processCompetencyCancel(competency, parameters); 
     432            } 
     433        } 
    305434 
    306435 
  • libs/cmion/cmionMain/src/cmion/level2/CompetencyExecutionPlan.java

    r248 r912  
    189189                currentlyExecuting = false;              
    190190        } 
    191          
    192          
    193191 
    194192} 
  • libs/cmion/cmionMain/src/cmion/level2/EventCompetencyExecutionPlanFailed.java

    r248 r912  
    3232import cmion.architecture.CmionEvent; 
    3333 
    34 /** this type of event is raised by the competency execution system when a competency execution plan has been carried out successfully  
     34/** this type of event is raised by the competency execution system when a competency execution plan has failed  
    3535*  the competency manager listens for those events */ 
    3636public class EventCompetencyExecutionPlanFailed extends CmionEvent  
  • libs/cmion/cmionMain/src/cmion/level3/AgentMindConnector.java

    r248 r912  
    7878protected abstract void processActionFailure(MindAction a); 
    7979 
     80/** informs mind of the success of the cancellation of an executed action */ 
     81protected abstract void processActionCancellation(MindAction a); 
     82 
    8083/** informs the mind that a new entity (agent or object) has been added to the world model*/ 
    8184protected abstract void processEntityAdded(String entityName); 
     
    107110        architecture.getCompetencyManager().getEventHandlers().add(new HandleActionSucceeded()); 
    108111        architecture.getCompetencyManager().getEventHandlers().add(new HandleActionFailed()); 
    109  
     112        architecture.getCompetencyManager().getEventHandlers().add(new HandleActionCancelled()); 
     113         
    110114        // register handlers with the world model for listening to changes to it 
    111115        // for now we are interested in entities added and removed from the world model 
     
    129133} 
    130134 
     135/** cancels a currently executing mind action (if such an action is currently running) */ 
     136public final void cancel(MindAction mindAction)  
     137{ 
     138        architecture.getCompetencyManager().schedule(new RequestCancelMindAction(mindAction)); 
     139} 
     140 
    131141/** abstract method overridden from ION.meta.element */ 
    132142@Override 
     
    177187        MindAction mA = ((EventMindActionFailed)evt).getMindAction(); 
    178188        processActionFailure(mA); 
     189    } 
     190} 
     191 
     192/** internal event handler class for listening to action failed events */ 
     193private class HandleActionCancelled extends EventHandler { 
     194 
     195    public HandleActionCancelled() { 
     196        super(EventMindActionCancelled.class); 
     197    } 
     198 
     199    @Override 
     200    public void invoke(IEvent evt) { 
     201        // since this is an event handler only for type EventMindActionFailed the following cast always works 
     202        MindAction mA = ((EventMindActionCancelled)evt).getMindAction(); 
     203        processActionCancellation(mA); 
    179204    } 
    180205} 
  • libs/cmion/cmionMain/src/cmion/level3/CompetencyManager.java

    r383 r912  
    5252import cmion.architecture.IArchitecture; 
    5353import cmion.level2.CompetencyExecutionPlan; 
     54import cmion.level2.CompetencyExecutionPlanStep; 
     55import cmion.level2.EventCompetencyExecutionPlanCancelled; 
    5456import cmion.level2.EventCompetencyExecutionPlanFailed; 
    5557import cmion.level2.EventCompetencyExecutionPlanSucceeded; 
     58import cmion.level2.RequestCancelCompetencyExecutionPlan; 
    5659import cmion.level2.RequestNewCompetencyExecutionPlan; 
    5760 
     
    111114                }        
    112115        }        
     116 
     117 
     118        /** method that is called by the event handler whenever the mind initiates a new action */ 
     119        protected synchronized void cancelActionFromMind(MindAction a) 
     120        {        
     121                // find plans currently executed as a realization of a 
     122                for (CompetencyExecutionPlan plan : plansCurrentlyExecuted.keySet()) 
     123                { 
     124                        // check if plan realizes a 
     125                        if ( (a!=null) && (a.equals(plansCurrentlyExecuted.get(plan)))) 
     126                        { 
     127                                // cancel plan 
     128                                architecture.getCompetencyExecution().schedule(new RequestCancelCompetencyExecutionPlan(plan));                  
     129                        } 
     130                } 
     131        }        
     132         
    113133         
    114134        /** find a rule from the rule base that maps the specified Mind Action to a competency execution plan 
     
    157177                // register new mind action request handler with this 
    158178                this.getRequestHandlers().add(new HandleNewMindAction()); 
     179                this.getRequestHandlers().add(new HandleCancelMindAction()); 
    159180                 
    160181                // register event handlers for execution plan events with competency execution system 
    161182                architecture.getCompetencyExecution().getEventHandlers().add(new HandleCEPSucceeded()); 
    162183                architecture.getCompetencyExecution().getEventHandlers().add(new HandleCEPFailed()); 
    163                  
     184                architecture.getCompetencyExecution().getEventHandlers().add(new HandleCEPCancelled());          
    164185        } 
    165186         
     
    263284                        // this should not happen, so print out error 
    264285                        System.err.println("CompetencyManager error: received plan failure for unknown plan"); 
     286                        System.err.println("plan steps: " + plan.getNoOfSteps()); 
     287                        for (CompetencyExecutionPlanStep step : plan.getPlanSteps()) 
     288                                System.err.println("step " + step.getCompetencyType()); 
    265289                } 
    266290                 
     291        } 
     292         
     293 
     294        /** handles cancelled competency execution plans */      
     295        private synchronized void processPlanCancellation(CompetencyExecutionPlan plan) 
     296        { 
     297                // check if this is one of the plans currently executed 
     298                if (plansCurrentlyExecuted.containsKey(plan)) 
     299                {                                                
     300                        // obtain the mind action belonging to this execution plan 
     301                        MindAction ma = plansCurrentlyExecuted.get(plan); 
     302                         
     303                        // remove this plan from our memory 
     304                        plansCurrentlyExecuted.remove(plan); 
     305                         
     306                        // remove what's left of this action from our memory 
     307                        rulesAlreadyTried.remove(ma); 
     308                                 
     309                        // raise an event that the mind action has failed 
     310                        this.raise(new EventMindActionCancelled(ma)); 
     311                }                        
    267312        } 
    268313         
     
    285330            } 
    286331        } 
     332 
     333        /** internal request handler class for listening to new action requests */ 
     334        private class HandleCancelMindAction extends RequestHandler { 
     335 
     336            public HandleCancelMindAction() { 
     337                super(new TypeSet(RequestCancelMindAction.class)); 
     338            } 
     339 
     340            @Override 
     341            public void invoke(IReadOnlyQueueSet<Request> requests)  
     342            { 
     343                // iterate through requests, normally this should always only be one 
     344                for (RequestCancelMindAction request : requests.get(RequestCancelMindAction.class)) 
     345                { 
     346                        cancelActionFromMind(request.getMindAction()); 
     347                }        
     348            } 
     349        } 
     350         
    287351         
    288352        /** internal event handler class for listening to competency execution plan succeeded events */ 
     
    316380        } 
    317381 
     382        /** internal event handler class for listening to competency execution plan cancellation events */ 
     383        private class HandleCEPCancelled extends EventHandler { 
     384 
     385            public HandleCEPCancelled() { 
     386                super(EventCompetencyExecutionPlanCancelled.class); 
     387            } 
     388 
     389            @Override 
     390            public void invoke(IEvent evt) { 
     391                // since this is an event handler only for type EventCompetencyExecutionPlanCancelled the following cast always works 
     392                CompetencyExecutionPlan plan = ((EventCompetencyExecutionPlanCancelled)evt).getCompetencyExecutionPlan(); 
     393                processPlanCancellation(plan); 
     394            } 
     395        }        
    318396         
    319397} 
  • libs/cmion/cmionMain/src/cmion/level3/MindAction.java

    r248 r912  
    141141         
    142142         
     143        /** override equals to allow comparisons between 2 mind actions */ 
     144        @Override  
     145        public boolean equals(Object other) 
     146        { 
     147                if (other == null) return false; 
     148                if (!(other instanceof MindAction)) return false; 
     149                MindAction otherMa = (MindAction) other; 
     150                if (   (name.equals(otherMa.name)) 
     151                        && (subject.equals(otherMa.subject)) 
     152                        && (parameters.equals(otherMa.parameters)) 
     153                        )  
     154                        return true; 
     155                else  
     156                        return false; 
     157        } 
     158         
     159        /** define hash code for mind actions */ 
     160        @Override  
     161        public int hashCode() 
     162        { 
     163                return name.hashCode() + subject.hashCode(); 
     164        } 
     165         
    143166        /** the name/identifier of the action */ 
    144167        protected String name; 
  • libs/cmion/cmionMain/src/cmion/level3/fatima/FAtiMAConnector.java

    r429 r912  
    3838import org.w3c.dom.Element; 
    3939import org.w3c.dom.Node; 
    40 import org.w3c.dom.Text; 
    41  
    4240import cmion.architecture.IArchitecture; 
    4341import cmion.level2.migration.Migrating; 
     
    5957        private boolean sleeping; 
    6058         
     59        /** keeps track of whether the connected mind is the new modular version of Fatima or not*/ 
     60        private boolean modular; 
     61         
    6162        /** is the connected FAtiMA capable of migrating, i.e. can it send and receive 
    6263         *  its agent state through the socket connection with this connector  
     
    8788                mindThread = null; 
    8889                canMigrate = false; 
     90                modular = false; 
    8991                new ListenForConnectionThread().start(); 
    9092        } 
     
    114116                else 
    115117                        sleeping = false; 
    116          
     118 
     119                if (optionsStr.contains("modular")) 
     120                        modular = true; 
     121                else 
     122                        modular = false; 
     123 
    117124                new ListenForConnectionThread().start(); 
    118125        } 
     
    154161        } 
    155162         
     163        /** FAtiMA is currently not receiving any cancellation feedback messages, 
     164         *  so we don't need to do anything in here */ 
     165        @Override 
     166        protected void processActionCancellation(MindAction a) {} 
    156167         
    157168        @Override 
     
    186197        protected void processPropertyChanged(String entityName, 
    187198                        String propertyName, String propertyValue) { 
    188                 if (mindThread!=null) mindThread.send("PROPERTY-CHANGED "+entityName+ "(" + propertyName+ ") " + propertyValue);                 
     199                if (mindThread!=null)  
     200                        if (modular) // the modular fatima version receives property change messages in a different format (because of ToM) 
     201                                mindThread.send("PROPERTY-CHANGED SELF "+ entityName+ "(" + propertyName+ ") " + propertyValue);                 
     202                        else 
     203                                mindThread.send("PROPERTY-CHANGED "+ entityName+ "(" + propertyName+ ") " + propertyValue);              
    189204        } 
    190205 
     
    320335        } 
    321336 
     337        public void saveStateToDisk() 
     338        { 
     339                if (mindThread!=null) 
     340                { 
     341                        // send save command to FAtiMA 
     342                        mindThread.send("CMD SAVE"); 
     343                } 
     344        } 
     345         
     346         
    322347        @Override 
    323348        public Element saveState(Document doc)  
     
    402427        } 
    403428 
    404  
    405  
    406  
    407429} 
  • libs/cmion/cmionMain/src/cmion/level3/fatima/FAtiMAListenerThread.java

    r434 r912  
    3434import java.util.StringTokenizer; 
    3535 
    36 import cmion.level3.MindAction; 
    3736import cmion.storage.WorldModel; 
    3837import cmion.util.SocketListener; 
     
    157156                        connector.notifySetState(); 
    158157                } 
     158                else if (type.equals("CANCEL-ACTION")) 
     159                { 
     160                        connector.cancel(FAtiMAutils.fatimaMessageToMindAction(agentName, st.nextToken())); 
     161                } 
    159162                else { 
    160163                        //Corresponds to an action 
  • libs/cmion/cmionMain/src/cmion/level3/supersimplemind/SuperSimpleMigratingMindConnector.java

    r415 r912  
    7676        } 
    7777 
     78        @Override 
     79        protected void processActionCancellation(MindAction a) { 
     80        } 
     81         
    7882        /** pause the mind */ 
    7983        @Override 
  • libs/cmion/cmionMain/src/cmion/level3/supersimplemind/SuperSimpleMind.java

    r248 r912  
    2929 
    3030package cmion.level3.supersimplemind; 
     31 
     32import java.util.ArrayList; 
    3133 
    3234import cmion.level3.MindAction; 
     
    9193        executing = false; 
    9294        // if we are not sleeping, execute new random action 
    93         if (!sleeping) executeRandomAction();    
     95        //if (!sleeping) executeRandomAction();  
     96} 
     97 
     98/** notify the mind of an action cancellation*/ 
     99public synchronized void sendCancel(MindAction a) { 
     100        // this super simple mind does not care what happens to the actions it sends 
     101        executing = false; 
     102        // if we are not sleeping, execute new random action 
     103        //if (!sleeping) executeRandomAction();  
     104        System.out.println("action succesfully cancelled"); 
    94105} 
    95106 
     
    112123} 
    113124 
     125private MindAction getAction() 
     126{ 
     127        // modify this for test purposes 
     128        ArrayList<String> parameters = new ArrayList<String>(); 
     129        parameters.add("test"); 
     130        return new MindAction(agentName,"TestAction",parameters);        
     131} 
     132 
    114133/** creates a random action and executes it, what random exactly means depends on the body of this 
    115134 * method, which can be modified for testing purposes */ 
     
    117136{ 
    118137        // modify this for test purposes 
    119         MindAction ma = new MindAction(agentName,"Greet",null); 
    120         this.connector.newAction(ma); 
     138        this.connector.newAction(getAction()); 
    121139        executing = true; 
    122140} 
     
    136154                String propertyValue)  
    137155{ 
    138         //this super simple mind doesn't do anything with perceptions} 
     156        if (propertyName.equals("cancel")) this.connector.cancel(getAction()); 
    139157} 
    140158 
  • libs/cmion/cmionMain/src/cmion/level3/supersimplemind/SuperSimpleMindConnector.java

    r248 r912  
    7070        } 
    7171 
     72        @Override 
     73        protected void processActionCancellation(MindAction a)  
     74        { 
     75                mind.sendCancel(a); 
     76        } 
     77         
    7278        /** pause the mind */ 
    7379        @Override 
Note: See TracChangeset for help on using the changeset viewer.