generated from telekom/reuse-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCallbackUrlCache.java
59 lines (46 loc) · 2.38 KB
/
CallbackUrlCache.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2024 Deutsche Telekom IT GmbH
//
// SPDX-License-Identifier: Apache-2.0
package de.telekom.horizon.comet.cache;
import de.telekom.eni.pandora.horizon.cache.service.JsonCacheService;
import de.telekom.eni.pandora.horizon.cache.util.Query;
import de.telekom.eni.pandora.horizon.exception.JsonCacheException;
import de.telekom.eni.pandora.horizon.kubernetes.resource.SubscriptionResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* The {@code CallbackUrlCache} class provides a service for managing callback properties associated with
* subscriptionIds. It uses an in-memory ConcurrentHashMap for efficient and thread-safe storage of callback properties.
* This class is intended to be used in scenarios where callback information needs to be cached and quickly accessed.
*/
@Service
@Slf4j
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class CallbackUrlCache {
private final JsonCacheService<SubscriptionResource> subscriptionCache;
public CallbackUrlCache(JsonCacheService<SubscriptionResource> subscriptionCache) {
this.subscriptionCache = subscriptionCache;
}
/**
* Retrieves the callback properties associated with the given subscriptionId.
*
* @param subscriptionId The subscriptionId for which to retrieve callback properties.
* @return The DeliveryTargetInformation object associated with the subscriptionId, or null if not found.
*/
public Optional<DeliveryTargetInformation> getDeliveryTargetInformation(String subscriptionId) {
Optional<SubscriptionResource> subscription = Optional.empty();
try {
subscription = subscriptionCache.getByKey(subscriptionId);
} catch (JsonCacheException e) {
log.error("Error occurred while executing query on JsonCacheServe", e);
}
return subscription.map(subscriptionResource -> new DeliveryTargetInformation
(subscriptionResource.getSpec().getSubscription().getCallback(),
subscriptionResource.getSpec().getSubscription().isCircuitBreakerOptOut(),
subscriptionResource.getSpec().getSubscription().getRetryableStatusCodes()));
}
}