|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2000, 2023, Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. |
3 | 3 | *
|
4 | 4 | * Licensed under the Universal Permissive License v 1.0 as shown at
|
5 | 5 | * https://oss.oracle.com/licenses/upl.
|
6 | 6 | */
|
7 | 7 | package com.tangosol.internal.net.topic.impl.paged;
|
8 | 8 |
|
| 9 | +import com.oracle.coherence.common.base.Logger; |
| 10 | +import com.tangosol.internal.net.topic.ChannelAllocationStrategy; |
9 | 11 | import com.tangosol.internal.net.topic.impl.paged.model.PagedTopicSubscription;
|
10 | 12 | import com.tangosol.internal.net.topic.impl.paged.model.SubscriberGroupId;
|
11 | 13 | import com.tangosol.internal.net.topic.impl.paged.model.SubscriberId;
|
@@ -187,6 +189,69 @@ public static boolean hasSubscription(Map<?, ?> configMap, long lSubscriptionId,
|
187 | 189 | return false;
|
188 | 190 | }
|
189 | 191 |
|
| 192 | + /** |
| 193 | + * Returns {@code true} if the specified topic has any registered subscriptions. |
| 194 | + * |
| 195 | + * @param configMap the config map for the service |
| 196 | + * @param sTopic the name of the topic |
| 197 | + * |
| 198 | + * @return {@code true} if the specified topic has any registered subscriptions |
| 199 | + */ |
| 200 | + public static boolean hasSubscriptions(Map<?, ?> configMap, String sTopic) |
| 201 | + { |
| 202 | + return configMap.keySet().stream() |
| 203 | + .filter(key -> key instanceof PagedTopicSubscription.Key) |
| 204 | + .map(PagedTopicSubscription.Key.class::cast) |
| 205 | + .anyMatch(key -> key.getTopicName().equals(sTopic)); |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * Returns the count of subscriptions for the specified topic. |
| 210 | + * |
| 211 | + * @param configMap the config map for the service |
| 212 | + * @param sTopic the name of the topic |
| 213 | + * |
| 214 | + * @return the count of subscriptions for the specified topic |
| 215 | + */ |
| 216 | + public static long getSubscriptionCount(Map<?, ?> configMap, String sTopic) |
| 217 | + { |
| 218 | + return configMap.keySet().stream() |
| 219 | + .filter(key -> key instanceof PagedTopicSubscription.Key) |
| 220 | + .map(PagedTopicSubscription.Key.class::cast) |
| 221 | + .filter(key -> key.getTopicName().equals(sTopic)) |
| 222 | + .count(); |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * Update the channel count and allocations for all subscriptions for a topic. |
| 227 | + * |
| 228 | + * @param configMap the config map to update |
| 229 | + * @param sTopic the name of the topic |
| 230 | + * @param cChannel the new channel count |
| 231 | + * @param strategy the channel allocation strategy |
| 232 | + */ |
| 233 | + @SuppressWarnings("unchecked") |
| 234 | + public static void setChannelCount(Map<?, ?> configMap, String sTopic, int cChannel, ChannelAllocationStrategy strategy) |
| 235 | + { |
| 236 | + Set<PagedTopicSubscription.Key> setKey = configMap.keySet().stream() |
| 237 | + .filter(key -> key instanceof PagedTopicSubscription.Key) |
| 238 | + .map(PagedTopicSubscription.Key.class::cast) |
| 239 | + .filter(key -> key.getTopicName().equals(sTopic)) |
| 240 | + .collect(Collectors.toSet()); |
| 241 | + |
| 242 | + Map<PagedTopicSubscription.Key, PagedTopicSubscription> mapSub = (Map<PagedTopicSubscription.Key, PagedTopicSubscription>) configMap; |
| 243 | + for (PagedTopicSubscription.Key key : setKey) |
| 244 | + { |
| 245 | + PagedTopicSubscription subscription = (PagedTopicSubscription) configMap.get(key); |
| 246 | + if (subscription.getChannelCount() < cChannel) |
| 247 | + { |
| 248 | + Logger.config("Updating channel count for subscription " + key.getGroupName() + " in topic " + sTopic + " to " + cChannel); |
| 249 | + subscription.updateChannelAllocations(strategy, cChannel); |
| 250 | + mapSub.put(key, subscription); |
| 251 | + } |
| 252 | + } |
| 253 | + } |
| 254 | + |
190 | 255 | /**
|
191 | 256 | * Remove configurations for the specified topic name.
|
192 | 257 | *
|
|
0 commit comments