Changeset 362


Ignore:
Timestamp:
04/14/2010 05:18:40 PM (10 years ago)
Author:
pedro.cuba
Message:

Integrated Migration Competency into CMION

Location:
libs/cmion/cmionMain/src/cmion
Files:
28 added
1 edited
2 copied

Legend:

Unmodified
Added
Removed
  • libs/cmion/cmionMain/src/cmion/architecture/IArchitecture.java

    r250 r362  
    5555        public CompetencyLibrary getCompetencyLibrary(); 
    5656         
     57        /** in this method the architecture must return a reference to an object with system specific information or resources. 
     58         * when there is system specific information or resources it returns null. */ 
     59        public Object getSystemContext(); 
    5760} 
  • libs/cmion/cmionMain/src/cmion/level3/supersimplemind/SuperSimpleMigratingMind.java

    r303 r362  
    3030package cmion.level3.supersimplemind; 
    3131 
     32import java.util.ArrayList; 
     33 
    3234import cmion.level3.MindAction; 
    3335 
     
    3537 * this is just to show how one could interface a different mind then FAtiMA, 
    3638 * e.g. a user controlled mind for debugging purposes*/ 
    37 public class SuperSimpleMind 
     39public class SuperSimpleMigratingMind 
    3840{ 
    3941 
    4042/** a pointer to the connector object that connects this mind to the competency manager */       
    41 private SuperSimpleMindConnector connector;      
     43private SuperSimpleMigratingMindConnector connector;     
    4244 
    4345/** a boolean tracking whether this mind is executing an action at the moment (i.e. waiting for  
     
    5254 
    5355/** creates a new super simple mind */ 
    54 public SuperSimpleMind(SuperSimpleMindConnector connector) 
     56public SuperSimpleMigratingMind(SuperSimpleMigratingMindConnector connector) 
    5557{ 
    5658        this.connector = connector; 
     
    7072public synchronized void sendAwake()  
    7173{ 
     74        System.out.println("Awaking"); 
    7275        if (sleeping) 
    7376        { 
    7477                // if we are not already executing something, execute a new random action 
    7578                sleeping = false; 
    76                 if (!executing) executeRandomAction(); 
     79                if (!executing) executeMigrationAction(); 
    7780        } 
    7881} 
     
    8285        // this super simple mind does not care what happens to the actions it sends 
    8386        executing = false; 
     87         
    8488        // if we are not sleeping, execute new random action 
    85         if (!sleeping) executeRandomAction(); 
     89        //if (!sleeping) executeMigrationAction(); 
    8690} 
    8791 
     
    9094        // this super simple mind does not care what happens to the actions it sends 
    9195        executing = false; 
     96         
    9297        // if we are not sleeping, execute new random action 
    93         if (!sleeping) executeRandomAction();    
     98        //if (!sleeping) executeMigrationAction();       
    9499} 
    95100 
     
    112117} 
    113118 
    114 /** creates a random action and executes it, what random exactly means depends on the body of this 
    115  * method, which can be modified for testing purposes */ 
    116 private void executeRandomAction() 
     119/** creates a Migrating action to a specific device and attempts to execute it */ 
     120private void executeMigrationAction() 
    117121{ 
     122        ArrayList<String> parameters = new ArrayList<String>(); 
     123        parameters.add("B"); 
     124         
    118125        // modify this for test purposes 
    119         MindAction ma = new MindAction(agentName,"Greet",null); 
     126        MindAction ma = new MindAction(agentName,"Migration",parameters); 
    120127        this.connector.newAction(ma); 
    121128        executing = true; 
  • libs/cmion/cmionMain/src/cmion/level3/supersimplemind/SuperSimpleMigratingMindConnector.java

    r303 r362  
    3030package cmion.level3.supersimplemind; 
    3131 
     32import org.w3c.dom.Document; 
     33import org.w3c.dom.Element; 
     34 
    3235import cmion.architecture.IArchitecture; 
     36import cmion.level2.migration.Migrating; 
    3337import cmion.level3.AgentMindConnector; 
    3438import cmion.level3.MindAction; 
    3539 
    3640/** The connector to a SuperSimpleMind (example implementation of a simple mind interface) */ 
    37 public class SuperSimpleMindConnector extends AgentMindConnector { 
     41public class SuperSimpleMigratingMindConnector extends AgentMindConnector implements Migrating { 
    3842 
    3943         
    4044        /** the mind itself */ 
    41         private SuperSimpleMind mind; 
     45        private SuperSimpleMigratingMind mind; 
    4246         
    4347        /** creates a new connector for a SuperSimpleMind */  
    44         public SuperSimpleMindConnector(IArchitecture architecture) 
     48        public SuperSimpleMigratingMindConnector(IArchitecture architecture) 
    4549        {        
    4650                super(architecture); 
    4751                // create the mind, initially sleeping 
    48                 mind = new SuperSimpleMind(this); 
     52                mind = new SuperSimpleMigratingMind(this); 
    4953        } 
    5054         
     
    113117        } 
    114118 
     119 
     120        @Override 
     121        public String getMessageTag() { 
     122                return "mindstate"; 
     123        } 
     124 
     125 
     126        @Override 
     127        public void restoreState(Element message) { 
     128 
     129                Element goal = (Element) message.getElementsByTagName("goal").item(0); 
     130                if(goal != null){ 
     131                        System.out.println("MIND-Received mind with goal: "+goal.getAttribute("value")); 
     132                } else { 
     133                        System.out.println("MIND-Received mind without goal."); 
     134                } 
     135        } 
     136 
     137 
     138        @Override 
     139        public Element saveState(Document doc) { 
     140                Element state = doc.createElement(getMessageTag()); 
     141                 
     142                Element goal = doc.createElement("goal"); 
     143                goal.setAttribute("value", "Migrate Mind"); 
     144                state.appendChild(goal); 
     145                 
     146                return state; 
     147        } 
     148 
     149 
     150        @Override 
     151        public void onMigrationFailure() { 
     152                System.out.println("MIND-Migration Failed."); 
     153        } 
     154 
     155 
     156        @Override 
     157        public void onMigrationIn() { 
     158                System.out.println("MIND-Receiving a migration."); 
     159        } 
     160 
     161 
     162        @Override 
     163        public void onMigrationOut() { 
     164                System.out.println("MIND-Going to migrate."); 
     165        } 
     166 
     167 
     168        @Override 
     169        public void onMigrationSuccess() { 
     170                System.out.println("MIND-Migration Success."); 
     171        } 
     172 
    115173} 
Note: See TracChangeset for help on using the changeset viewer.