com.tangosol.internal.net.topic.impl.paged.PagedTopicConfigMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of coherence Show documentation
Show all versions of coherence Show documentation
Oracle Coherence Community Edition
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/
package com.tangosol.internal.net.topic.impl.paged;
import com.tangosol.internal.net.topic.impl.paged.model.PagedTopicSubscription;
import com.tangosol.internal.net.topic.impl.paged.model.SubscriberGroupId;
import com.tangosol.internal.net.topic.impl.paged.model.SubscriberId;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* A config map utility class for a {@link com.tangosol.net.PagedTopicService}.
*
* @author Jonathan Knight
* @since 22.06.4
*/
public abstract class PagedTopicConfigMap
{
/**
* Return a {@link Set} of topic names known to this config map.
*
* @return a {@link Set} of topic names known to this config map
*/
public static Set getTopicNames(Map, ?> configMap)
{
return configMap.keySet().stream()
.filter(key -> key instanceof String)
.map(String.class::cast)
.collect(Collectors.toSet());
}
/**
* Return a {@link Set} of {@link SubscriberGroupId subscriber group identifiers}
* for a specific topic known to this config map.
*
* @param sTopicName the name of the topic to get the groups for
*
* @return a {@link Set} of {@link SubscriberGroupId subscriber group identifiers}
* for a specific topic known to this config map
*/
public static Set getSubscriberGroups(Map, ?> configMap, String sTopicName)
{
return configMap.keySet().stream()
.filter(v -> v instanceof PagedTopicSubscription.Key)
.map(PagedTopicSubscription.Key.class::cast)
.filter(key -> key.getTopicName().equals(sTopicName))
.map(PagedTopicSubscription.Key::getGroupId)
.collect(Collectors.toSet());
}
/**
* Return a {@link Set} of {@link SubscriberId subscriber identifiers} for subscribers
* that sre subscribed to a specific subscriber group for a specific topic known to
* this config map.
*
* @param sTopicName the name of the topic to get the groups for
*
* @return a {@link Set} of {@link SubscriberId subscriber identifiers} for subscribers
* that sre subscribed to a specific subscriber group for a specific topic known to
* this config map
*/
public static Set getSubscribers(Map, ?> configMap, String sTopicName, SubscriberGroupId groupId)
{
PagedTopicSubscription subscription = getSubscription(configMap, sTopicName, groupId);
if (subscription != null)
{
return new HashSet<>(subscription.getSubscribers().values());
}
return Collections.emptySet();
}
/**
* Return an {@link Iterable} of {@link PagedTopicSubscription subscriptions}
* known to this config map.
*
* @return an {@link Iterable} of {@link PagedTopicSubscription subscriptions}
* known to this config map
*/
public static Iterable getSubscriptions(Map, ?> configMap)
{
return configMap.values().stream()
.filter(v -> v instanceof PagedTopicSubscription)
.map(PagedTopicSubscription.class::cast)
.collect(Collectors.toList());
}
/**
* Update this config map with the specified {@link PagedTopicSubscription subscription}.
*
* @param subscription the {@link PagedTopicSubscription subscription} to update
*/
public static void updateSubscription(Map