7 Replies Latest reply on Mar 7, 2002 9:41 PM by davidjencks

    Referencing MBeans from a client

    kdavey67

      I am creating a new MBean for the first time. This MBean will manage 'machines' that poll for new files from physical machines and parse the data out and place it in the database.

      I created a MachineService MBean that looks to the database and creates all the machines instances that are configured in the system. My idea was that this MachineService MBean will handle all the maintenance of the machines, such as starting and stopping.

      To get started on this I created the MachineService MBean and had it create 3 machines. No problem, this works fine and the way that I need it to.

      No I am trying to have a client request the status of the machines from the MachineService MBean. I created code in the MBean that will register the MachineService MBean uder the java:/ namespace as 'MachineService'. I see the name in the JNDIView when I look at the server.

      But when I try to reference the server from the client I am getting a not bound error. Not being really familiar with all the details of JNDI, I am not sure where to look next.

      Here is the code that I have

      In the MachineService MBean

      **************************

      protected void startService() throws Exception {
      super.startService();

      log.info(this.jndiName);
      // Bind in JNDI
      bind(new InitialContext(), this.jndiName, this);

      log.info("Machine Service "+ getName()+" bound to " +getJndiName());

      }
      ***************

      public void setJndiName(String pJndiName) {
      jndiName = "java:/" + pJndiName;
      }
      *****************

      private void bind(Context ctx, String name, Object val) throws NamingException {
      // Bind val to name in ctx, and make sure that all intermediate contexts exist
      Name n = ctx.getNameParser("").parse(name);
      while (n.size() > 1) {
      String ctxName = n.get(0);
      try {
      ctx = (Context)ctx.lookup(ctxName);
      } catch (NameNotFoundException e) {
      log.info(e.getExplanation());
      ctx = ctx.createSubcontext(ctxName);
      }
      n = n.getSuffix(1);
      }

      ctx.bind(n.get(0), val);
      }

      *********************

      Here is the line from the client

      ***********************

      MachineService ms = (MachineService) jndiContext.lookup("java:/MachineService");

      *************

      This last line from the client is the problem.


      Any help is greatly appriciated

      kmd