4 Replies Latest reply on Feb 7, 2005 7:03 AM by mjea

    problem adding notification listener from remote client

    mjea

      Hi all,

      I've got a NullPointerException while using the addNotificationListener API in RMIAdaptor with JBoss 3.2.6. I first tried the example code from the admin and development guide and this works well, so I suppose the RMI adaptor is correctly configured. The exception occurs while registering the listener, so I don't even receive a first Notification object.
      Here is my code

      public class DistantNotificationClient
       implements RMINotificationListener, Serializable {
      
       public DistantNotificationClient() {
       try{
       String url = "jnp://" + "etbs159" + ":1099";
       String ini = "org.jnp.interfaces.NamingContextFactory";
       String pkgs = "org.jboss.naming,org.jnp.interfaces";
       Hashtable env = new Hashtable();
       env.put("java.naming.provider.url", url);
       env.put("java.naming.factory.initial", ini);
       env.put("java.naming.factory.url.pkgs", pkgs);
       Context ic = new InitialContext(env);
       RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor");
       ObjectName emitterName = new ObjectName("osp.smf.test:service=BroadcasterTest");
       server.addNotificationListener(emitterName, this, null, new Long(System.currentTimeMillis()));
       }catch(Exception e){
       e.printStackTrace();
       }
      
       }
      
       public void handleNotification(Notification event, Object handback){
       String type = event.getType();
       String message = event.getMessage();
       System.out.println("type = "+type+" \t message = "+message);
       }
      }
      
      


      and here is the Exception


      java.lang.NullPointerException

      at org.jboss.jmx.connector.invoker.InvokerAdaptorService.invoke(InvokerAdaptorService.java:234)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at java.lang.reflect.Method.invoke(Method.java:324)

      at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:60)

      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:62)

      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:54)

      at org.jboss.mx.server.Invocation.invoke(Invocation.java:82)

      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:197)

      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)

      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:360)

      at sun.reflect.GeneratedMethodAccessor119.invoke(Unknown Source)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at java.lang.reflect.Method.invoke(Method.java:324)

      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)

      at sun.rmi.transport.Transport$1.run(Transport.java:148)

      at java.security.AccessController.doPrivileged(Native Method)

      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)

      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)

      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)

      at java.lang.Thread.run(Thread.java:534)

      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)

      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)

      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)

      at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)

      at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)

      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)

      at org.jboss.jmx.connector.invoker.client.InvokerAdaptorClientInterceptor.invoke(InvokerAdaptorClientInterceptor.java:58)

      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:55)

      at org.jboss.proxy.ClientMethodInterceptor.invoke(ClientMethodInterceptor.java:55)

      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)

      at $Proxy0.addNotificationListener(Unknown Source)

      at com.alcatel.osp.mbean.test.DistantNotificationClient.<init>(DistantNotificationClient.java:30)

      at com.alcatel.osp.mbean.test.DistantNotificationClient.main(DistantNotificationClient.java:87)



      Does anybody have an idea of what went wrong ?
      I certainly missed something or did something wrong but I can't find the problem.

      Thanks for your help !

      Maxime


        • 1. Re: problem adding notification listener from remote client
          starksm64

          Go over the example from the admin/devel guide that uses a remote notification listener. You cannot simply pass an implementation of RMINotificationListener to the server. This has to be an exported rmi service as well.

          • 2. Re: problem adding notification listener from remote client
            mjea

            I didn't find any example of remote RMINotificationListener in adminDevel guide (nor in wiki's or faq's). However I tried to register the listener as a rmi service.
            So I made my listener extend UnicastRemoteObject and I added this code:

             public TestMain() {
             try{
             /*if (System.getSecurityManager() == null) {
             System.setSecurityManager(new RMISecurityManager());
             }*/
             DistantNotificationClient dnc = new DistantNotificationClient();
             Naming.bind("//138.203.236.159:1098/DistantNotificationClient", dnc);
             String url = "jnp://" + "etbs159" + ":1099";
             String ini = "org.jnp.interfaces.NamingContextFactory";
             String pkgs = "org.jboss.naming,org.jnp.interfaces";
             Hashtable env = new Hashtable();
             env.put("java.naming.provider.url", url);
             env.put("java.naming.factory.initial", ini);
             env.put("java.naming.factory.url.pkgs", pkgs);
             Context ic = new InitialContext(env);
             RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor");
             ObjectName emitterName = new ObjectName("osp.smf.test:service=BroadcasterTest");
             server.addNotificationListener(emitterName, dnc, null, new Long(System.currentTimeMillis()));
             }catch(Exception e){
             e.printStackTrace();
             }
            
             }
            


            Now I get the following exception:

            java.rmi.NoSuchObjectException: no such object in table

            at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)

            at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)

            at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:350)

            at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)

            at java.rmi.Naming.bind(Naming.java:111)

            at com.alcatel.osp.mbean.test.TestMain.<init>(TestMain.java:18)

            at com.alcatel.osp.mbean.test.TestMain.main(TestMain.java:80)



            I couldn't find info on this exception that matches my problem. I ran my application from the same machine as JBoss (running Solaris 9).


            • 3. Re: problem adding notification listener from remote client
              dimitris

              You don't need to bind dnc to the Naming service, it won't be looked up.

              • 4. Re: problem adding notification listener from remote client
                mjea

                Ok. How do I export the NitificationClient as a RMI service, then ? If I skip the 'bind' action, then I get The NullPointerException back.