Jacques Desmazieres wrote:
Hi,

Just a fix to the code of my previous email : you should not call
admin.cancelUpdate(oid.toString()); in the catch block of the cache method
(you should never go in this code, but if you do so, you have an exception :
not in update state)


ok! I checked in a patched version of ObjectCacheOSCacheImpl. Could you please check my changes. Here is a link to the new version


http://cvs.apache.org/viewcvs.cgi/db-ojb/contrib/src/ObjectCacheOSCacheImpl.java?rev=1.1.4.3&view=markup

regards,
Armin

regards

Jacques


-----Message d'origine-----
De : Armin Waibel [mailto:[EMAIL PROTECTED]
Envoy� : jeudi 12 mai 2005 16:38
� : OJB Users List
Objet : Re: ObjectCacheInternal and OSCache / JGroups issue


Hi,

Jacques Desmazieres wrote:


Based on all that I have been seeking a little bit deeper in the OSCache
documentation. Actually, OSCache sends notifications (Events)

only on flush

events. The putInCache method do not flush the cache, so no

event is sent.

The ObjectCacheOSCacheInternalImpl should force OSCache to

flush the entry

in order to generate an events.

Based on that, there is a mistake in the sample code provided :

you have to

add a call to remove(oid) just before calling putInCache (twice in the
code).

And now it works fine. Hope this could help anyone else.


Thanks much! I will patch the sample code.

regards
Armin



Jacques Desmazieres


Here is the code of my current implementation, based on your sample with just some fixes

public class ObjectCacheOSCacheInternalImpl implements

ObjectCacheInternal

{
        private static GeneralCacheAdministrator admin = new
GeneralCacheAdministrator();
        private static final int REFRESH_PERIOD =
com.opensymphony.oscache.base.CacheEntry.INDEFINITE_EXPIRY;
        private Logger log =
Logger.getLogger(ObjectCacheOSCacheInternalImpl.class);

public ObjectCacheOSCacheInternalImpl(PersistenceBroker

broker, Properties

prop)
        {
        }

        public void cache(Identity oid, Object obj)
        {
                try
                {
                        remove(oid);
                        admin.putInCache(oid.toString(), obj);
                }
                catch (Exception e)
                {
                        admin.cancelUpdate(oid.toString());
                        log.error("                Error while try to

cache object: " + oid, e);

                }
        }

        public void doInternalCache(Identity oid, Object obj, int type)
        {
                cache(oid, obj);
        }

        public boolean cacheIfNew(Identity oid, Object obj)
        {
                boolean result = false;
                Cache cache = admin.getCache();
                try
                {
                        cache.getFromCache(oid.toString());
                }
                catch (NeedsRefreshException e)
                {
                        cache( oid, obj );
                        if (log.isDebugEnabled()) log.debug("

retrieved from application

cache");
                }
                return result;
        }

        public Object lookup(Identity oid)
        {
                try
                {
                        return admin.getFromCache(oid.toString(),

REFRESH_PERIOD);

                }
                catch (NeedsRefreshException e)
                {
                        // not found in cache
                        if (log.isDebugEnabled()) log.debug("Not

found in cache: " + oid);

                        admin.cancelUpdate(oid.toString());
                        return null;
                }
                catch (Exception e)
                {
                        log.error("Unexpected error when lookup

object from cache: " + oid, e);

                        admin.cancelUpdate(oid.toString());
                        return null;
                }
        }

        public void remove(Identity oid)
        {
                try
                {
                        admin.flushEntry(oid.toString());
                }
                catch (Exception e)
                {
                        throw new RuntimeCacheException("Unexpected

error when remove object from

cache: " + oid, e);
                }
        }

        public void clear()
        {
                try
                {
                        if (log.isDebugEnabled()) log.debug("Clear cache");
                        admin.flushAll();
                }
                catch (Exception e)
                {
                        throw new RuntimeCacheException("Unexpected

error while clear cache", e);

                }
        }
}




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]








--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to