0 Replies Latest reply on Aug 17, 2003 12:33 PM by oscpro

    MBean exercise

    oscpro

      On the exo1 of chap2 (Standard MBean) we have the following code for the JNDIMap class

      private void rebind() throws NamingException
      {
       InitialContext rootCtx = new InitialContext();
       Name fullName = rootCtx.getNameParser("").parse(jndiName);
       System.out.println("fullName=" + fullName);
       NonSerializableFactory.rebind(fullName, contextMap, true);
      }
      
      private void unbind(String jndiName)
      {
       try
       {
       InitialContext rootCtx = new InitialContext();
       rootCtx.unbind(jndiName);
       NonSerializableFactory.unbind(jndiName);
       }
       catch (NamingException e)
       {
       e.printStackTrace();
       }
      }
      


      if I try the following client code:

      InitialContext context = new InitialContext();
      HashMap map = (HashMap) context.lookup("inmemory/maps/MapTest");
      System.err.println("map: " + map);
      


      I get:
      map: null
      



      So I changed the JNDI class code to:

      private void rebind() throws NamingException
      {
       InitialContext rootCtx = new InitialContext();
       Name fullName = rootCtx.getNameParser("").parse(jndiName);
       System.out.println("fullName=" + fullName);
       rootCtx.bind(fullName, contextMap); // <== ADDED
       // NonSerializableFactory.rebind(fullName, contextMap, true); <== REMOVED
      }
      
      private void unbind(String jndiName)
      {
       try
       {
       InitialContext rootCtx = new InitialContext();
       rootCtx.unbind(jndiName);
       // NonSerializableFactory.unbind(jndiName); <== REMOVED
       }
       catch (NamingException e)
       {
       e.printStackTrace();
       }
      }
      


      Now with the same client code it works fine, I get:
      map: {key0=value0}
      


      So the question is: What is the purpose of "NonSerializableFactory.rebind" ?

      Oscar