[jboss-user] [EJB 3.0] - Re: Can't get @Service to work

chtimi2 do-not-reply at jboss.com
Wed Mar 25 04:10:37 EDT 2009


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")
  |     //, at 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 ();
  | }
  | 



View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4220819#4220819

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4220819



More information about the jboss-user mailing list