You can return a unique facade to a central cache to each bundle. You can 
use the facade to collect the bundle's class loader when a key is added to 
the cache. You use the facade just to know which bundle is interacting 
with the central cache.
-- 

BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the OSGi Alliance
hargr...@us.ibm.com

office: +1 386 848 1781
mobile: +1 386 848 3788




From:   Balázs Zsoldos <balazs.zsol...@everit.biz>
To:     OSGi Developer Mail List <osgi-dev@mail.osgi.org>
Date:   2014/11/20 08:07
Subject:        Re: [osgi-dev] How to pass Classloader for a Cache 
component
Sent by:        osgi-dev-boun...@mail.osgi.org



I have been thinking of this solution but I had the following issue with 
it: If multiple bundles request the OSGi service, they might think that 
they see the same cache while they always get a new instance. Also, if I 
configure a cache with 10.000 maxEntries, this cache will be populated as 
many times as the service is requested.

The issue is that many of the cache implementations support custom 
ClassLoaders to be passed only during the initialization of the cache (and 
not when the get(key) function is called).

Do you think cache / bundle is a better choice than defining the 
classloader bundle in configuration? I could not decide for sure. I feel 
hat classloader-bundle-configuration is less KISS but more deterministic.


On Thu, Nov 20, 2014 at 1:56 PM, BJ Hargrave <hargr...@us.ibm.com> wrote:
If you register the cache as a service using ServiceFactory, then you will 
know the bundle that gets the service. You can then use that bundle's 
class loader. This would seem sufficient, or did I not fully understand 
the problem? 
-- 

BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the OSGi Alliance
hargr...@us.ibm.com 

office: +1 386 848 1781
mobile: +1 386 848 3788




From:        Balázs Zsoldos <balazs.zsol...@everit.biz> 
To:        OSGi Developer Mail List <osgi-dev@mail.osgi.org> 
Date:        2014/11/20 06:07 
Subject:        [osgi-dev] How to pass Classloader for a Cache component 
Sent by:        osgi-dev-boun...@mail.osgi.org 




Hi, 

we have several cache components that can store key-value pairs. The 
different implementations are: 
Noop (No operation, the cache always says that it does not have the data, 
implements ConcurrentMap) 
ConcurrentHashMap (for development and tests) 
Infinispan (transactional and distributed ConcurrentMap)

When it comes to the point of distribution or hard drive storage, the 
following question is raised: 
How to pass the Classloader that can deserialize the key and value classes 
to the cache?

Current solution 

There is a cache-api that contains a factory interface. The classloader is 
passed to the createCacheHolder function. The cacheHolder can be closed 
when we do not want to use the cache anymore and it has a function that 
gives us back a concurrentMap. 

The issue with this solution is that we have to keep three member 
variables in our component and initialize the cache in the activate 
method. The code looks a bit ugly. 

Other possible solution 

The cache component registers an OSGi service based on the Map, 
ConcurrentMap, CacheSpecificInterface interfaces. The one who want to use 
the created cache instance can use one of the interfaces that is 
available. 

E.g: In case of Infinispan, the cache registers an OSGi service with three 
interfaces: Map, ConcurrentMap, InfinispanCache. 

The code on the consumer side looks cool, we need only one reference with 
type Map, ConcurrentMap or whatever. The API is much more flexible and 
simple. However, the classloader is not passed in this case. 

I was thinking a lot and I came out with a weird idea: 

In case the cache needs a ClassLoader, one of the configuration attributes 
is a filter expression for a bundle. The cache OSGi service is registered 
when that bundle is available and it uses the ClassLoader of the bundle. 

E.g: We have the following cache configuration: 

classLoaderBundle: (&(bundle.name=xy)(bundle.version>1.0.0)...) 

Question 

Do you think this solution is too weird to use? Do you know any other 
options to solve this issue? 

I am planning to create a new major release soon and it would be really 
helpful to find the best API / Configuration for this issue. 

Regards, 
Balázs Zsoldos 
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev 

_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to