IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

création d'un client jmx


Sujet :

Java

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2012
    Messages : 2
    Par défaut création d'un client jmx
    Bonjour à tous,

    je suis débutant en java

    j'ai un Mbean serveur qui fonctionne correctement grâce au tuto
    http://skebir.developpez.com/tutoriels/java/jmx/

    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

  2. #2
    Modérateur
    Avatar de Gugelhupf
    Homme Profil pro
    Analyste Programmeur
    Inscrit en
    Décembre 2011
    Messages
    1 326
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Analyste Programmeur

    Informations forums :
    Inscription : Décembre 2011
    Messages : 1 326
    Billets dans le blog
    12
    Par défaut
    Bonjour,

    Peux-tu nous décrire tes étapes et nous indiquer les erreurs ?

    Cordialement,
    N'hésitez pas à consulter la FAQ Java, lire les cours et tutoriels Java, et à poser vos questions sur les forums d'entraide Java

    Ma page Developpez | Mon profil Linkedin | Vous souhaitez me contacter ? Contacter Gokan EKINCI

  3. #3
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2012
    Messages : 2
    Par défaut je crée un mbean Hello et son interface HelloMbean , un serveur et un client
    Voici mon mbean
    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    /*
     * Hello.java
     *
     * Created on 7 septembre 2016, 17:56
     */
    package monitor.sdf;
     
    import javax.management.*;
     
    /**
     * Class Hello
     *
     * @MARONE219
     */
    public class Hello implements HelloMBean {
        /**
         * Attribute : Helloword
         */
        private String helloword;
     
        public Hello() {
        }
     
        /**
         * Get NewAttribute0 Description
         */
        public String getHelloword() {
            return helloword;
        }
     
        /**
         * Set NewAttribute0 Description
         */
        public void setHelloword(String value) {
            helloword = value;
        }
     
        /**
         * newOperation0 Description
         * @param x parameter0 Description
         * @param y parameter1 Description
         * @return int
         */
        public int add(int x, int y) {
            //TODO add your own implementation
            return x + y;
        }
     
        /**
         * newOperation1 Description
         */
        public void sayHello() {
            System.out.println(helloword);
        }
    }

    Son interface

    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    /*
     * HelloMBean.java
     *
     * Created on 7 septembre 2016, 17:56
     */
    package monitor.sdf;
     
    /**
     * Interface HelloMBean
     *
     * @author 3tête
     */
    public interface HelloMBean {
     
        /**
         * Get NewAttribute0 Description
         */
        public String getHelloword();
     
        /**
         * Set NewAttribute0 Description
         */
        public void setHelloword(String value);
     
        /**
         * newOperation0 Description
         * @param x parameter0 Description
         * @param y parameter1 Description
         * @return int
         */
        public int add(int x, int y);
     
        /**
         * newOperation1 Description
         */
        public void sayHello();
     
    }

    Mon serveur



    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    package monitor;
     
    import java.lang.management.ManagementFactory;
    import java.rmi.registry.LocateRegistry;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.management.MBeanServer;
    import javax.management.ObjectName;
    import javax.management.remote.JMXConnectorServer;
    import javax.management.remote.JMXConnectorServerFactory;
    import javax.management.remote.JMXServiceURL;
    import monitor.sdf.Hello;
     
    /**
     *
     * @ MARONE219
     */
    public class Monitor {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
            try {
                LocateRegistry.createRegistry(9999);
                ObjectName name = new ObjectName("Hello:type=helloObject");
                Hello h = new Hello();
                h.setHelloword("Bonjour MC Marone");
                mbs.registerMBean(h, name);
                JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:9999/server");
                JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
                cs.start();
                System.out.println("ecoute ........");
                int n = 1;
                while (true) {                
                    System.out.println(h.getHelloword());
                    Thread.sleep(3000);
     
                }
            } catch (Exception ex) {
                Logger.getLogger(Monitor.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
     
    }

    Mon client

    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    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;
     
    public class Client {
     
        public static void 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();
            }
        }
    }


    Et l’erreur affichée par le client


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    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)

Discussions similaires

  1. création d'un client FTP à l'aide de windev express
    Par young077 dans le forum WinDev
    Réponses: 4
    Dernier message: 28/05/2007, 22h34
  2. [newbie] Création d'un client
    Par Marthym dans le forum Services Web
    Réponses: 1
    Dernier message: 23/05/2007, 11h04
  3. création d'un client - server.
    Par damien77 dans le forum Entrée/Sortie
    Réponses: 3
    Dernier message: 14/04/2007, 17h28
  4. [WTP] Création d'un client Webservice
    Par osmoze dans le forum Services Web
    Réponses: 1
    Dernier message: 09/03/2007, 17h04
  5. création d'un client messagerie
    Par lonycc dans le forum ASP
    Réponses: 2
    Dernier message: 22/02/2007, 15h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo