2010-10-01 64 views
0

我在JBoss上使用NotificationListener有一些問題。JBoss MBean NotificationListener問題

我在JBoss上有一個MBean,我可以連接並調用他們的方法。但是,當我嘗試添加通知Ÿ獲得下一個例外:

 
org.jboss.invocation.JBossLazyUnmarshallingException: getArguments failed 
    at org.jboss.invocation.MarshalledInvocation.getArguments(MarshalledInvocation.java:513) 
    at org.jboss.jmx.connector.invoker.InvokerAdaptorService.invoke(InvokerAdaptorService.java:230) 
    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:597) 
    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157) 
    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96) 
    at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:138) 
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:90) 
    at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:140) 
    at org.jboss.jmx.connector.invoker.SerializableInterceptor.invoke(SerializableInterceptor.java:74) 
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:90) 
    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264) 
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668) 
    at org.jboss.invocation.jrmp.server.JRMPProxyFactory.invoke(JRMPProxyFactory.java:180) 
    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:597) 
    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157) 
    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96) 
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:88) 
    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264) 
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668) 
    at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:855) 
    at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:422) 
    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:597) 
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305) 
    at sun.rmi.transport.Transport$1.run(Transport.java:159) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at sun.rmi.transport.Transport.serviceCall(Transport.java:155) 
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:637) 
Caused by: java.lang.ClassNotFoundException: ar.com.cube3.test.msn.MyListener 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:247) 
    at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:292) 
    at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1119) 
    at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:798) 
    at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:441) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:247) 
    at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604) 
    at org.jboss.invocation.MarshalledValueInputStream.resolveClass(MarshalledValueInputStream.java:109) 
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575) 
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496) 
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732) 
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) 
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1667) 
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1323) 
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) 
    at org.jboss.invocation.MarshalledValue.get(MarshalledValue.java:91) 
    at org.jboss.invocation.MarshalledInvocation.getArguments(MarshalledInvocation.java:509) 
    ... 40 more 

我打電話的MBean形成客戶JBOSS

主要的代碼之外是:

 
Properties env = new Properties(); 
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 
      env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); 
      env.put(Context.PROVIDER_URL, "jnp://localhost:1099"); 

      InitialContext ctx; 
      ctx = new InitialContext(env); 

      MBeanServerConnection server = (MBeanServerConnection)ctx.lookup("jmx/invoker/RMIAdaptor"); 


       // get reference to CacheMgmtInterceptor MBean 

       String cache_service = "ar.com.cube3.framework.modulos.msn:jndiName=msnControl,service=MSNControlAcceso"; 
       //String cache_service = "jboss:service=JNDIView"; 
       ObjectName mgmt_name = new ObjectName(cache_service); 
//    
       server.addNotificationListener(mgmt_name,(NotificationListener) new MyListener(), new NotificationFilter() { 


       private static final long serialVersionUID = 6404657810887052083L; 

       public boolean isNotificationEnabled(Notification notification) { 
        // TODO Auto-generated method stub 
        return true; 
       } 
      }, null); 

      Object obj[]= {"test"}; 
      Object temp = server.invoke(mgmt_name, "registrarMsnMessenger", obj, new String[]{String.class.getName()}); 
      System.out.println(temp); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

和notificationListener實現:

 

import java.io.Serializable; 

import javax.management.Notification; 
import javax.management.NotificationListener; 

public class MyListener implements NotificationListener, Serializable{ 


    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 

    public void handleNotification(Notification notification, Object handback) { 
     System.out.println("objecto "+ notification.getMessage()); 

    } 
} 

在此先感謝。 Andres。

回答

1

問題是您的JBoss服務器在其類路徑中沒有您的監聽器實現(ar.com.cube3.test.msn.MyListener),所以它不能實例化它將其註冊爲監聽器。將所有自定義類(如偵聽器)打包到jar中,並將該jar放入目錄[jboss-home]/server/[server-name]/lib

+0

尼古拉斯一些信息,是的,你是對的,我的錯誤,我認爲這是沒有必要把罐子到lib文件夾時的類已經在耳邊。 – aivaldi 2010-10-18 13:30:12