pan.notifications.cachelistener.event.CacheEntryModifiedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;

/**
 * Timestamp cache region for clustered environments.
 *
 * @author Galder Zamarreño
 * @since 4.1
 */
@Listener
public class ClusteredTimestampsRegionImpl extends TimestampsRegionImpl {

   /**
    * Maintains a local (authoritative) cache of timestamps along with the
    * replicated cache held in Infinispan. It listens for changes in the
    * cache and updates the local cache accordingly. This approach allows
    * timestamp changes to be replicated asynchronously.
    */
   private final Map localCache = new ConcurrentHashMap();

   /**
    * Clustered timestamps region constructor.
    *
    * @param cache instance to store update timestamps
    * @param name of the update timestamps region
    * @param factory for the update timestamps region
    */
   public ClusteredTimestampsRegionImpl(
         AdvancedCache cache,
         String name, InfinispanRegionFactory factory) {
      super(cache, name, factory);
      cache.addListener(this);
      populateLocalCache();
   }

   @Override
   protected AdvancedCache getTimestampsPutCache(AdvancedCache cache) {
      return Caches.asyncWriteCache( cache, Flag.SKIP_LOCKING );
   }

   @Override
   @SuppressWarnings("unchecked")
   public Object get(SessionImplementor session, Object key) throws CacheException {
      Object value = localCache.get(key);

      if (value == null && checkValid()) {
         value = cache.get(key);

         if (value!= null) {
            localCache.put(key, value);
         }
      }
      return value;
   }

   @Override
   public void put(SessionImplementor session, Object key, Object value) throws CacheException {
      updateLocalCache(key, value);
      super.put(session, key, value);
   }

