How to instantiate Ignite CacheManager with programmatic configuration / without XML

973 Views Asked by At

I want to create an Ignite node with a programmatic configuration. A javax.cache.CacheManager object is required for the application.

I know that I can start an Ignite node with the following code:

//with XML configuration
Ignition.start("path-to-ignite-config-xml");

//with programmatic configuration
Ignition.start(cfg)

//with xml-config with the JCache-API   
Caching.getCachingProvider().getCacheManager(uriToXML, classloader);

The first two method calls got an Ignite object as a return value. The last one got a CacheManager object as a return value. But I would need something like this:

Caching.getCachingProvider().getCacheManager(IgniteConfiguration cfg);
// or this:
Ignition.start(IgniteConfiguration cfg).getCacheManager();

There's a method org.apache.ignite.cache.CachingProvider.findManager(Ignite) which has got the return type javax.cache.CacheManager (which is what I want) but the return value is always null.

Is there a way to get a javax.cache.CacheManager object without XML config?

2

There are 2 best solutions below

0
On

I worked around the issue in my code by ditching CachingProvider and writing my own implementation of the javax.cache.CacheManager interface.

I am creating an Ignite instance in the constructor of the CacheManager implementation and forwarding all the calls to it. IgniteCache is already implementing javax.cache.Cache, so no issues there.

It is not strictly JCache, but it is close enough for my purposes.

0
On

Unfortunately, JCache API does not allow this and supports only URLs. You should use XML file for configuration, or use native Ignite API.