Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created separate APIs for durable subscribers.
- Loading branch information
Showing
9 changed files
with
175 additions
and
78 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
api/src/main/java/org/jboss/seam/jms/DurableMessageManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.jboss.seam.jms; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.jms.Destination; | ||
import javax.jms.MessageListener; | ||
import javax.jms.TopicSubscriber; | ||
|
||
import org.jboss.seam.jms.annotations.Durable; | ||
|
||
@Durable | ||
public interface DurableMessageManager extends MessageManager { | ||
|
||
/** | ||
* Initializes the connection for this DurableMessageManager. | ||
* Sets the ClientID for the underlying {@link javax.jms.Connection} | ||
* | ||
* @param clientId | ||
*/ | ||
public void login(String clientId); | ||
/** | ||
* Creates a topic subscriber with the given ID and binds a message listener to it, if valid. | ||
* | ||
* {@see MessageBuilder.createDurableSubscriber} | ||
* | ||
* @param destination JNDI Location of the topic to subscribe to. | ||
* @param id the client id for the subscriber. This ID should be unique, and should be used to shutdown the listener. | ||
* @param listener The Message Listeners to be bound, if any. | ||
* @return the resulting TopicSubscriber or null if an error occurred. | ||
*/ | ||
public TopicSubscriber createDurableSubscriber(String destination, String id, MessageListener... listeners); | ||
|
||
/** | ||
* Creates a topic subscriber with the given ID and binds a message listener to it, if valid. | ||
* | ||
* {@see MessageBuilder.createDurableSubscriber} | ||
* | ||
* @param destination the existing destination to reference. | ||
* @param id the client id for the subscriber. This ID should be unique, and should be used to shutdown the listener. | ||
* @param listener The Message Listeners to be bound, if any. | ||
* @return the resulting TopicSubscriber or null if an error occurred. | ||
*/ | ||
public TopicSubscriber createDurableSubscriber(Destination destination, String id, MessageListener... listeners); | ||
/** | ||
* Unsubscribes a durable subscriber from the topic, with the given id. | ||
* | ||
* @param id the id of the subscriber. | ||
*/ | ||
public void unsubscribe(String id); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
api/src/main/java/org/jboss/seam/jms/annotations/Durable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.jboss.seam.jms.annotations; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.inject.Qualifier; | ||
|
||
/** Durable represents durable subscribers. | ||
* | ||
* @author johnament | ||
*/ | ||
@Qualifier | ||
@Documented | ||
@Target( { FIELD, METHOD, TYPE, PARAMETER }) | ||
@Retention(RUNTIME) | ||
public @interface Durable { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
impl/src/main/java/org/jboss/seam/jms/DurableMessageManagerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package org.jboss.seam.jms; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.enterprise.context.Dependent; | ||
import javax.inject.Inject; | ||
import javax.jms.Connection; | ||
import javax.jms.ConnectionFactory; | ||
import javax.jms.Destination; | ||
import javax.jms.JMSException; | ||
import javax.jms.MessageListener; | ||
import javax.jms.Session; | ||
import javax.jms.TopicSubscriber; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.jboss.seam.jms.annotations.Durable; | ||
import org.jboss.seam.jms.annotations.Module; | ||
|
||
@Dependent | ||
@Durable | ||
public class DurableMessageManagerImpl | ||
extends MessageManagerImpl | ||
implements DurableMessageManager | ||
{ | ||
|
||
private Logger logger = Logger.getLogger(DurableMessageManagerImpl.class); | ||
@Inject @Module ConnectionFactory connectionFactory; | ||
private Connection connection; | ||
|
||
@Override | ||
@PostConstruct | ||
public void init() { | ||
try{ | ||
connection = connectionFactory.createConnection(); | ||
} catch (JMSException e) { logger.warn("Unable to create connection."); } | ||
} | ||
|
||
@PreDestroy | ||
public void shutdown() { | ||
if(connection != null) { | ||
try{ | ||
connection.close(); | ||
} catch (JMSException e) { logger.warn("Unable to create connection."); } | ||
} | ||
} | ||
|
||
public void login(String clientId) { | ||
try{ | ||
connection.setClientID(clientId); | ||
connection.start(); | ||
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); | ||
} catch (JMSException e) { | ||
logger.warn("Unable to create connection."); | ||
} | ||
} | ||
|
||
@Override | ||
public TopicSubscriber createDurableSubscriber(String destination, String id, MessageListener... listeners) { | ||
TopicSubscriber ts = createDurableSubscriber(destination,id); | ||
if(ts != null && listeners != null && listeners.length > 0) { | ||
for(MessageListener listener : listeners) | ||
try { | ||
ts.setMessageListener(listener); | ||
} catch (JMSException e) { | ||
logger.warn("Unable to map listener "+listener+" to subscriber "+ts,e); | ||
} | ||
} | ||
return ts; | ||
} | ||
|
||
@Override | ||
public TopicSubscriber createDurableSubscriber(Destination destination, String id, MessageListener... listeners) { | ||
TopicSubscriber ts = createDurableSubscriber(destination,id); | ||
if(ts != null && listeners != null && listeners.length > 0) { | ||
for(MessageListener listener : listeners) | ||
try { | ||
ts.setMessageListener(listener); | ||
} catch (JMSException e) { | ||
logger.warn("Unable to map listener "+listener+" to subscriber "+ts,e); | ||
} | ||
} | ||
return ts; | ||
} | ||
|
||
@Override | ||
public void unsubscribe(String id) { | ||
try { | ||
session.unsubscribe(id); | ||
} catch (JMSException e) { | ||
logger.warn("Unable to unsubscribe for id: "+id,e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters