Package overit.geocall.cluster.redis
Class SideCache
java.lang.Object
overit.geocall.cluster.redis.SideCache
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic overit.geocall.cluster.slot.SlotacquireSlot(String name, int many) acquires a slot for the whole cluster for limiting the parallelism of the execution of a task.static overit.geocall.cluster.slot.SlotawaitAcquireSlot(String name, int many) Acquires and returns aSlotfor the whole cluster, so that only some node inside the cluster at a time can execute the associated task.static overit.geocall.cluster.slot.SlotawaitAcquireSlot(String name, int many, long timeout, TemporalUnit unit) Acquires and returns aSlotfor the whole cluster, so that only some node inside the cluster at a time can execute the associated task.static voidclearSessionInfo(String sessionId) Remove the information related to a web session from Redisstatic voidclearSessionInfo(overit.geocall.servlet.IWebSession session) Remove the information related to a web session from Redisstatic overit.geocall.cluster.slot.BadgeKitThis method returns an instance ofBadgeKit.static CachegetCache()retrieves a list of health-records, for all the active nodes of the clusterstatic Stringstatic StringvoidhandleContextClosed(org.springframework.context.event.ContextClosedEvent ignored) voidhandleContextStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) static voidonMessage(overit.geocall.cluster.redis.MessageHandler handler) Records a listener on receipt of a message from the redis server.static Objectpeeks and removes atomically an object from the storagestatic voidstores a temporary complex java object serializing it with a specific serialization method.Retrieve the information related all session stored into Redis.retrieveWebSessionInfo(String sessionId) Retrieve the information related a specific session from Redis.static voidsend(overit.geocall.cluster.redis.Message message) Send a new message to all the listeners attached to the current cluster channel.static voidSend a new message to all the listeners attached to the current cluster channel.voidsetContext(org.springframework.context.ApplicationContext context) static voidstores a health-record lasting for "foundation.cluster.heartbeatDuration" millisecondsstatic voidupdateSessionInfo(overit.geocall.servlet.IWebSession session) Store the information related to a web session into Redis
-
Field Details
-
SIDE_CACHE_ROOT
- See Also:
-
cache
-
-
Constructor Details
-
SideCache
public SideCache()
-
-
Method Details
-
getKey
-
setContext
@Autowired public void setContext(org.springframework.context.ApplicationContext context) -
handleContextStarted
@Order(0) @EventListener public void handleContextStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) -
handleContextClosed
@EventListener public void handleContextClosed(org.springframework.context.event.ContextClosedEvent ignored) -
getCache
- Returns:
- the cache instance that can be used to store/invalidate/retrieve the object inside the side cache
-
setHealth
stores a health-record lasting for "foundation.cluster.heartbeatDuration" milliseconds- Parameters:
m- the key-value map of the record to be stored
-
getHealth
retrieves a list of health-records, for all the active nodes of the cluster- Returns:
- a list of health records, one for each active node on the cluster. If no health information can be fetched from any node, it returns and empty list;
-
updateSessionInfo
public static void updateSessionInfo(overit.geocall.servlet.IWebSession session) Store the information related to a web session into Redis- Parameters:
session- instance of the web session
-
clearSessionInfo
public static void clearSessionInfo(overit.geocall.servlet.IWebSession session) Remove the information related to a web session from Redis- Parameters:
session- instance of the web session
-
clearSessionInfo
Remove the information related to a web session from Redis- Parameters:
sessionId- session identifier
-
retrieveWebSessionInfo
Retrieve the information related all session stored into Redis.- Returns:
- the list containing all the information related the all web sessions. If there's no session info stored, it returns an empty list.
-
retrieveWebSessionInfo
Retrieve the information related a specific session from Redis.- Parameters:
sessionId- web session identifier- Returns:
- the map containing all the information related the web session. If there's no information for the passed id, it returns an empty map.
-
getMemoryDoctor
- Returns:
- the redis specific MemoryDoctor information
-
getMemoryStats
- Returns:
- the redis specific memory-stats data
-
put
stores a temporary complex java object serializing it with a specific serialization method. Also, the serialization method is stored so that it can be used to deserialize the object- Parameters:
key- the stored name of the objectserialization- the serialization algorithm as specified inSerializerfactory documentationo- the object to be storedttl- the time-to-leave of the store object
-
peek
peeks and removes atomically an object from the storage- Parameters:
key- the name of the object- Returns:
- the deserialized object
-
acquireSlot
acquires a slot for the whole cluster for limiting the parallelism of the execution of a task. The slot must be closed (i.e.Closeable) to release the slot and to admit other thread all over the cluster, to execute a similar task- Parameters:
name- the name of the slot. Other tasks can use the same name to undergo to the slot limitationmany- the parallelism of the slot- Returns:
- a Closeable reference that must be closed to release the slot and to admit other thread all over the cluster, to execute a similar task
-
awaitAcquireSlot
public static overit.geocall.cluster.slot.Slot awaitAcquireSlot(String name, int many) throws TimeoutException Acquires and returns aSlotfor the whole cluster, so that only some node inside the cluster at a time can execute the associated task. The other nodes will wait that the slot is released before they can continue.The
.Slotmust be closed (i.e. it has to implementCloseable) to release the slot and allow other threads, all over the cluster, to continue- Parameters:
name-Stringabout the name of theSlotto create and return.many- the parallelism of the slot- Returns:
- a
Slotfor the whole cluster, so that only some nodes within the cluster at a time can execute the associated task. - Throws:
TimeoutException- exception thrown in case, after the timeout set, no locking Slot has been acquired.
-
awaitAcquireSlot
public static overit.geocall.cluster.slot.Slot awaitAcquireSlot(String name, int many, long timeout, TemporalUnit unit) throws TimeoutException Acquires and returns aSlotfor the whole cluster, so that only some node inside the cluster at a time can execute the associated task. The other nodes will wait that the slot is released before they can continue up until a maximum timeout period.The
.Slotmust be closed (i.e. it has to implementCloseable) to release the slot and allow other threads, all over the cluster, to continue- Parameters:
name-Stringabout the name of theSlotto create and return.many- the parallelism of the slottimeout- the maximum time to wait. 0 means it waits foreverunit- the unit of date-time the timeout parameter refers to- Returns:
- a
Slotfor the whole cluster, so that only some nodes within the cluster at a time can execute the associated task. - Throws:
TimeoutException- exception thrown in case, after the timeout set, no locking Slot has been acquired.
-
getBadgeKit
public static overit.geocall.cluster.slot.BadgeKit getBadgeKit()This method returns an instance ofBadgeKit. TheBadgeKitenables the retrieval of badges, which are special objects designed to ensure controlled access to specific resources. By using badges, one can implement distributed locking mechanisms that enforce restricted access policies. In essence, badges act as keys that control access to various parts of a system, thereby helping to manage concurrent operations across a distributed environment.- Returns:
- an instance of
BadgeKitif the badge provider is available; otherwise, it returns null.
-
send
Send a new message to all the listeners attached to the current cluster channel. The handlers of the current connector will not receive any notification.- Parameters:
message- instance of the message to sent- Throws:
IllegalStateException- if you have not subscribed to any channelException- in case of any error during the sending
-
send
public static void send(overit.geocall.cluster.redis.Message message, Boolean meToo) throws Exception Send a new message to all the listeners attached to the current cluster channel. It possible to send a notification to the handlers of the current connector or not.- Parameters:
message- instance of the message to sentmeToo- flag to send the message to the handlers of the current connector- Throws:
IllegalStateException- if you have not subscribed to any channelException- in case of any error during the sending
-
onMessage
public static void onMessage(overit.geocall.cluster.redis.MessageHandler handler) Records a listener on receipt of a message from the redis server. Thestart()method must be called before the registration, otherwise no notification will be received.- Parameters:
handler- instance of the listener that will be notified on every message
-
getRedisDB
- Returns:
- the
Optionalinstance of the Redis DB server
-