Class SideCache

java.lang.Object
overit.geocall.cluster.redis.SideCache

@Service @DependsOn("deploymentInfo") public class SideCache extends Object
this class provides static access to a Side Cache Redis implementation. it provides starts and stop capabilities, access to an instance of Cache backed by a RedisDB and methods for putting and peeking data, for health get and list
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static Lazy<Cache>
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static overit.geocall.cluster.slot.Slot
    acquireSlot(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.Slot
    awaitAcquireSlot(String name, int many)
    Acquires and returns a Slot for the whole cluster, so that only some node inside the cluster at a time can execute the associated task.
    static overit.geocall.cluster.slot.Slot
    awaitAcquireSlot(String name, int many, long timeout, TemporalUnit unit)
    Acquires and returns a Slot for the whole cluster, so that only some node inside the cluster at a time can execute the associated task.
    static void
    Remove the information related to a web session from Redis
    static void
    clearSessionInfo(overit.geocall.servlet.IWebSession session)
    Remove the information related to a web session from Redis
    static overit.geocall.cluster.slot.BadgeKit
    This method returns an instance of BadgeKit.
    static Cache
     
    retrieves a list of health-records, for all the active nodes of the cluster
    static String
     
    static String
     
    static Map<String,Object>
     
     
    void
    handleContextClosed(org.springframework.context.event.ContextClosedEvent ignored)
     
    void
    handleContextStarted(org.springframework.boot.context.event.ApplicationStartedEvent event)
     
    static void
    onMessage(overit.geocall.cluster.redis.MessageHandler handler)
    Records a listener on receipt of a message from the redis server.
    static Object
    peek(String key)
    peeks and removes atomically an object from the storage
    static void
    put(String key, String serialization, Object o, long ttl)
    stores a temporary complex java object serializing it with a specific serialization method.
    Retrieve the information related all session stored into Redis.
    static Map<String,Object>
    Retrieve the information related a specific session from Redis.
    static void
    send(overit.geocall.cluster.redis.Message message)
    Send a new message to all the listeners attached to the current cluster channel.
    static void
    send(overit.geocall.cluster.redis.Message message, Boolean meToo)
    Send a new message to all the listeners attached to the current cluster channel.
    void
    setContext(org.springframework.context.ApplicationContext context)
     
    static void
    stores a health-record lasting for "foundation.cluster.heartbeatDuration" milliseconds
    static void
    updateSessionInfo(overit.geocall.servlet.IWebSession session)
    Store the information related to a web session into Redis

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • SideCache

      public SideCache()
  • Method Details

    • getKey

      public static String getKey(String key)
    • 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

      @Bean @DependsOn("deploymentInfo") @Lazy public static Cache getCache()
      Returns:
      the cache instance that can be used to store/invalidate/retrieve the object inside the side cache
    • setHealth

      public static void setHealth(Map<String,String> m)
      stores a health-record lasting for "foundation.cluster.heartbeatDuration" milliseconds
      Parameters:
      m - the key-value map of the record to be stored
    • getHealth

      public static List<Map<String,String>> 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

      public static void clearSessionInfo(String sessionId)
      Remove the information related to a web session from Redis
      Parameters:
      sessionId - session identifier
    • retrieveWebSessionInfo

      public static List<Map<String,Object>> 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

      public static Map<String,Object> retrieveWebSessionInfo(String sessionId)
      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

      public static String getMemoryDoctor()
      Returns:
      the redis specific MemoryDoctor information
    • getMemoryStats

      public static Map<String,Object> getMemoryStats()
      Returns:
      the redis specific memory-stats data
    • put

      public static void put(String key, String serialization, Object o, long ttl)
      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 object
      serialization - the serialization algorithm as specified in Serializer factory documentation
      o - the object to be stored
      ttl - the time-to-leave of the store object
    • peek

      public static Object peek(String key)
      peeks and removes atomically an object from the storage
      Parameters:
      key - the name of the object
      Returns:
      the deserialized object
    • acquireSlot

      public static overit.geocall.cluster.slot.Slot acquireSlot(String name, int many)
      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 limitation
      many - 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 a Slot for 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 Slot must be closed (i.e. it has to implement Closeable) to release the slot and allow other threads, all over the cluster, to continue

      .
      Parameters:
      name - String about the name of the Slot to create and return.
      many - the parallelism of the slot
      Returns:
      a Slot for 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 a Slot for 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 Slot must be closed (i.e. it has to implement Closeable) to release the slot and allow other threads, all over the cluster, to continue

      .
      Parameters:
      name - String about the name of the Slot to create and return.
      many - the parallelism of the slot
      timeout - the maximum time to wait. 0 means it waits forever
      unit - the unit of date-time the timeout parameter refers to
      Returns:
      a Slot for 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 of BadgeKit. The BadgeKit enables 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 BadgeKit if the badge provider is available; otherwise, it returns null.
    • send

      public static void send(overit.geocall.cluster.redis.Message message) throws Exception
      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 channel
      Exception - 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 sent
      meToo - flag to send the message to the handlers of the current connector
      Throws:
      IllegalStateException - if you have not subscribed to any channel
      Exception - 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. The start() 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

      public static Optional<RedisDB> getRedisDB()
      Returns:
      the Optional instance of the Redis DB server