Hi,

we have several cache components that can store key-value pairs. The
different implementations are:


   - Noop <https://github.com/everit-org/cache-noop> (No operation, the
   cache always says that it does not have the data, implements ConcurrentMap)
   - ConcurrentHashMap (for development and tests)
   - Infinispan <https://github.com/everit-org/cache-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 <https://github.com/everit-org/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
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to