You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Piotr Klimczak (Commented) (JIRA)" <ji...@apache.org> on 2012/03/10 22:40:57 UTC

[jira] [Commented] (CAMEL-3686) Allow to share cache between bundles, and only clear cache when no more bundles access that cache

    [ https://issues.apache.org/jira/browse/CAMEL-3686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13226946#comment-13226946 ] 

Piotr Klimczak commented on CAMEL-3686:
---------------------------------------

The CacheManagerFactory have to be set as a shared by this:
{code}
<bean id="cacheManagerFactory" class="org.apache.camel.component.cache.DefaultCacheManagerFactory">
    <property name="shared" value="true" />
</bean>
{code}

This have to be done on the host bundle, that will share the cache.
Next we have to expose the CacheManagerFactory as an OSGi service.
The other bundles have to make a reference to that CacheManagerFactory.

The trick is, that the CacheEndpoint instance will close the CacheManagerFactory only if:
a) CacheManagerFactory has a property "shared" set to false (default)
b) CacheManagerFactory has a property "shared" manually set to true and the classloader of CacheEndpoint is same as CacheManagerFactory's classloader.

In other words, if shared is set to true, only the "owner" of CacheManagerFactory can stop it during bundle shutdown.

This is how we can avoid closing the CacheManagerFactory by stopping/uninstalling the referencing bundles.

Please note, that the CacheManagerFactory on the host side will be closed only if it will be used in the host's camel context (to route something).
If it will be created only by spring and exposed as a service, you have to set the destroy-method (doStop) on bean definition (similar like with datasources).

Is that ok? Or maybe you still want to track consumers?
                
> Allow to share cache between bundles, and only clear cache when no more bundles access that cache
> -------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-3686
>                 URL: https://issues.apache.org/jira/browse/CAMEL-3686
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-cache
>    Affects Versions: 2.4.0
>         Environment: camel-cache 2.4.0-fuse-01-00
>            Reporter: Justas
>             Fix For: 2.10.0
>
>         Attachments: camel-cache.sharedCacheManagerFactory.patch, camel-cache.zip, diff.txt
>
>
> I am using camel-cache component in serviceMix. Cache endpoint uri is 
> "cache://elements?maxElementsInMemory=2&memoryStoreEvictionPolicy=MemoryStoreEvictionPolicy.FIFO&overflowToDisk=false&eternal=false&timeToLiveSeconds=800" 
> I have 2 bundles (core.jar, services.jar). Inside those bundles I use 
> @EndpointInject(uri = Constants.CACHE_URI) 
> ProducerTemplate cacheTemplate; 
> cacheTemplate.requestBodyAndHeaders(...) 
> core.jar puts and reads elements from cache. 
> services.jar only reads elements from cache. 
> After deploying both bundles it works fine, but if i uninstall services.jar, cache is "destroyed". core.jar (and all others) can't put objects into cache anymore. 
> How could I make all bundles to "share" the same cache? 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira