generated from telekom/reuse-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add autoconfig for the JsonCache based subscription-cache
- Loading branch information
1 parent
4da14c2
commit c201362
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...n/java/de/telekom/eni/pandora/horizon/autoconfigure/cache/JsonCacheAutoconfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.telekom.eni.pandora.horizon.autoconfigure.cache; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.hazelcast.core.HazelcastInstance; | ||
import com.hazelcast.core.HazelcastJsonValue; | ||
import com.hazelcast.map.IMap; | ||
import de.telekom.eni.pandora.horizon.cache.service.JsonCacheService; | ||
import de.telekom.eni.pandora.horizon.kubernetes.resource.SubscriptionResource; | ||
import de.telekom.jsonfilter.operator.Operator; | ||
import de.telekom.jsonfilter.serde.OperatorDeserializer; | ||
import de.telekom.jsonfilter.serde.OperatorSerializer; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
public class JsonCacheAutoconfiguration { | ||
|
||
private static final String SUBSCRIPTION_RESOURCE_V1 = "subscriptions.subscriber.horizon.telekom.de.v1"; | ||
|
||
@Bean | ||
public JsonCacheService<SubscriptionResource> subscriptionCache(HazelcastInstance hazelcastInstance) { | ||
var module = new SimpleModule(); | ||
module.addSerializer(Operator.class, new OperatorSerializer()); | ||
module.addDeserializer(Operator.class, new OperatorDeserializer()); | ||
|
||
var mapper = new ObjectMapper(); | ||
mapper.registerModule(module); | ||
|
||
IMap<String, HazelcastJsonValue> map = hazelcastInstance.getMap(SUBSCRIPTION_RESOURCE_V1); | ||
return new JsonCacheService<>(SubscriptionResource.class, map, mapper); | ||
} | ||
|
||
} |