5 Replies Latest reply: Sep 7, 2010 6:43 PM by EJP RSS

    RMID Many activation processes problem

    843793
      Hello,

      I am using RMID to activate Java independent processes, that derived from the same Activable class, but are registered under different names in the RMI Registry (same port is used).

      My Problem is, after some time, many processes exist, often two per Activable object (one with environment properties and another one with the expected properties that are different for every Activable object), and more processes appear as they were instanciated from an Activable object already associated to an existing process, whereas that should not happened.

      My code, registering Activable objects in rmiregistry, is the following :

       
      public static void main(String[] args) throws Exception {
      
              // Instanciate a custom Security Manager
              System.setSecurityManager(new MySecurityManager());
      
               // Set every environment variables in properties, as well as the
              // security policy that shall be added even if a Security Manager has
              // been instanciated before
              ActivationGroupDesc.CommandEnvironment ace = null;
              Properties props = new Properties();
              props.put("java.security.policy", System.getenv("MY_HOME") + File.separator + "resources" + File.separator
                                                + "AllPermissionPolicy");
      
              
              
              // The "location" String specifies a URL from where the class
              // definition will come when this object is requested (activated).
              // Don't forget the trailing slash at the end of the URL
              // or your classes won't be found.
              String location = System.getProperty("java.rmi.server.codebase");
      
              // The location argument to the ActivationDesc constructor will be used
              // to uniquely identify this class; it's location is relative to the
              // URL-formatted String, location.
              MarshalledObject data = null;
              
              ActivationSystem localActivationSystem = ActivationGroup.getSystem();
              
              // Variables declaration
              ActivationGroupID agi = null;
              ActivationDesc desc = null;
              ActivationGroupDesc groupDesc = null;
              
              try {
                  // FOR EACH project
                  File[] projects = (new File(System.getenv("MY_CONF"))).listFiles();
                  for (int p = 0; p < projects.length; p++) {
                      if (!projects[p].isFile()) {
                          String project = projects[p].getName();
                          File[] subprojects= projects[p].listFiles();
                          // FOR EACH subproject
                          for (int m = 0; m < subprojects.length; m++) {
                              if (!subprojects[m].isFile()) {
                                  String subproject = subprojects[m].getName();
                                  String lookupName = project + subproject + "MyActivableObject";
      
                                  props.put("PROJECT", project);
                                  props.put("SUBPROJECT", subproject);
                                  
                                  // Activation Group Descriptor
                                  groupDesc = new ActivationGroupDesc(props, ace);        
                                  agi = localActivationSystem.registerGroup(groupDesc);
                                  
                                  // The activation group is what creates the activable object in a JVM
                                  // Sets the activation group for the current JVM
                                  //ActivationGroup.createGroup(agi, groupDesc, 0);
                                 
                                  // Once the ActivationGroupDesc has been created, register it
                                  // with the activation system to obtain its ID
                                  desc = new ActivationDesc(agi, "example.MyActivableObject", location, data);
      
                                  // Register with rmid
                                  MyActivableObjectInterface mri = (MyActivableObjectInterface) Activatable.register(desc);
                                  
                                  // Bind the stub to a name in the registry
                                  Naming.rebind("//" + InetAddress.getLocalHost().getHostName() + ":" + MY_RMI_PORT + "/" + lookupName,
                                                mri);
                                  System.out.println(project + "\t" + subproject+ "\tMyActivableObject done.");
                              }
                          }
                      }
                  }
              }
              catch (Exception e) {
                  e.printStackTrace();
                  System.err.println("Failed to set up start services. " + e.getMessage());
              }
              System.exit(0);
          }
      Could you, please, tell me what am I doing wrong, knowing that my aim is to have the minimum of processes, one per "subproject", that are all independent, and that can be activated and killed every time I want ?

      Thank you in advance for your help,

      Eva
        • 1. Re: RMID Many activation processes problem
          EJP
          What you are probably doing wrong is running that code multiple times. Every time you register a new activatable you are compounding this problem.

          The tutorials don't make this clear at all, but you need to split this code into two. You need to run the registration part of it exactly once, and serialize the activatable stub to a file. Then, every system startup, run another program that reads the stubs and registers them with the RMI Registry.
          • 2. Re: RMID Many activation processes problem
            843793
            I'm not sure I understand. As you told me, I separated the registration of the Activable object to the stubs binding part. I didn't bind the stubs to the RMI Registry in another program, because I need all of them to be reachable immediately.
            There is the updated code that gives the same results as the old one :
            public static void main(String[] args) throws Exception {
            
                    // Instanciate a custom Security Manager
                    System.setSecurityManager(new MySecurityManager());
            
                    // ---- Configuration
                    // String directoryPath = System.getenv("MY_CONF");
            
                    // Set every environment variables in properties, as well as the
                    // security policy that shall be added even if a Security Manager has
                    // been instanciated before
                    ActivationGroupDesc.CommandEnvironment ace = null;
                    Properties props = new Properties();
                    props.put("java.security.policy", System.getenv("MY_HOME") + File.separator + "resources" + File.separator
                                                      + "AllPermissionPolicy");
            
                    
                    
                    // The "location" String specifies a URL from where the class
                    // definition will come when this object is requested (activated).
                    // Don't forget the trailing slash at the end of the URL
                    // or your classes won't be found.
                    String location = System.getProperty("java.rmi.server.codebase");
                   
                    // The location argument to the ActivationDesc constructor will be used
                    // to uniquely identify this class; it's location is relative to the
                    // URL-formatted String, location.
                    MarshalledObject data = null;
                    
                    ActivationSystem localActivationSystem = ActivationGroup.getSystem();
                    
                    
                    // Activation Group Descriptor
                    ActivationGroupDesc groupDesc = new ActivationGroupDesc(props, ace);        
                    ActivationGroupID agi = localActivationSystem.registerGroup(groupDesc);
                    
                    // The activation group is what creates the activable object in a JVM
                    // Sets the activation group for the current JVM
                    //ActivationGroup.createGroup(agi, groupDesc, 0);
                   
                    // Once the ActivationGroupDesc has been created, register it
                    // with the activation system to obtain its ID
                    ActivationDesc desc = new ActivationDesc(agi, "example.MyActivableObject", location, data);
                    
                    // Register with rmid
                    MyActivableObjectInterface mri = (MyActivableObjectInterface) Activatable.register(desc);
                    
                    try {
                        // FOR EACH project
                        File[] projects = (new File(System.getenv("DALI_CONF"))).listFiles();
                        for (int p = 0; p < projects.length; p++) {
                            if (!projects[p].isFile()) {
                               String project = projects[p].getName();
                                File[] subprojects= projects[p].listFiles();
                                // FOR EACH subproject
                                for (int m = 0; m < subprojects.length; m++) {
                                    if (!subprojects[m].isFile()) {
                                        String subproject = subprojects[m].getName();
                                        String lookupName = project + subproject + "MyActivableObject";
            
                                        props.put("PROJECT", project);
                                        props.put("SUBPROJECT", subproject);
            
                                        // Bind the stub to a name in the registry
                                        Naming.rebind("//" + InetAddress.getLocalHost().getHostName() + ":" + MY_RMI_PORT + "/" + lookupName,
                                                      mri);
                                        System.out.println(project + "\t" + mission + "\tMyActivableObject ... done");
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e) {
                        e.printStackTrace();
                        System.err.println("Failed to set up start services. " + e.getMessage());
                    }
                    System.exit(0);
                }
            Please, could you explain to me what I'm missing or not understanding ?
            Thank you,

            Eva
            • 3. Re: RMID Many activation processes problem
              EJP
              You still haven't separated registration from binding here. You need two separate programs.
              • 4. Re: RMID Many activation processes problem
                843793
                Finally, I found why many processes stayed alive, even if the rmid process is killed and then restarted.
                RMID kept a snapshot of old activated processes in the file log/Snapshot.1, and activated the processes in this file, at startup.
                After removing the file Snapshot.1, now my application is behaving as expected.
                • 5. Re: RMID Many activation processes problem
                  EJP
                  And that's for the reason I stated. You have to separate this program into two parts. One that does the registration, which creates entries in the Snapshot file, and another that does the binding. If you run the registration part every startup you are just doing something unnecessary, and deleting the snapshot file just undoes the unnecessary repetition. Solve the problem.