2 Replies Latest reply on May 19, 2003 9:23 AM by Adrian Brock

    jboss sample doesn't work

    Fuqiang Sun Newbie

      I have write a MBean followed the exsample code listed in chap2/ex2. After I deployed it, I could found it successfully displayed in console. But when I use client to test it, I only can get null object from lookup method.

      Followed is MBean code:
      package com.lenovo.nms.tm;

      /**
      * Title: MsgCatch
      * Description: Used to store message catch.
      * Copyright: Copyright (c) 2003
      * Company: Lenovo
      * @author Sun Fuqiang
      * @version 1.0
      */

      import java.util.HashMap;
      import javax.naming.InitialContext;
      import javax.naming.Name;
      import javax.naming.NamingException;
      import org.jboss.naming.NonSerializableFactory;

      public class MsgCatch extends org.jboss.system.ServiceMBeanSupport
      implements MsgCatchMBean{

      private String jndiName;
      private MsgCatchQueue msgCatchQueue = new MsgCatchQueue();

      public String getJndiName()
      {
      return jndiName;
      }
      public void setJndiName(String jndiName) throws NamingException
      {
      String oldName = this.jndiName;
      this.jndiName = jndiName;
      if( super.getState() == STARTED )
      {
      unbind(oldName);
      try
      {
      rebind();
      }
      catch(Exception e)
      {
      NamingException ne = new
      NamingException("Failed to update jndiName");
      ne.setRootCause(e);
      throw ne;
      }
      }
      }

      public void startService() throws Exception
      {
      //jndiName="inmemory/maps/MsgCatch";
      System.out.println("Start Service invoked.");
      System.out.println(jndiName);
      rebind();
      }
      public void stopService()
      {
      unbind(jndiName);
      }

      private void rebind() throws NamingException
      {
      InitialContext rootCtx = new InitialContext();
      Name fullName = rootCtx.getNameParser("").parse(jndiName);
      log.info("fullName="+fullName);
      NonSerializableFactory.rebind(fullName, msgCatchQueue, true);
      }
      private void unbind(String jndiName)
      {
      try
      {
      InitialContext rootCtx = new InitialContext();
      rootCtx.unbind(jndiName);
      NonSerializableFactory.unbind(jndiName);
      }
      catch(NamingException e)
      {
      log.error("Failed to unbind map", e);
      }
      }
      }

      Client test code:
      try {
      InitialContext ctx = new InitialContext();
      Object msgCatchQueue = (Object) ctx.lookup("inmemory/maps/MsgCatch");
      String s=new String();
      s="OK,I am Richard.";
      //msgCatchQueue.addTail(s);
      int i=0;
      } catch (Exception e) {
      e.printStackTrace();
      }
      }
      msgCatchQueue always is null.

      could anyone met this problem before?

      Thanks.