Reputation: 361
Here is what I have:
Serializer
s that I want to use.Here is my problem:
Serializer
s have constructor dependencies so it's not possible to declare them via the .xml.Config
afterwards (i. e. adding the Serializer
s to the config) does not result in the Serializer
s being registred.Solutions that I am looking for / that I have tried so far:
HazelcastInstance
manually and the bind it to JCache somehow (don't know how to achieve this, don't even know if it's possible)Serializer
s to the existing HazelcastInstance
/Config
(as said before, seems not to work)Question(s):
Is there any way to get it work? Am I missing something completely obvious? Am I using the frameworks wrong?
Upvotes: 0
Views: 282
Reputation: 823
Assuming you build your Hazelcast Config
with custom Serializer
s programmatically, here is one way to start a named Hazelcast embedded member and reference it by name:
Config config = new Config();
// apart from your config, setup the instance name
config.setInstanceName("jcache-test");
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
// request the server-side caching provider
// same method to bind by instance name also applies to client-side caching provider
CachingProvider cachingProvider = Caching.getCachingProvider(HazelcastCachingProvider.SERVER_CACHING_PROVIDER);
// request the default CacheManager(url = null & ClassLoader = null)
// indicating it should be bound to the named HazelcastInstance
CacheManager cacheManager = cachingProvider.getCacheManager(null, null,
HazelcastCachingProvider.propertiesByInstanceName("jcache-test"));
// use the CacheManager as usual
Cache<String, String> cache = cacheManager.createCache("cache", new MutableConfiguration<>());
cache.put("1", "a");
System.out.println(cache.get("1"));
There are more ways to achieve binding a CacheManager
to an explicitly configured HazelcastInstance
, you can have a look at the examples in this reference manual section.
As a sidenote, in general Hazelcast expects that the Config
it is started with is final on startup. Mutations to the Config
object after Hazelcast is started are not taken into account, except for specific data structure configuration that can be added after startup as discussed here.
Upvotes: 1