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.
- Loading branch information
Showing
6 changed files
with
109 additions
and
79 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...kom/eni/pandora/horizon/cache/listener/AbstractHazelcastJsonEntryMapEventBroadcaster.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,51 @@ | ||
package de.telekom.eni.pandora.horizon.cache.listener; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.hazelcast.core.EntryEvent; | ||
import com.hazelcast.core.HazelcastJsonValue; | ||
import com.hazelcast.map.listener.EntryAddedListener; | ||
import com.hazelcast.map.listener.EntryEvictedListener; | ||
import com.hazelcast.map.listener.EntryRemovedListener; | ||
import com.hazelcast.map.listener.EntryUpdatedListener; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
|
||
import java.util.Optional; | ||
|
||
@Slf4j | ||
public abstract class AbstractHazelcastJsonEntryMapEventBroadcaster<T extends AbstractHazelcastJsonEvent<?>> implements EntryAddedListener<String, HazelcastJsonValue>, | ||
EntryRemovedListener<String, HazelcastJsonValue>, | ||
EntryUpdatedListener<String, HazelcastJsonValue>, | ||
EntryEvictedListener<String, HazelcastJsonValue> { | ||
|
||
protected final ObjectMapper mapper; | ||
|
||
private final ApplicationEventPublisher applicationEventPublisher; | ||
|
||
public AbstractHazelcastJsonEntryMapEventBroadcaster(ObjectMapper mapper, ApplicationEventPublisher applicationEventPublisher) { | ||
this.mapper = mapper; | ||
this.applicationEventPublisher = applicationEventPublisher; | ||
} | ||
|
||
protected abstract Optional<T> map(EntryEvent<String, HazelcastJsonValue> entryEvent); | ||
|
||
@Override | ||
public void entryAdded(EntryEvent<String, HazelcastJsonValue> entryEvent) { | ||
map(entryEvent).ifPresent(applicationEventPublisher::publishEvent); | ||
} | ||
|
||
@Override | ||
public void entryEvicted(EntryEvent<String, HazelcastJsonValue> entryEvent) { | ||
map(entryEvent).ifPresent(applicationEventPublisher::publishEvent); | ||
} | ||
|
||
@Override | ||
public void entryRemoved(EntryEvent<String, HazelcastJsonValue> entryEvent) { | ||
map(entryEvent).ifPresent(applicationEventPublisher::publishEvent); | ||
} | ||
|
||
@Override | ||
public void entryUpdated(EntryEvent<String, HazelcastJsonValue> entryEvent) { | ||
map(entryEvent).ifPresent(applicationEventPublisher::publishEvent); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
...rc/main/java/de/telekom/eni/pandora/horizon/cache/listener/SubscriptionResourceEvent.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,11 @@ | ||
package de.telekom.eni.pandora.horizon.cache.listener; | ||
|
||
import com.hazelcast.core.EntryEvent; | ||
import com.hazelcast.core.HazelcastJsonValue; | ||
import de.telekom.eni.pandora.horizon.kubernetes.resource.SubscriptionResource; | ||
|
||
public class SubscriptionResourceEvent extends AbstractHazelcastJsonEvent<SubscriptionResource> { | ||
public SubscriptionResourceEvent(SubscriptionResource value, SubscriptionResource oldValue, EntryEvent<String, HazelcastJsonValue> entryEvent) { | ||
super(value, oldValue, entryEvent); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...a/de/telekom/eni/pandora/horizon/cache/listener/SubscriptionResourceEventBroadcaster.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,42 @@ | ||
package de.telekom.eni.pandora.horizon.cache.listener; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.hazelcast.core.EntryEvent; | ||
import com.hazelcast.core.HazelcastJsonValue; | ||
import de.telekom.eni.pandora.horizon.kubernetes.resource.SubscriptionResource; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
|
||
import java.util.Optional; | ||
|
||
@Slf4j | ||
public class SubscriptionResourceEventBroadcaster extends AbstractHazelcastJsonEntryMapEventBroadcaster<SubscriptionResourceEvent> { | ||
|
||
public SubscriptionResourceEventBroadcaster(ObjectMapper mapper, ApplicationEventPublisher applicationEventPublisher) { | ||
super(mapper, applicationEventPublisher); | ||
} | ||
|
||
@Override | ||
protected Optional<SubscriptionResourceEvent> map(EntryEvent<String, HazelcastJsonValue> entryEvent) { | ||
try { | ||
SubscriptionResource newValue = null; | ||
SubscriptionResource oldValue = null; | ||
|
||
if (entryEvent.getValue() != null) { | ||
newValue = mapper.readValue(entryEvent.getValue().getValue(), SubscriptionResource.class); | ||
} | ||
|
||
if (entryEvent.getOldValue() != null) { | ||
oldValue = mapper.readValue(entryEvent.getOldValue().getValue(), SubscriptionResource.class); | ||
} | ||
|
||
|
||
return Optional.of(new SubscriptionResourceEvent(newValue, oldValue, entryEvent)); | ||
} catch (JsonProcessingException e) { | ||
log.error(e.getMessage(), e); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
} |
74 changes: 0 additions & 74 deletions
74
...main/java/de/telekom/eni/pandora/horizon/cache/service/JsonCacheServiceEntryListener.java
This file was deleted.
Oops, something went wrong.
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