2 Replies Latest reply on May 19, 2003 9:23 AM by adrian.brock

    jboss sample doesn't work

    sunnus

      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.

        • 1. Re: jboss sample doesn't work
          darranl

          Is your client a stand alone application running in it's own JVM?

          If you want to invoke methods on a MBean from outside of JBoss I think the only real option is to use the RMI adapter.

          Alternatively you could implement a session bean that invokes the methods you require.

          • 2. Re: jboss sample doesn't work

            This example shows how to bind a non serializable
            object into jndi. Because it is not serializable
            it cannot be accessed remotely.

            Regards,
            Adrian