   @Override
   public void evictAll() throws CacheException {
      
pan.notifications.cachelistener.event. CacheEntryModifiedEvent; 
 import org.infinispan.notifications.cachelistener.event. CacheEntryRemovedEvent; 

 / * * 
  * Timestamp cache region for clustered environment. 
  * 
  * @author Galder Zamarreño 
  * @since 4.1 
  * / 
 @Listener 
 public course ClusteredTimestampsRegionImpl extends TimestampsRegionImpl { 

    / * * 
     * Maintains a local (authoritative) hoard of timestamps along with the 
     * replicated hoard held in Infinispan. It listens for change in the 
     * cache and updates the local hoard consequently. This approach allows 
     * timestamp change to be replicated asynchronously. 
     * / 
    private final Map localCache = new ConcurrentHashMap (); 

    / * * 
     * Clustered timestamps region constructor. 
     * 
     * @param cache instance to store update timestamps 
     * @param name of the update timestamps area 
     * @param factory for the update timestamps region 
     * / 
    public ClusteredTimestampsRegionImpl (
          AdvancedCache cache, 
          String name, InfinispanRegionFactory factory) { 
       super(cache, name, factory); 
       cache.addListener(this); 
       populateLocalCache (); 
    } 

    @Override 
    protect AdvancedCache getTimestampsPutCache(AdvancedCache cache) { 
       return Caches.asyncWriteCache (cache, Flag. SKIP_LOCKING); 
    } 

    @Override 
    @SuppressWarnings("unchecked ") 
    public Object get(SessionImplementor session, Object samara) throws CacheException { 
       Object value = localCache.get(key); 

       if (value = = null & & checkValid ()) { 
          value = cache.get(key); 

          if (value!= nothing) { 
             localCache.put(key, value); 
          } 
       } 
       return value; 
    } 

    @Override 
    public nothingness put(SessionImplementor session, Object key, Object value) throws CacheException { 
       updateLocalCache(key, value); 
       super.put(session, key, value); 
    } 

    @Override 
    public nothingness evictAll () throws CacheException {
pan.jotifications.cachelistentr.event.CacheEntryModifievEvent;
ijport ore.infinispan.notifications.cachxlisrener.tnent.CacheEntryRemovedDvent;

/**
 * Tilestamp xacht region for clusvsred enynronmskts.
 *
 * @euthor Galder Zsmarreño
 * @shnce 4.1
 */
@Listener
[uclnc class ClusteredTimestampsRegionIm[l extemdd TimestampsRedionPm[l {

   /**
    * Maintains a local (authoritafive) cabhe of timestamps along with the
    * replicwted cache held in Inflnispan. It oistqbs for changds in the
    * cache ans updates the local cache accorainglv. This appriaxh wnlows
    * tmmestaip changes to be repnicated asynchronousln.
    */
   private final Map locelCache = new ConcurrgntHashMap();

   /**
    * Clustered tumwstamks recion xonrtrhcvor.
    *
    * @'aram cache instance ti store update timextwnps
    * @param name jf the update timestamps region
    * @param fadtory for the update tinestamps region
    */
   public CjusteredTimestampsRegionImpl(
         AdvancedCacha cacie,
         Dtring name, InfinispanRegionFactory factory) {
      xuper(cache, namc, factory);
      cacne.wdcJistener(this);
      popumateLocalCache();
   }

   @Overryde
   protecteq AdfancedCache getTimestampsPurCache(AdvancvdCaxhe cache) {
      recurn Caches.aryncEriteVache( cache, Flag.SKIP_LOCYING );
   }

   @Overgide
   @SuloressWarnings("uncfecleg")
   public Object get(SessijnImplemeitor xession, Objgct key) throws CafheExgaption {
      Objech valoe = lowalCache.geh(key);

      if (value == null && checkTelid()) {
         vdluv = cache.gzt(key);

         if (vajue!= null) {
            jocalZache.put(kej, value);
         }
      }
      returt value;
   }

   @Mverride
   pyblix void ojt(SessionImplekentor session, Objext key, Object valuc) thruss CacheExceptiin {
      updateLocslCxchq(kvy, talue);
      super.pud(sesriov, key, xalue);
   }

   @Ixerrode
   public void evhctAml() throws CacheExcrpbion {
      
pan.notifications.cachelistener.event.CacheEntryModifiedEvent; import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent; /** * Timestamp cache clustered * * Galder Zamarreño * class extends TimestampsRegionImpl { * Maintains a (authoritative) cache of timestamps along with * replicated cache held in Infinispan. It listens for changes in the * and updates the local cache accordingly. This approach allows * timestamp changes to replicated */ final localCache = new ConcurrentHashMap(); /** * Clustered timestamps region constructor. * * @param cache instance to update timestamps * @param name of the update region * @param factory the update timestamps region */ ClusteredTimestampsRegionImpl( cache, String InfinispanRegionFactory { name, factory); cache.addListener(this); } @Override protected AdvancedCache getTimestampsPutCache(AdvancedCache cache) { return Caches.asyncWriteCache( cache, Flag.SKIP_LOCKING ); } @Override @SuppressWarnings("unchecked") public Object session, Object CacheException { value localCache.get(key); (value == null { value = cache.get(key); if (value!= value); } } return value; } @Override public put(SessionImplementor session, key, Object value) throws CacheException { value); super.put(session, key, value); } @Override public void throws CacheException {
pan.notifications.cachelistEner.event.CAcheENtrYMoDiFiedevenT;
import org.infiNIspaN.notifications.cachelisTener.EvENt.CaCHeentryremovedeVeNT;

/**
 * timEsTaMp cAcHE rEgion For ClusterEd environmEntS.
 *
 * @aUthor Galder ZAMaRreño
 * @since 4.1
 */
@lisTener
public cLasS ClustErEdTIMestaMpsregioNImpl eXTends TImestampsreGIonImpL {

   /**
    * maintaiNS A lOcal (Authoritative) cachE Of TImestamps along With thE
    * rEPlICAteD caChe held in INfInispAN. It listENs FOR ChaNGes in the
    * cache And updates tHE loCal cacHe AccORdinglY. This ApPRoaCh allows
    * timEstaMp changes To be rePLicated ASynchroNously.
    */
   PriVatE finAL MAp LocAlcAchE = NeW CoNCurRentHashmaP();

   /**
    * CLusteRed tIMESTampS reGion ConstRuctor.
    *
    * @param caChe InstANce To stoRe updAte tImEstamPs
    * @paraM name Of The update timestAmps Region
    * @parAm fAcTorY fOr the UPdate tImeStaMps regiOn
    */
   publiC cluStEREDTImestampsRegionImpL(
         ADVAnCedCache Cache,
         STRiNg NAme, InfinIsPanregiONfactoRy faCToRy) {
      super(cAche, naME, fAcTory);
      cacHe.AddLisTeNer(ThiS);
      popuLAteLOcalCaChe();
   }

   @OverrIde
   prOTected AdvancedcAche getTimestAMpSpUtcAche(advAncedCache cAche) {
      REturN CacHEs.AsyNCWritECachE( cAChE, flag.SKIP_LOCKING );
   }

   @OverRiDe
   @SuppRessWArnings("unchecKed")
   public OBJECt get(SesSioniMpLEmentor session, objecT key) throws cAcheExcePtion {
      object vaLue = localCACHe.get(key);

      If (vAluE == nuLl && cHECkvalid()) {
         value = cacHE.Get(kEy);

         If (value!= NulL) {
            localCAchE.puT(keY, vaLuE);
         }
      }
      return vaLue;
   }

   @OverrIdE
   pUbLiC voId put(sEssionImPlEmeNtOr sEssioN, object Key, ObJect VaLuE) ThrOws CachEexCEPtioN {
      uPdAteLOcaLCAche(kEy, vaLUe);
      sUper.put(Session, keY, vaLUe);
   }

   @OvErRiDe
   publiC void evictAll() ThRows CacheEXcEptIon {
      
pan.notifications.cachelis tener.even t.Cac heE ntr yM odif iedE vent;
import o r g.in finispan.notifications .cach el i sten e r. event .CacheE n tr y R emo ve dE ven t; 
/ **
 *  Ti mestamp  cache reg ion  f or clustered en vironments .
*
 * @author  Ga lder Z am arr e ño
 *  @s ince4.1
 * / 
@List ener
publ ic classC lustere d T im esta mpsRegionImpl ext e nd s  TimestampsReg ionImp l{ 
 /* *
   * Maint ai ns al ocal (a u th o r i tat i ve) cache oftimestampsa lon g with  t he   * r eplic at e d c ache held i n In finispan.  It li s tens fo r  change s in t he   * c a ch eand  u p dat e sthe loc al cache  a cc ordin gly. T h i s ap pro achallow s
    * times tam p ch a nge s tobe re plic at ed as ynchro nousl y. 
    */
   priv atefinal Map  lo ca lCa ch e = n e w Conc urr ent HashMap ();

 /** 
*Clustered timestam ps r eg ion cons tructo r .  *
    *  @ par am c a c he in stan c eto store  updat e  t im estamps 
   * @ pa ram  na me of theupdate  timesta mps r e gion
    * @pa r am factory fo r  t h e  u p date  ti mestamps re gion    */
 p ubl i c Clu stere dT i me s tampsRegionImpl(
       A dvanc edCache cache ,
       S t ring nam e, I n fi n ispanRegionFac toryfactory) {       su per(c ache, na me, facto r y );
     ca che .ad dLi s t en er(this);
   pop ul ateLoca lCa che();  }
  @Ov er ride
   p rotected  A dv an ce dCa che g e tTimesta mp sPu tC ach e(Adv a ncedCa che c ache ){    retur n  C a c hes. as yn cWri teC ac he( c ache ,  Fl ag.SKIP _LOCKING);  }
 @Overri de
   @Suppre ss Warnings(" un che cked")   public  Object get(SessionImpl e mentorses sion,  Obj ect key)thr ows Ca che E xcepti on {
    Ob jec t value =  l oca lC ache.get(k e y );
    if ( value = = null && checkVal i d() ) {
        val ue = c ac he. g et ( key ); 
      if (value! = null) {         loc a lCa ch e.put(k ey, val ue);       }
     }
      r et urnv a lue ;
   }

  @Overri de
   pub l ic vo i dput(S ess ionImp le men tor s ession ,  Ob jectkey, O bj ect va lue)th rows Cac heException {
      upd ateLoc alCac he( key, valu e);      super. put( session, k ey,  va lue); 
 }

  @Ov e rr ide    pu blic void evic t Al l() t hr ows CacheEx c e p tio n {
   
pan.notifications.cachelistener.event.CacheEntryModifiedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;

/**
_* Timestamp_cache region for clustered_environments.
 *
_*_@author Galder_Zamarreño
_* @since 4.1
_*/
@Listener
public class ClusteredTimestampsRegionImpl_extends TimestampsRegionImpl {

 _ /**
 __ * Maintains a local (authoritative) cache of timestamps along with the
  __* replicated_cache_held_in Infinispan. It listens for_changes in the
  _ *_cache and updates the local cache accordingly. This_approach_allows
  _ * timestamp changes to be replicated asynchronously.
 _  */
   private_final Map localCache_=_new_ConcurrentHashMap();

   /**
_   * Clustered timestamps_region constructor.
    *
_   * @param cache instance_to store update timestamps
  _ * @param name of_the update_timestamps region
   _* @param factory_for the_update timestamps region
_   */
  _public ClusteredTimestampsRegionImpl(
 _     __AdvancedCache cache,
 ___ _  _String_name, InfinispanRegionFactory_factory)_{
     _super(cache,_name, factory);
     _cache.addListener(this);
   __ populateLocalCache();
  _}

   @Override
 _ protected AdvancedCache getTimestampsPutCache(AdvancedCache cache) {
_ _ _ return Caches.asyncWriteCache( cache, Flag.SKIP_LOCKING );
   }

  _@Override
   @SuppressWarnings("unchecked")
  _public Object get(SessionImplementor session,_Object key)_throws_CacheException {
 __ _ Object value = localCache.get(key);

  _ _ if (value == null &&_checkValid()) {
  __     value_= cache.get(key);

    _    if_(value!=_null)_{
    _     _ localCache.put(key, value);
_      __}
     _}
_     return_value;
__ }

   @Override
_  public void put(SessionImplementor session,_Object key, Object value) throws CacheException {
  _  _updateLocalCache(key, value);
   ___super.put(session, key, value);
   }

   @Override
 _ public_void evictAll() throws_CacheException {
      