[jboss-user] [JBoss Seam] - Re: Injection not working when using thirdparty JMS library

raoul.schmidiger do-not-reply at jboss.com
Wed Dec 5 05:53:44 EST 2007


Hi Pete,

No, it is not declared as a MDB. It is clear to me, that this is not the usual way to go. But what about thirdparty libs in general, well yes, that start off some threads and do callbacks on my code? I know it is not considered "good" practice but then again... 

@Stateful
  | @Name("jmsListener")
  | @Scope (ScopeType.SESSION)
  | public class JmsMessageListener implements MessageListener, IJmsMessageListener {
  | 	
  | 	// factor out into properties
  | 	private static final String SEND_QUEUE = "IN";
  | 	private static final String RECEIVE_QUEUE = "OUT";
  | 
  | 	private ASyncSender asyncSender;
  | 	//private SyncSender syncSender;
  | 
  | 	@In(create=true, required=true)
  | 	private IUnderlyingService underlyingService;
  | 	private IUnderlyingService underlyingServiceHack;
  | 
  | 	@In(create=true, required=true)
  | 	private IConnectionProvider connectionFactoryProvider;
  | 
  | 	public JmsMessageListener() {
  | 		System.out.println("constructor: JmsMessageListener");
  | 	}
  | 
  | 	@Remove @Destroy
  | 	public void remove() {
  | 		System.out.println("destroyed: JmsMessageListener");
  | 	}
  | 
  | 	@Create
  | 	public void init() throws JMSException {
  | 		MessageSessionProvider messageSessionProvider = new MessageSessionProvider(connectionFactoryProvider.getConnectionFactory());
  | 		asyncSender = new ASyncSender(messageSessionProvider, SEND_QUEUE);
  | 		messageSessionProvider.setMessageListener(RECEIVE_QUEUE, this);
  | 		//syncSender = new SyncSender(messageSessionProvider, SEND_QUEUE);
  | 		messageSessionProvider.startConnection();
  | 		
  | 		if(underlyingService == null) {
  | 			System.out.println("at init, underlyingService is null");
  | 		} else {
  | 			System.out.println("at init, underlyingService is not null");
  | 			underlyingServiceHack = underlyingService;
  | 		}
  | 	}
  | 
  | 	@Override
  | 	public void onMessage(Message message) {
  | 		if(message instanceof ObjectMessage) {
  | 			try {
  | 				System.out.println("got a message: " + ((ObjectMessage) message).getObject());
  | 			} catch (JMSException e) {
  | 				e.printStackTrace();
  | 			}
  | 		} else {
  | 			System.out.println("got a message: " + message);
  | 		}
  | 		if (message instanceof ObjectMessage) {
  | 			ObjectMessage objectMessage = (ObjectMessage) message;
  | 			try {
  | 				//...
  | 				}
  | 			} catch (JMSException e) {
  | 				// TODO Auto-generated catch block
  | 				e.printStackTrace();
  | 			}
  | 		}
  | 	}
  | 	
  | }
  | 

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

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



More information about the jboss-user mailing list