Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


How to know an object is replicated?

  • Minoru Nitta
    Minoru Nitta


    I am implementing distributed object replication with ehcahce, and I have a question.

    I would like to be notified when an object is newly replicated from other peers.
    I looked at JavaDoc but it seems to me that it is not possible to implement such

    Does anyone know how to do that? Is there any listener interface to implement?

    Thank you.


    • Andrew Liles
      Andrew Liles

      AFAIK you are correct; you can listen to cache put events (see http://ehcache.org/documentation/cache_event_listeners.html\)  but you cannot distinguish that they came from a peer or the current cache.  However this is easily achieved, here are two options for you to consider:

      1. Make the value passed in the Element are rich object that includes the identifier of the JVM/host/peer that created the data.  Therefore, having been notified about a cache put, you could distinguish whether it came from "itself".

      2. If you are using JMS replication, this is implemented using a JMS topic.  JMS topics can be listened to by any number of clients - the ehcache implementation adds a listener per Cache Manager.  You could implement your own listener, quite outside of Ehcache, and notice when data is being replicated.  (Same problem as in 1 - if you wish to notice that the replication was caused by a remote peer, you need to pass an attribute in the Element's value object).

    • Minoru Nitta
      Minoru Nitta

      Hi Andrew

      Thank you for your thoughtful ideas. I didn't notice that.
      I'll try to do that.