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

Glassfish et Payara Java Discussion :

[JMX] comment appeler un Mbean depuis un EJB


Sujet :

Glassfish et Payara Java

  1. #1
    Membre confirmé
    Inscrit en
    Mai 2006
    Messages
    210
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 210
    Par défaut [JMX] comment appeler un Mbean depuis un EJB
    j'ai créé un projet pour faire un jar contenant
    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
    /*
     * PromoMBeanImplMBean.java
     *
     * Created on 21 avril 2010, 12:19
     */
     
    package hotel.jmx;
     
     
    /**
     * Interface PromoMBeanImplMBean
     *
     * @author MiGuilbert
     */
    public interface PromoMBeanImplMBean
    {
     
        /**
         * Get NewAttribute0 Description
         */
        public String getDateDebut();
     
        /**
         * Set NewAttribute0 Description
         */
        public void setDateDebut(String value);
     
        /**
         * Get NewAttribute1 Description
         */
        public String getDateFin();
     
        /**
         * Set NewAttribute1 Description
         */
        public void setDateFin(String value);
     
    }
    et
    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
    /*
     * PromoMBeanImpl.java
     *
     * Created on 21 avril 2010, 12:19
     */
     
    package hotel.jmx;
    import javax.management.*;
     
    /**
     * Class PromoMBeanImpl
     *
     * @author MiGuilbert
     */
    public class PromoMBeanImpl implements PromoMBeanImplMBean {
        /**
         * Attribute : DateDebut
         */
        private String dateDebut;
        /**
         * Attribute : DateFin
         */
        private String dateFin;
     
        public PromoMBeanImpl(){
        }
     
        /**
         * Get NewAttribute0 Description
         */
        public String getDateDebut() {
            return dateDebut;
        }
     
        /**
         * Set NewAttribute0 Description
         */
        public void setDateDebut(String value) {
            dateDebut = value;
        }
     
        /**
         * Get NewAttribute1 Description
         */
        public String getDateFin() {
            return dateFin;
        }
     
        /**
         * Set NewAttribute1 Description
         */
        public void setDateFin(String value) {
            dateFin = value;
        }
    }

    Dans mon EJB (qui est dans un autre projet) je fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    try { // Register MBean in Platform MBeanServer
                mbeanPromo = new PromoMBeanImpl();
                ManagementFactory.getPlatformMBeanServer().
                        registerMBean(mbeanPromo,
                        new ObjectName("hotel.jmx:type=PromoMBeanImpl"));
            }catch(JMException ex) {
                // TODO handle exception
            }
            Logger.getLogger(HotelBean.class.getName()).finest("===============================================");   
            Logger.getLogger(HotelBean.class.getName()).finest("===========>"+mbeanPromo.getDateDebut()+"<===========");
            Logger.getLogger(HotelBean.class.getName()).finest("===============================================");
    J'ai déployer mon application ear contenant l'EJB
    J'ai déployé mon "Mbeans personnalisés" à partir du fichier jar
    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
     
    Nom : mBeans
    Nom de classe d'implémentation :hotel.jmx.PromoMBeanImpl
    Nom d'objet : user:impl-class-name=hotel.jmx.PromoMBeanImpl,name=PromoMBeanImpl
     
    Description :
     
    Statut : Activé
     
     
    Attribut(s) (2)
    Nom
    Type
    Valeur
    DateDebut	java.lang.String	01/01/2010
    DateFin	java.lang.String	01/01/2010
    et dans les logs j'ai "null"

  2. #2
    Membre confirmé
    Inscrit en
    Mai 2006
    Messages
    210
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 210
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    try {
                // Get the platform MBeanServer
                MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
                ObjectName name = new ObjectName("user:impl-class-name=hotel.jmx.PromoMBeanImpl,name=PromoMBeanImpl,server=server");
                mbeanPromo = (PromoMBeanImplMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, name, PromoMBeanImplMBean.class, false);
            } catch(Exception e) {
                e.printStackTrace();
            }
    c'etait pas le bon appel

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. comment appeler un widget depuis une fonction
    Par Thierry {-|-o dans le forum Tkinter
    Réponses: 3
    Dernier message: 02/01/2008, 23h23
  2. Comment appeler une fonction depuis .Net ?
    Par bluecurve dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 04/07/2007, 19h00
  3. Réponses: 2
    Dernier message: 25/08/2006, 21h53
  4. [VB.NET] Comment appeler un DTS depuis page Web ?
    Par the_mat dans le forum ASP.NET
    Réponses: 2
    Dernier message: 22/08/2006, 12h06
  5. Réponses: 2
    Dernier message: 20/02/2006, 13h20

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