mirror of https://github.com/apache/activemq.git
Add some utility methods that are useful for restoring past subscriptions.
This commit is contained in:
parent
b550fb7742
commit
4b0e3e57ba
|
@ -16,24 +16,59 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.store;
|
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.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.
|
* Used to implement common PersistenceAdapter methods.
|
||||||
*/
|
*/
|
||||||
public class PersistenceAdapterSupport {
|
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>();
|
ArrayList<SubscriptionInfo> rc = new ArrayList<SubscriptionInfo>();
|
||||||
for (ActiveMQDestination destination : pa.getDestinations()) {
|
for (ActiveMQDestination destination : adapter.getDestinations()) {
|
||||||
if (destination.isTopic()) {
|
if (destination.isTopic()) {
|
||||||
TopicMessageStore store = pa.createTopicMessageStore((ActiveMQTopic) destination);
|
TopicMessageStore store = adapter.createTopicMessageStore((ActiveMQTopic) destination);
|
||||||
for (SubscriptionInfo sub : store.getAllSubscriptions()) {
|
for (SubscriptionInfo sub : store.getAllSubscriptions()) {
|
||||||
if (clientId == sub.getClientId() || clientId.equals(sub.getClientId())) {
|
if (clientId == sub.getClientId() || clientId.equals(sub.getClientId())) {
|
||||||
rc.add(sub);
|
rc.add(sub);
|
||||||
|
@ -44,4 +79,85 @@ public class PersistenceAdapterSupport {
|
||||||
return rc;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue