SessionAwareMessageListener supports generic declaration of concrete JMS Message type

This commit is contained in:
Juergen Hoeller 2009-03-23 11:19:25 +00:00
parent 147709fa9e
commit c82a66b59c
3 changed files with 8 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ import javax.jms.Session;
* @see org.springframework.jms.listener.endpoint.JmsMessageEndpointManager
* @see javax.jms.MessageListener
*/
public interface SessionAwareMessageListener {
public interface SessionAwareMessageListener<M extends Message> {
/**
* Callback for processing a received JMS message.
@ -51,6 +51,6 @@ public interface SessionAwareMessageListener {
* @param session the underlying JMS Session (never <code>null</code>)
* @throws JMSException if thrown by JMS methods
*/
void onMessage(Message message, Session session) throws JMSException;
void onMessage(M message, Session session) throws JMSException;
}

View File

@ -128,7 +128,8 @@ import org.springframework.util.ObjectUtils;
* @see org.springframework.jms.listener.SessionAwareMessageListener
* @see org.springframework.jms.listener.AbstractMessageListenerContainer#setMessageListener
*/
public class MessageListenerAdapter implements MessageListener, SessionAwareMessageListener, SubscriptionNameProvider {
public class MessageListenerAdapter
implements MessageListener, SessionAwareMessageListener<Message>, SubscriptionNameProvider {
/**
* Out-of-the-box value for the default listener method: "handleMessage".
@ -318,6 +319,7 @@ public class MessageListenerAdapter implements MessageListener, SessionAwareMess
* @param session the JMS session to operate on
* @throws JMSException if thrown by JMS API methods
*/
@SuppressWarnings("unchecked")
public void onMessage(Message message, Session session) throws JMSException {
// Check whether the delegate is a MessageListener impl itself.
// In that case, the adapter will simply act as a pass-through.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -52,7 +52,7 @@ import org.springframework.remoting.support.RemoteInvocationResult;
* @see JmsInvokerProxyFactoryBean
*/
public class JmsInvokerServiceExporter extends RemoteInvocationBasedExporter
implements SessionAwareMessageListener, InitializingBean {
implements SessionAwareMessageListener<Message>, InitializingBean {
private MessageConverter messageConverter = new SimpleMessageConverter();