You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ha...@apache.org on 2014/12/18 00:36:26 UTC
[11/17] activemq git commit:
https://issues.apache.org/jira/browse/AMQ-5290
https://issues.apache.org/jira/browse/AMQ-5290
Add some utility methods that are useful for restoring past
subscriptions.
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/07bfc1ef
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/07bfc1ef
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/07bfc1ef
Branch: refs/heads/activemq-5.10.x
Commit: 07bfc1ef0e5887e7d4ec7c1e8768d2e0cca4e254
Parents: 9b4f6ac
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed Jul 30 11:31:57 2014 -0400
Committer: Hadrian Zbarcea <ha...@apache.org>
Committed: Wed Dec 17 15:09:45 2014 -0500
----------------------------------------------------------------------
.../store/PersistenceAdapterSupport.java | 134 +++++++++++++++++--
1 file changed, 125 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/07bfc1ef/activemq-broker/src/main/java/org/apache/activemq/store/PersistenceAdapterSupport.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/store/PersistenceAdapterSupport.java b/activemq-broker/src/main/java/org/apache/activemq/store/PersistenceAdapterSupport.java
index aca4574..491c5ed 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/store/PersistenceAdapterSupport.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/store/PersistenceAdapterSupport.java
@@ -16,26 +16,61 @@
*/
package org.apache.activemq.store;
-import org.apache.activemq.command.ActiveMQDestination;
-import org.apache.activemq.command.ActiveMQTopic;
-import org.apache.activemq.command.SubscriptionInfo;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.activemq.command.ActiveMQDestination;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.command.SubscriptionInfo;
+
/**
* Used to implement common PersistenceAdapter methods.
*/
public class PersistenceAdapterSupport {
- static public List<SubscriptionInfo> listSubscriptions(PersistenceAdapter pa, String clientId) throws IOException {
+ private static final DestinationMatcher MATCH_ALL = new AlwaysMatches();
+
+ /**
+ * Provides an interface for a Destination matching object that can be used to
+ * search for specific destinations from a persistence adapter.
+ */
+ public interface DestinationMatcher {
+
+ /**
+ * Given a Destination object, return true if the destination matches some defined
+ * search criteria, false otherwise.
+ *
+ * @param destination
+ * the destination to inspect.
+ *
+ * @return true if the destination matches the target criteria, false otherwise.
+ */
+ boolean matches(ActiveMQDestination destination);
+
+ }
+
+ /**
+ * Searches the set of subscriptions from the given persistence adapter and returns all those
+ * that belong to the given ClientId value.
+ *
+ * @param adapter
+ * the persistence adapter instance to search within.
+ * @param clientId
+ * the client ID value used to filter the subscription set.
+ *
+ * @return a list of all subscriptions belonging to the given client.
+ *
+ * @throws IOException if an error occurs while listing the stored subscriptions.
+ */
+ static public List<SubscriptionInfo> listSubscriptions(PersistenceAdapter adapter, String clientId) throws IOException {
ArrayList<SubscriptionInfo> rc = new ArrayList<SubscriptionInfo>();
- for (ActiveMQDestination destination : pa.getDestinations()) {
- if( destination.isTopic() ) {
- TopicMessageStore store = pa.createTopicMessageStore((ActiveMQTopic) destination);
+ for (ActiveMQDestination destination : adapter.getDestinations()) {
+ if (destination.isTopic()) {
+ TopicMessageStore store = adapter.createTopicMessageStore((ActiveMQTopic) destination);
for (SubscriptionInfo sub : store.getAllSubscriptions()) {
- if(clientId==sub.getClientId() || clientId.equals(sub.getClientId()) ) {
+ if (clientId == sub.getClientId() || clientId.equals(sub.getClientId())) {
rc.add(sub);
}
}
@@ -44,4 +79,85 @@ public class PersistenceAdapterSupport {
return rc;
}
+ /**
+ * Provides a means of querying the persistence adapter for a list of ActiveMQQueue instances.
+ *
+ * @param adapter
+ * the persistence adapter instance to query.
+ *
+ * @return a List<ActiveMQQeue> with all the queue destinations.
+ *
+ * @throws IOException if an error occurs while reading the destinations.
+ */
+ static public List<ActiveMQQueue> listQueues(PersistenceAdapter adapter) throws IOException {
+ return listQueues(adapter, MATCH_ALL);
+ }
+
+ /**
+ * Provides a means of querying the persistence adapter for a list of ActiveMQQueue instances
+ * that match some given search criteria.
+ *
+ * @param adapter
+ * the persistence adapter instance to query.
+ * @param matcher
+ * the DestinationMatcher instance used to find the target destinations.
+ *
+ * @return a List<ActiveMQQeue> with all the matching destinations.
+ *
+ * @throws IOException if an error occurs while reading the destinations.
+ */
+ static public List<ActiveMQQueue> listQueues(PersistenceAdapter adapter, DestinationMatcher matcher) throws IOException {
+ ArrayList<ActiveMQQueue> rc = new ArrayList<ActiveMQQueue>();
+ for (ActiveMQDestination destination : adapter.getDestinations()) {
+ if (destination.isQueue() && matcher.matches(destination)) {
+ rc.add((ActiveMQQueue) destination);
+ }
+ }
+ return rc;
+ }
+
+ /**
+ * Provides a means of querying the persistence adapter for a list of ActiveMQTopic instances.
+ *
+ * @param adapter
+ * the persistence adapter instance to query.
+ *
+ * @return a List<ActiveMQTopic> with all the topic destinations.
+ *
+ * @throws IOException if an error occurs while reading the destinations.
+ */
+ static public List<ActiveMQTopic> listTopics(PersistenceAdapter adapter) throws IOException {
+ return listTopics(adapter, MATCH_ALL);
+ }
+
+ /**
+ * Provides a means of querying the persistence adapter for a list of ActiveMQTopic instances
+ * that match some given search criteria.
+ *
+ * @param adapter
+ * the persistence adapter instance to query.
+ * @param matcher
+ * the DestinationMatcher instance used to find the target destinations.
+ *
+ * @return a List<ActiveMQTopic> with all the matching destinations.
+ *
+ * @throws IOException if an error occurs while reading the destinations.
+ */
+ static public List<ActiveMQTopic> listTopics(PersistenceAdapter adapter, DestinationMatcher matcher) throws IOException {
+ ArrayList<ActiveMQTopic> rc = new ArrayList<ActiveMQTopic>();
+ for (ActiveMQDestination destination : adapter.getDestinations()) {
+ if (destination.isTopic() && matcher.matches(destination)) {
+ rc.add((ActiveMQTopic) destination);
+ }
+ }
+ return rc;
+ }
+
+ private static class AlwaysMatches implements DestinationMatcher {
+
+ @Override
+ public boolean matches(ActiveMQDestination destination) {
+ return true;
+ }
+ }
}