jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramirof <ramiro_fala...@yahoo.com.ar>
Subject Re: JCS Element Event Handling Problem
Date Thu, 28 Oct 2010 16:35:51 GMT

Hi Umut Dogan!

I'm experiencing the same issue you described in this post, and I can't
solve it. Did you find out which was the problem?
Or anyone knows how..

Thanks in advance!

Ramiro




Umut Dogan wrote:
> 
> Hi,
> 
>  
> 
> I created a class as mentioned
> http://jakarta.apache.org/jcs/ElementEventHandling.html page:
> 
>  
> 
> package com.mytest;
> 
>  
> 
> import java.util.EventObject;
> 
>  
> 
> import org.apache.jcs.engine.CacheElement;
> 
> import org.apache.jcs.engine.control.event.behavior.IElementEvent;
> 
> import
> org.apache.jcs.engine.control.event.behavior.IElementEventConstants;
> 
> import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
> 
> import org.apache.log4j.Logger;
> 
>  
> 
> public class CacheEventHandler implements IElementEventHandler {
> 
>  
> 
>       public static final Logger _logger =
> Logger.getLogger(CacheEventHandler.class);
> 
>       
> 
>       private static final String sessionCacheRegionName = "session";
> 
>       
> 
>       /**
> 
>        * Listens to cache events and accordingly logs out sessions or
> clears
> folders.
> 
>        */
> 
>    public void handleElementEvent(IElementEvent event)
> 
>    {
> 
>  
> 
>       if (_logger.isDebugEnabled())
> 
>       {
> 
>          _logger.debug("Handle cache element event: " +
> event.getElementEvent());
> 
>       }
> 
>       switch(event.getElementEvent())
> 
>       {
> 
>          case
> IElementEventConstants.ELEMENT_EVENT_EXCEEDED_IDLETIME_BACKGROUND:
> 
>          case
> IElementEventConstants.ELEMENT_EVENT_EXCEEDED_IDLETIME_ONREQUEST:
> 
>          case
> IElementEventConstants.ELEMENT_EVENT_EXCEEDED_MAXLIFE_ONREQUEST:
> 
>          case
> IElementEventConstants.ELEMENT_EVENT_EXCEEDED_MAXLIFE_BACKGROUND:
> 
>             CacheElement element =
> (CacheElement)((EventObject)event).getSource();
> 
>             if (sessionCacheRegionName.equals(element.getCacheName()))
> 
>             {
> 
>                // private codes
> 
>             }
> 
>             break;
> 
>       }
> 
>       
> 
>    }
> 
>  
> 
> }
> 
>  
> 
> Then tried to call this class from my CacheManager class. I tried  both
> approaches you mentioned in the above document like these lines:
> 
>  
> 
> private static final String sessionCacheRegionName = "session";
> 
> private static JCS sessionCache = null;
> 
>  
> 
> // initialize session cache
> 
>       if(sessionCache == null)
> 
>       {
> 
>          try
> 
>          {
> 
>             sessionCache = JCS.getInstance(sessionCacheRegionName);
> 
>  
> 
>             // this should add the event handler to all items as
> 
>             // they are created.
> 
>             IElementAttributes attributes =
> sessionCache.getDefaultElementAttributes();
> 
>             attributes.addElementEventHandler(new CacheEventHandler());
> 
>             sessionCache.setDefaultElementAttributes(attributes);
> 
>          }
> 
>          catch (CacheException e)
> 
>             {
> 
>                 _logger.error( "Problem initializing cache for region name
> ["
> 
>                   + sessionCacheRegionName + "].", e );
> 
>             }
> 
>          
> 
>       }  
> 
>  
> 
> Or in the putSession method:
> 
>  
> 
> public void putSession(String userId, String session)
> 
>    {
> 
>       try
> 
>       {
> 
>         CacheEventHandler ceh = new CacheEventHandler();
> 
>         IElementAttributes attributes =
> sessionCache.getDefaultElementAttributes();
> 
>         attributes.addElementEventHandler(ceh);
> 
>         sessionCache.put(userId, session, attributes);        
> 
>       }
> 
>       catch (CacheException e)
> 
>         {
> 
>             _logger.error( "Problem initializing cache for region name ["
> 
>               + sessionCacheRegionName + "].", e );
> 
>         }
> 
>    } 
> 
>  
> 
> Cache.ccf file is like this:
> 
>  
> 
> # DEFAULT CACHE REGION
> 
> jcs.default=DC
> 
> jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
> 
> jcs.default.cacheattributes.MaxObjects=1000
> 
> jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru
> .LRUMemoryCache
> 
> jcs.default.cacheattributes.UseMemoryShrinker=false
> 
> jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
> 
> jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
> 
> jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
> 
> jcs.default.elementattributes.IsEternal=false
> 
> jcs.default.elementattributes.MaxLifeSeconds=60
> 
> jcs.default.elementattributes.IdleTime=1800
> 
> jcs.default.elementattributes.IsSpool=true
> 
> jcs.default.elementattributes.IsRemote=true
> 
> jcs.default.elementattributes.IsLateral=true
> 
>  
> 
> # PRE-DEFINED CACHE REGIONS - sessionCache
> 
> jcs.region.sessionCache=DC
> 
> jcs.region.sessionCache.cacheattributes=
> org.apache.jcs.engine.CompositeCacheAttributes
> 
> jcs.region.sessionCache.cacheattributes.MaxObjects=1000
> 
> jcs.region.sessionCache.cacheattributes.MemoryCacheName=
> org.apache.jcs.engine.memory.lru.LRUMemoryCache
> 
> jcs.region.sessionCache.cacheattributes.UseMemoryShrinker=true
> 
> jcs.region.sessionCache.cacheattributes.MaxMemoryIdleTimeSeconds=3600
> 
> jcs.region.sessionCache.cacheattributes.ShrinkerIntervalSeconds=20
> 
> jcs.region.sessionCache.cacheattributes.MaxSpoolPerRun=500
> 
> jcs.region.sessionCache.cacheattributes.MaxLifeSeconds=3600
> 
> jcs.region.sessionCache.elementattributes=org.apache.jcs.engine.ElementAttri
> butes
> 
> jcs.region.sessionCache.elementattributes.IsEternal=false
> 
>  
> 
> # AVAILABLE AUXILIARY CACHES
> 
> jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFacto
> ry
> 
> jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDis
> kCacheAttributes
> 
> jcs.auxiliary.DC.attributes.DiskPath=${user.dir}/jcs_swap
> 
> jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000000
> 
> jcs.auxiliary.DC.attributes.MaxKeySize=1000000
> 
> jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
> 
> jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
> 
> jcs.auxiliary.DC.attributes.ShutdownSpoolTimeLimit=60
> 
>  
> 
>  
> 
> But it newer enters to the CacheEventHandler class' handleElementEvent
> method when I debug, and it nevers calls the eventhandler to make the
> things
> which I want.
> 
>  
> 
> Is this a bug, or am I doing something wrong?
> 
>  
> 
> Thanks,
> 
> Umut
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/JCS-Element-Event-Handling-Problem-tp21954783p30078417.html
Sent from the JCS - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Mime
View raw message