Hi,

I have an application working with OJB 1.0.1 and OSCache / JGroups and I am
currently moving to OJB 1.0.3 in order to use ObjectCacheTwoLevelImpl cache
implementation. And unfortunately I am facing several issues :

- first I have cut/past the source code of the ObjectCacheOSCacheImpl.java
class, and sometimes the application hangs ! I finally sorted this by fixing
the code, adding a call "cache.cancelUpdate(oid.toString());" in the catch
block of lookup method.

- and I am now facing a more serious problem. Using the
ObjectCacheOSCacheImpl within a ObjectCacheTwoLevelImpl, not OScase /
JGroups notification is sent. Even if I use directly the
ObjectCacheOSCacheImpl, no notification is sent. On the contrary, if I used
my previous version of the ObjectCacheOSCacheImpl class, those one
implementing ObjectCache, it works fine, notifications are sent. Of course,
all of my OJB access are within a transaction, started with a
PersistenceBroker.startTransaction.

Any idea, am I missing something or is there a bug ?


Jacques Desmazieres


Here is an extract of my repository-jdbc-connection.xml file:

<jdbc-connection-descriptor
        jcd-alias="Convergence"
        default-connection="true"
        platform="Hsqldb"
        jdbc-level="2.0"
        driver="org.hsqldb.jdbcDriver"
        protocol="jdbc"
        subprotocol="hsqldb"
        dbalias="hsql://localhost:9001"
        username="sa"
        password="">

        <!- this works fine : ObjectCacheOSCacheImpl implements ObjectCache -->
        <object-cache
class="com.is2france.framework.middleware.services.ObjectCacheOSCacheImpl"/>

        <!- this does not work : ObjectCacheOSCacheInternalImpl implements
ObjectCacheInternal -->
<!--    <object-cache
class="com.is2france.framework.middleware.services.ObjectCacheOSCacheInterna
lImpl"/> -->

        <!- this does not work -->
<!--    <object-cache
class="org.apache.ojb.broker.cache.ObjectCacheTwoLevelImpl">
                <attribute attribute-name="cacheExcludes" attribute-value=""/>
                <attribute attribute-name="applicationCache"
attribute-value="com.is2france.framework.middleware.services.ObjectCacheOSCa
cheInternalImpl"/>
                <attribute attribute-name="copyStrategy"
attribute-value="org.apache.ojb.broker.cache.ObjectCacheTwoLevelImpl$CopyStr
ategyImpl"/>
        </object-cache>-->

        <connection-pool        maxActive="50"
                                                maxIdle="-1"
                                                maxWait="200"
                                                whenExhaustedAction="1"
                                                
timeBetweenEvictionRunsMillis="-1"
                                                testOnBorrow="false"
                                                testOnReturn="false"
                                                testWhileIdle="false"
                                                validationQuery="select 
count(*) from OJB_HL_SEQ" />

        <sequence-manager
className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl">
                <attribute attribute-name="grabSize" attribute-value="10"/>
                <attribute attribute-name="globalSequenceId" 
attribute-value="false"/>
        </sequence-manager>
</jdbc-connection-descriptor>



And the implementation of ObjectCacheOSCacheInternalImpl

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

        public ObjectCacheOSCacheInternalImpl(PersistenceBroker broker, 
Properties
prop)
        {
        }

        public void cache(Identity oid, Object obj)
        {
                try
                {
                        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)
                {
                        try
                        {
                                cache.putInCache(oid.toString(), obj);
                                result = true;
                        }
                        catch (Exception e1)
                        {
                                cache.cancelUpdate(oid.toString());
                                log.error("Error while try to cache object: " + 
oid, e);
                        }
                }
                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
                {
                        if (log.isDebugEnabled())
                                log.debug("Remove from cache: " + oid);
                        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]

Reply via email to