mais dans le tuto Selim KEBIR a utilisé jconsole comme client.
je vais créer un client que j'utiliserai dans mon interface graphique, le problème est que tous les exemples j'ai trouvé sur Internet en commençant par celles d'Oracle génère des erreurs.
quelques idées ou propositions m'aideraient beaucoup
08/09/2016, 14h12
Gugelhupf
Bonjour,
Peux-tu nous décrire tes étapes et nous indiquer les erreurs ?
Cordialement,
09/09/2016, 01h21
marone219
je crée un mbean Hello et son interface HelloMbean , un serveur et un client
package client;
import java.util.HashMap;
import javax.management.Attribute;
import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import monitor.sdf.HelloMBean;
publicclass Client {publicstaticvoid main(String[] args){try{// Environment map//
System.out.println("\nInitialize the environment map");
HashMap env = new HashMap();
// Provide the credentials required by the server to successfully// perform user authentication//// String[] credentials = new String[] { "username" , "password" };// env.put("jmx.remote.credentials", credentials);// Create an RMI connector client and// connect it to the RMI connector server//
System.out.println("\nCreate an RMI connector client and " +
"connect it to the RMI connector server");
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:9999/server");
// Get an MBeanServerConnection//try(JMXConnector jmxc = JMXConnectorFactory.connect(url, null)){// Get an MBeanServerConnection//
System.out.println("\nGet an MBeanServerConnection");
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
// Get domains from MBeanServer//
System.out.println("\nDomains:");
String domains[] = mbsc.getDomains();
for(int i = 0; i < domains.length; i++){
System.out.println("\tDomain[" + i + "] = " + domains[i]);
}// Create SimpleStandard MBean//// ObjectName mbeanName = new ObjectName("monitor.sdf:type=Hello");
ObjectName mbeanName = ObjectName.getInstance("monitor.sdf:type=helloObject");
System.out.println("\nCreate Hello MBean...");
mbsc.createMBean("Hello", mbeanName);
// mbsc.createMBean("Hello", mbeanName, null, null);// Get MBean count//
System.out.println("\nMBean count = " + mbsc.getMBeanCount());
// Get State attribute//
System.out.println("\nState = " +
mbsc.getAttribute(mbeanName, "helloword"));
// Set State attribute//
mbsc.setAttribute(mbeanName,
new Attribute("helloword", "MC MARONE"));
// Get State attribute//// Another way of interacting with a given MBean is through a// dedicated proxy instead of going directly through the MBean// server connection//
HelloMBean proxy = JMX.newMBeanProxy(
mbsc, mbeanName, HelloMBean.class);
System.out.println("\nHelloword = " + proxy.getHelloword());
// Add notification listener on SimpleStandard MBean//
ClientListener listener = new ClientListener();
System.out.println("\nAdd notification listener...");
mbsc.addNotificationListener(mbeanName, listener, null, null);
// Invoke "reset" in SimpleStandard MBean//// Calling "reset" makes the SimpleStandard MBean emit a// notification that will be received by the registered// ClientListener.//
System.out.println("\nInvoke reset() in SimpleStandard MBean...");
mbsc.invoke(mbeanName, "sayHello", null, null);
// Sleep for 2 seconds in order to have time to receive the// notification before removing the notification listener.//
System.out.println("\nWaiting for notification...");
Thread.sleep(2000);
// Remove notification listener on SimpleStandard MBean//
System.out.println("\nRemove notification listener...");
mbsc.removeNotificationListener(mbeanName, listener);
// Unregister SimpleStandard MBean//
System.out.println("\nUnregister Hello MBean...");
mbsc.unregisterMBean(mbeanName);
// Close MBeanServer connection//
System.out.println("\nClose the connection to the server");
}
System.out.println("\nBye! Bye!");
}catch(Exception e){
e.printStackTrace();
}}}
javax.management.ReflectionException: The MBean class could not be loaded by the default loader repository
at com.sun.jmx.mbeanserver.MBeanInstantiator.findClassWithDefaultLoaderRepository(Unknown Source)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(Unknown Source)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(Unknown Source)
at com.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.createMBean(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl_Stub.createMBean(Unknown Source)
at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.createMBean(Unknown Source)
at client.Client.main(Client.java:46)
Caused by: java.lang.ClassNotFoundException: Hello
at com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.loadClass(Unknown Source)
at com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.loadClass(Unknown Source)
at com.sun.jmx.mbeanserver.MBeanInstantiator.findClassWithDefaultLoaderRepository(Unknown Source)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(Unknown Source)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(Unknown Source)
at com.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.createMBean(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)