Package jade.core

Examples of jade.core.Location


    }
   
    private void handleRequestMove(VerticalCommand cmd) throws IMTPException, NotFoundException {
      Object[] params = cmd.getParams();
      AID agentID = (AID)params[0];
      Location where = (Location)params[1];
     
      moveAgent(agentID, where);
    }
View Full Code Here


    }
   
    private void handleRequestClone(VerticalCommand cmd) throws IMTPException, NotFoundException {
      Object[] params = cmd.getParams();
      AID agentID = (AID)params[0];
      Location where = (Location)params[1];
      String newName = (String)params[2];
     
      copyAgent(agentID, where, newName);
    }
View Full Code Here

          cmd.setReturnValue(fetchClassFile(className, agentName));
        }
        else if(cmdName.equals(AgentMobilitySlice.H_MOVEAGENT)) {
          GenericCommand gCmd = new GenericCommand(AgentMobilityHelper.REQUEST_MOVE, AgentMobilitySlice.NAME, null);
          AID agentID = (AID)params[0];
          Location where = (Location)params[1];
          gCmd.addParam(agentID);
          gCmd.addParam(where);
         
          result = gCmd;
        }
        else if(cmdName.equals(AgentMobilitySlice.H_COPYAGENT)) {
          GenericCommand gCmd = new GenericCommand(AgentMobilityHelper.REQUEST_CLONE, AgentMobilitySlice.NAME, null);
          AID agentID = (AID)params[0];
          Location where = (Location)params[1];
          String newName = (String)params[2];
          gCmd.addParam(agentID);
          gCmd.addParam(where);
          gCmd.addParam(newName);
         
          result = gCmd;
        }
        else if(cmdName.equals(AgentMobilitySlice.H_PREPARE)) {
         
          cmd.setReturnValue(new Boolean(prepare()));
        }
        else if(cmdName.equals(AgentMobilitySlice.H_TRANSFERIDENTITY)) {
          AID agentID = (AID)params[0];
          Location src = (Location)params[1];
          Location dest = (Location)params[2];
         
          cmd.setReturnValue(new Boolean(transferIdentity(agentID, src, dest)));
        }
        else if(cmdName.equals(AgentMobilitySlice.H_HANDLETRANSFERRESULT)) {
          AID agentID = (AID)params[0];
View Full Code Here

    // Vertical command handler methods
   
    private void handleRequestMove(VerticalCommand cmd) throws IMTPException, ServiceException, NotFoundException {
      Object[] params = cmd.getParams();
      AID agentID = (AID)params[0];
      Location where = (Location)params[1];
     
      MainContainer impl = myContainer.getMain();
      if(impl != null) {
        ContainerID cid = impl.getContainerID(agentID);
        AgentMobilitySlice targetSlice = (AgentMobilitySlice)getSlice(cid.getName());
View Full Code Here

    }
   
    private void handleRequestClone(VerticalCommand cmd) throws IMTPException, ServiceException, NotFoundException {
      Object[] params = cmd.getParams();
      AID agentID = (AID)params[0];
      Location where = (Location)params[1];
      String newName = (String)params[2];
     
      MainContainer impl = myContainer.getMain();
      if(impl != null) {
        ContainerID cid = impl.getContainerID(agentID);
View Full Code Here

    }
   
    private void handleInformMoved(VerticalCommand cmd) throws IMTPException, ServiceException, JADESecurityException, NotFoundException {
      Object[] params = cmd.getParams();
      AID agentID = (AID)params[0];
      Location where = (Location)params[1];
     
      if(myLogger.isLoggable(Logger.CONFIG))
        myLogger.log(Logger.CONFIG,"Moving agent " + agentID.getName() + " on container " + where.getName());
     
      Agent a = myContainer.acquireLocalAgent(agentID);
      if (a == null) {
        myLogger.log(Logger.SEVERE,"Internal error: handleMove() called with a wrong name (" + agentID.getName() + ") !!!");
        return;
      }
     
      int transferState = 0;
      List messages = new ArrayList();
      AgentMobilitySlice dest = null;
      try {
        // If the destination container is the same as this one, there is nothing to do
        if (CaseInsensitiveString.equalsIgnoreCase(where.getName(), myContainer.here().getName())) {
          return;
        }
       
        dest = (AgentMobilitySlice) getSlice(where.getName());
        if (dest == null) {
          myLogger.log(Logger.SEVERE,"Destination "+where.getName()+" does not exist or does not support mobility");
          return;
        }
        if(myLogger.isLoggable(Logger.FINE)) {
          myLogger.log(Logger.FINE,"Destination container for agent " + agentID + " found");
        }
       
        transferState = 1;
       
        // Serialize the agent
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream encoder = new ObjectOutputStream(out);
        encoder.writeObject(a);
        byte[] bytes = out.toByteArray();
        if(myLogger.isLoggable(Logger.FINE)) {
          myLogger.log(Logger.FINE,"Agent " + agentID.getName() + " correctly serialized");
        }
       
        // Gets the container where the agent classes can be retrieved (possibly the agent arrived in this container from another container)
        String classSiteName = (String)sites.get(a);     
        if (classSiteName == null) {
          // The agent was born on this container
          classSiteName = getLocalNode().getName();
        }
       
        // Create the agent on the destination container
        try {
          dest.createAgent(agentID, bytes, classSiteName, MIGRATION, CREATE_ONLY);
        }
        catch(IMTPException imtpe) {
          // Try to get a newer slice and repeat...
          dest = (AgentMobilitySlice)getFreshSlice(where.getName());
          dest.createAgent(agentID, bytes, classSiteName, MIGRATION, CREATE_ONLY);
        }
       
        transferState = 2;
        if(myLogger.isLoggable(Logger.FINE)) {
View Full Code Here

    }
   
    private void handleInformCloned(VerticalCommand cmd) throws IMTPException, NotFoundException, NameClashException, JADESecurityException { // HandleInformCloned start
      Object[] params = cmd.getParams();
      AID agentID = (AID)params[0];
      Location where = (Location)params[1];
      String newName = (String)params[2];
     
      try {
        //#J2ME_EXCLUDE_BEGIN 
        //Register the clone in the Code Locator in the case its father is a jar agent
        String containerName = myContainer.getID().getName();
        Agent agent = myContainer.acquireLocalAgent(agentID);
        String codeContainerName = getClassSite(agent);
        myContainer.releaseLocalAgent(agentID);

        //Check if the code is in the same container or in a remote one.
        AgentManagementService amSrv = (AgentManagementService) myFinder.findService(AgentManagementService.NAME);
        CodeLocator codeLocator = amSrv.getCodeLocator();
       
        if (codeContainerName == null) codeContainerName = containerName;
        if (containerName.equals(codeContainerName)) {
          if (codeLocator.isRegistered(agentID)) {
            if(myLogger.isLoggable(Logger.FINE)) {
              myLogger.log(Logger.FINE," adding clone " + newName  + " to code locator.");
            }
           
            codeLocator.cloneAgent(agentID, new AID(newName,AID.ISLOCALNAME));
         
        } else {
          //Send a CLONE_CODE_LOCATOR_ENTRY command to the container with the agent code.
          AgentMobilitySlice codeSlice = (AgentMobilitySlice) getSlice(codeContainerName);
          try {
            codeSlice.cloneCodeLocatorEntry(agentID, new AID(newName,AID.ISLOCALNAME));
          } catch (IMTPException imtpe) {
            // Try to get a newer slice and repeat...
            codeSlice = (AgentMobilitySlice) getSlice(codeContainerName);
            codeSlice.cloneCodeLocatorEntry(agentID, new AID(newName,AID.ISLOCALNAME));
          }
        }
        //#J2ME_EXCLUDE_END 
       
        //log("Cloning agent " + agentID + " on container " + where.getName(), 1);
        if(myLogger.isLoggable(Logger.CONFIG))
          myLogger.log(Logger.CONFIG,"Cloning agent " + agentID + " on container " + where.getName());
       
        Agent a = myContainer.acquireLocalAgent(agentID);
        if (a == null) {
          //System.out.println("Internal error: handleClone() called with a wrong name (" + agentID + ") !!!");
          if(myLogger.isLoggable(Logger.SEVERE))
            myLogger.log(Logger.SEVERE,"Internal error: handleClone() called with a wrong name (" + agentID + ") !!!");
          return;
        }
       
        AgentMobilitySlice dest = (AgentMobilitySlice)getSlice(where.getName());
        if (dest == null) {
          myLogger.log(Logger.SEVERE,"Destination "+where.getName()+" does not exist or does not support mobility");
          return;
        }
        if(myLogger.isLoggable(Logger.FINE))
          myLogger.log(Logger.FINE,"Destination container for agent " + agentID + " found");
       
       
        // Serialize the agent
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream encoder = new ObjectOutputStream(out);
        encoder.writeObject(a);
        byte[] bytes = out.toByteArray();
        //log("Agent " + agentID + " correctly serialized", 2);
        if(myLogger.isLoggable(Logger.FINE))
          myLogger.log(Logger.FINE,"Agent " + agentID + " correctly serialized");
       
       
        // Gets the container where the agent classes can be retrieved
        String classSiteName = (String)sites.get(a);
        if (classSiteName == null) {
          // The agent was born on this container
          classSiteName = getLocalNode().getName();
        }
       
        // Create the agent on the destination container with the new AID
        AID newID = new AID(newName, AID.ISLOCALNAME);
        try {
          dest.createAgent(newID, bytes, classSiteName, CLONING, CREATE_AND_START);
        }
        catch(IMTPException imtpe) {
          // Try to get a newer slice and repeat...
          dest = (AgentMobilitySlice)getFreshSlice(where.getName());
          dest.createAgent(newID, bytes, classSiteName, CLONING, CREATE_AND_START);
        }
        if(myLogger.isLoggable(Logger.FINE))
          myLogger.log(Logger.FINE,"Cloned Agent " + newID + " correctly created on destination container");
       
View Full Code Here

  public void postProcess(VerticalCommand cmd) {
    String name = cmd.getName();

    if (name.equals(jade.core.mobility.AgentMobilityHelper.INFORM_MOVED)) {
      AID agent = (AID) cmd.getParam(0);
      Location destination = (Location) cmd.getParam(1);
      if (!myAgentContainer.isLocalAgent(agent)) {
        // The agent actually moved elsewhere
        if (destination instanceof ContainerID) {
          // The agent moved to a container inside the platform --> transfer its local aliases there
          myService.transferLocalAliases(agent, (ContainerID) destination);
View Full Code Here

TOP

Related Classes of jade.core.Location

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.