1 2 Previous Next 18 Replies Latest reply on Apr 1, 2009 3:39 AM by ezza ezaezazea

    Can't get @Service to work

    ezza ezaezazea Novice

      Even deploying the provided example (http://www.jboss.org/jbossejb3/docs/reference/build/reference/en/html/jboss_extensions.html#d0e375), no MBean with the specified objectName is ever created. No stack either, not even a WARN or suspicious looking DEBUG.

      @Service (objectName = "jboss:custom=Name"

      I'm using JBoss 4.2.3GA.

        • 1. Re: Can't get @Service to work
          jaikiran pai Master

          Please post the bean code including the import statements. Also post the console logs.

          • 2. Re: Can't get @Service to work
            ezza ezaezazea Novice

            Alright i must have done something wrong yesterday, i tried again and the example works. I still cant manage to manage my MDB though(which was the objective i had).

            _____WORKS_____

            Management interface

            package com.navineo.sa.ejb.session;
            import org.jboss.annotation.ejb.Management;
            
            @Management
            public interface ServiceOneManagement
            {
             void setAttribute(int attribute);
             int getAttribute();
             String sayHello();
            
             void create() throws Exception;
             void start() throws Exception;
             void stop();
             void destroy();
            }


            And the SLSB:
            package com.navineo.sa.ejb.session;
            
            import javax.ejb.Remote;
            
            import org.jboss.annotation.ejb.Service;
            
            
            @Service (objectName = "jboss:custom=Name")
            @Remote(ServiceOneRemote.class)
            public class ServiceOne implements ServiceOneRemote, ServiceOneManagement
            {
             int attribute;
            
             public void setAttribute(int attribute)
             {
             this.attribute = attribute;
             }
            
             public int getAttribute()
             {
             return this.attribute;
             }
            
             public String sayHello()
             {
             return "Hello from service One";
             }
            
             // Lifecycle methods
             public void create() throws Exception
             {
             System.out.println("ServiceOne - Creating");
             }
            
             public void start() throws Exception
             {
             System.out.println("ServiceOne - Starting");
             }
            
             public void stop()
             {
             System.out.println("ServiceOne - Stopping");
             }
            
             public void destroy()
             {
             System.out.println("ServiceOne - Destroying");
             }
            }
            


            It implements the Remote interface:
            package com.navineo.sa.ejb.session;
            
            public interface ServiceOneRemote
            {
             public void setAttribute(int attribute);
             public int getAttribute();
            }
            


            An MBean with the objectName = "jboss:custom=Name" is indeed created.

            DOESN'T WORK:
            package com.navineo.hora.ejb.mdb;
            
            import javax.annotation.Resource;
            import javax.ejb.ActivationConfigProperty;
            import javax.ejb.EJB;
            import javax.ejb.MessageDriven;
            import javax.ejb.TransactionAttribute;
            import javax.ejb.TransactionAttributeType;
            import javax.jms.JMSException;
            import javax.jms.Message;
            import javax.jms.MessageListener;
            import javax.jms.ObjectMessage;
            import javax.jms.Topic;
            import javax.jms.TopicConnectionFactory;
            
            import org.apache.log4j.LogManager;
            import org.apache.log4j.Logger;
            import org.jboss.annotation.ejb.Clustered;
            import org.jboss.annotation.ejb.Service;
            
            import com.navineo.dock.ejb.session.JMSTopicManager;
            import com.navineo.hora.ejb.session.suivi.ISuiviControleurDonneesTRFacadeLocal;
            import com.navineo.hora.ejb.session.suivi.gses.GestionDeServiceFacadeLocal;
            import com.navineo.hora.ejb.session.suivi.localisation.GestionLocalisationFacadeLocal;
            import com.navineo.hora.impacts.suivi.ImpactsDonneesSuivi;
            import com.navineo.sa.bo.message.EnumMessage;
            import com.navineo.sa.bo.message.GSDemandeVacation;
            import com.navineo.sa.bo.message.GSEtatService;
            import com.navineo.sa.bo.message.GSFinExploitationVehicule;
            import com.navineo.sa.bo.message.LocEtat;
            import com.navineo.sa.bo.message.LocValeur;
            import com.navineo.sa.ejb.mdb.DepuisEmbarqueMDBManagement;
            import com.navineo.sa.util.common.IObjectExchange;
            import com.navineo.sa.util.common.MessageVehicule;
            
            
            @Service (objectName = "jboss:custom=NameXXX")
            @MessageDriven (activationConfig={
             @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Topic"),
             @ActivationConfigProperty(propertyName="destination" , propertyValue="topic/DepuisEmbarqueDestination"),
             @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue="Auto-Acknowledge")
             //,@ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1")
             },messageListenerInterface=MessageListener.class
            )
            @Clustered
            @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
            //@Service (objectName = "NAVINEO.SA:service=FFF")//CLA On met SA meme si des raisons de dependances font qu'il est dans HORA
            //@PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=1, timeout=5000)
            public class DepuisEmbarqueMDB /*extends ComEmbarquesMDBManagement*/ implements MessageListener, DepuisEmbarqueMDBManagement
            {
             private transient Logger log = LogManager.getLogger("SA.ejb.DepuisEmbarqueMDB");
            
             @EJB
             private GestionDeServiceFacadeLocal gestionDeServiceTRFacade;
            
             @EJB
             private GestionLocalisationFacadeLocal gestionLocalisationFacade;
            
             @EJB
             private ISuiviControleurDonneesTRFacadeLocal suiviControleurDonneesTRFacade;
            
             /**
             * Topic JMS
             */
             @Resource( mappedName="topic/AcquitMessageEmarque" )
             private Topic acquitMessageEmbarqueTopicJMS;
            
             /**
             * Topic Factory
             */
             @Resource( mappedName="java:/JmsXA" )
             private TopicConnectionFactory topicConnectionFactory;
            
             /**
             * Topic Manager
             */
             private JMSTopicManager fJmsAcquitMessageEmbarqueManager;
            
             public DepuisEmbarqueMDB () {}
            
             /**
             * Renvoie (et construit au besoin) le topic manager pour la publication de messages JMS vers le topic d'acquittement des msgs embarqués
             */
             private JMSTopicManager getJmsAcquitMessageEmbarqueManager()
             {
             try
             {
             fJmsAcquitMessageEmbarqueManager = new JMSTopicManager( topicConnectionFactory, acquitMessageEmbarqueTopicJMS );
             }
             catch( JMSException e )
             {
             log.error("", e);
             }
             return fJmsAcquitMessageEmbarqueManager;
             }
            
             @Override
             public void onMessage(Message message)
             {
             log.info ( "onMessage/actif: " + actif );
             log.debug("onMessage/message/"+message.getClass().toString());
            
             try
             {
             if ( message instanceof ObjectMessage )
             {
             ObjectMessage objectMessage = (ObjectMessage) message;
             Object o = objectMessage.getObject();
            
             if (o instanceof MessageVehicule)
             {
            
             //
             // IL S AGIT D UN MESSAGE EN PROVENANCE D UN VEHICULE
             //
             MessageVehicule navineoMessage = (MessageVehicule) o;
             ImpactsDonneesSuivi impacts = null;
            
             String numeroParcSender = navineoMessage.getNumeroParc();
             int idCentreExploitation = navineoMessage.getIdCentreExploitation();
            
             log.debug("DepuisEmbarqueMDB/onMessage/navineoMessage:");
             log.debug(navineoMessage);
            
             EnumMessage typeMessage = navineoMessage.getTypeMessage();
            
            // fLogInterface.info("DepuisEmbarqueTopic : traitement du message ["+typeMessage.name()+"]");
            
             log.debug("DepuisEmbarqueMDB/onMessage/Numéro de Centre d'Exploitation : "+ idCentreExploitation +"Numéro Parc Véhicule : "+numeroParcSender );
            
             IObjectExchange navineoObject = navineoMessage.getObject();
             if(navineoObject != null)
             {
             log.info(navineoObject.dump());
             }
            
             if ( typeMessage == EnumMessage.GSDV )
             {
             gestionDeServiceTRFacade.receptionDemandeVacation((GSDemandeVacation)navineoObject);
             }
             else if ( typeMessage == EnumMessage.GSES )
             {
             impacts = gestionDeServiceTRFacade.receptionEtatService((GSEtatService)navineoObject);
            
             }
             else if ( typeMessage == EnumMessage.GSFDE )
             {
             impacts = gestionDeServiceTRFacade.receptionFinExploitation((GSFinExploitationVehicule)navineoObject);
            
             }
             else if ( typeMessage == EnumMessage.GSFORCEREP )
             {
             log.debug("onMessage/GSFORCEREP" );
             }
             else if ( typeMessage == EnumMessage.LOCETAT )
             {
             impacts = gestionLocalisationFacade.receptionLOCETAT((LocEtat)navineoObject);
             }
             else if ( typeMessage == EnumMessage.LOCVAL )
             {
             impacts = gestionLocalisationFacade.receptionLOCVAL((LocValeur)navineoObject);
             }
             else
             {
             log.error("Type de message ["+typeMessage.name()+"] non attendu sur le topic DepuisEmbarqueTopic");
             }
            
             getJmsAcquitMessageEmbarqueManager().publish(new AcquitMessageEmbarque(typeMessage, objectMessage.getJMSMessageID()));
            
             suiviControleurDonneesTRFacade.envoieImpactsAuxMMIs(impacts);
             } // end if( navineoMessage.getTypeElementDistant() == EnumTypeEquipment.VEH )
             else
             {
             // TO DO : TRAITER LES MESSAGES DES AUTRES EQUIPEMENTS
             }
             }
             else
             {
             log.error("Type de message JMS invalide: " + message.getClass().getSimpleName());
             }
             }
             catch (Throwable e)
             {
             log.error(e.getLocalizedMessage(), e);
             }
             }
            
             protected boolean actif = true;
            
            
             @Override
             public void activer()
             {
             actif = true;
             }
            
             @Override
             public void desactiver()
             {
             actif = false;
             }
            
             @Override
             public void create() throws Exception
             {
             log.info ( "____create____" );
             }
            
             @Override
             public void destroy()
             {
             log.info ( "____destroy____" );
             }
            
             @Override
             public void start() throws Exception
             {
             log.info ( "____start____" );
             }
            
             @Override
             public void stop()
             {
             log.info ( "____stop____" );
             }
            }
            

            The management interface:
            package com.navineo.sa.ejb.mdb;
            
            import org.jboss.annotation.ejb.Management;
            
            @Management
            public interface DepuisEmbarqueMDBManagement
            {
             void create() throws Exception;
             void start() throws Exception;
             void stop();
             void destroy();
            
             void activer ();
             void desactiver ();
            }
            




            • 3. Re: Can't get @Service to work
              jaikiran pai Master

               

              "chtimi2" wrote:
              I still cant manage to manage my MDB though(which was the objective i had).


              Could you please explain what you are trying to do? @Service is not meant for a MDB

              • 4. Re: Can't get @Service to work
                ezza ezaezazea Novice

                The debug output is too big to be posted here, i put it on rapidshare:
                http://rapidshare.com/files/213262254/DEBUG_output.html

                • 5. Re: Can't get @Service to work
                  ezza ezaezazea Novice

                  I want to expose a setActive(boolean) management on the MDB to programmatically activate or desactivate it.
                  If !active, onMessage would do nothing.

                  So @Service doesn't work on a MDB?

                  • 6. Re: Can't get @Service to work
                    ezza ezaezazea Novice

                    Sorry i don't see any "edit message" button.
                    I think i'm just going to call an MBean that has the isActive method from the MDB's onMessage instead, and replace the impossible call to the MDB management by a call to the MBean's setActive.
                    Or would that be bad practice?

                    • 7. Re: Can't get @Service to work
                      jaikiran pai Master

                       

                      "chtimi2" wrote:

                      If !active, onMessage would do nothing.

                      That would mean the message delivered to the MDB will be completely lost (i.e. no processing done on the message). Do you really want this? Or do you want to stop the message itself from being delivered to the MDB (this way the message will stay in queue but won't be delivered)



                      • 8. Re: Can't get @Service to work
                        ezza ezaezazea Novice

                        Well you're right it would certainly be better not to waste resources moving around messages that will never be used, if i had a way to deactivate the MDB/unplug it from the topic. Is it possible?

                        My use case is a bit special because the destination this MDB used to listen to was a queue, which was fine since the message had to be consumed on only one node of the cluster.
                        But meanwhile it has appeared that a queue won't do since some new unit test MDPs also listen to this destination. Of course if it's a queue the message can only be consumed once so the test isn't notified and fails. But if it's a standard topic, the MDB will use it on all nodes which isn't right either.

                        So my idea was to use a topic and activate/deactivate the MDB.

                        • 9. Re: Can't get @Service to work
                          jaikiran pai Master

                          Which version of JBossAS?

                          • 10. Re: Can't get @Service to work
                            ezza ezaezazea Novice

                            I'm using JBoss 4.2.3.GA (with JBM 1.4.2.GA-SP1 if it changes anything)

                            • 12. Re: Can't get @Service to work
                              jaikiran pai Master

                              In that case, there are MBeans for MDBs which provide this already. Access the jmx-console (http://localhost:8080/jmx-console) and you will find MBean(s) similar to this:

                              binding=message-driven-bean,jndiName=local/MDBExample@1421788223,plugin=invoker,service=EJB


                              I don't have access to 4.2.3 system right now, so i can't tell you the MBean name for sure. Click on that MBean in the jmx-console and you should be able to see the necessary methods

                              • 13. Re: Can't get @Service to work
                                ezza ezaezazea Novice

                                Aaaaah it works!
                                Thanks a lot, i hadn't thought of using the standard start/stop method of the MDB's MBean.

                                • 14. Re: Can't get @Service to work
                                  ezza ezaezazea Novice

                                  One more thing while you're here, what is the cleanest way to have the MDB inactive on startup? So that it's start/stop is entirely controlled by my explicit calls to the MBean.

                                  1 2 Previous Next