<dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-hazelcast</artifactId>
<version>0.5-incubating-SNAPSHOT</version>
</dependency>
2019-11-17
Tamaya Hazelcast is an extension module. Refer to the extensions documentation for further details.
Tamaya Hazelcast provides a property source which uses Hazelcast as configuration backend. Hereby the module supports read-only integration (as a HazelcastPropertySource as well as a writing configuration changes back (based on Tamaya’s MutableConfiguration API defined by the tamaya-mutable-config extension module.
The module is based on Java 8.
To use tamaya-hazelcast you only must add the corresponding dependency to your module:
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-hazelcast</artifactId>
<version>0.5-incubating-SNAPSHOT</version>
</dependency>
Hazelcast integration comes basically with 2 artifacts:
The org.apache.tamaya.hazelcast.HazelcastPropertySource is a PropertySource. The property source is not automatically
registered. Either register it using the ServiceLoader yourself or implement
and register a corresponding PropertySourceProvider
.
If the tamaya-mutable-config module is loaded it is possible to write property values back into the consul cluster, by accessing a MutableConfiguration using the URI config:hazelcast.
Access of consul key/value pairs is through the normal Tamaya API.
The HazelcastPropertySource is not automatically registered and provides different options how to integrate Tamaya with Hazelcast. It provides:
a Hazelcast based property source implementation.
configurable caching of key/values.
configuraing a dedicated Hazelcast map ID to be used.
To use hazelcast as a configuration backend, you simply create the corresponding Hazelcast instance and use it to initialize the Tamaya property source. Given that a hazelcast backend configuration can be easily created as illustrated below:
Config hazelcastConfig = new Config();
// define config settings
HazelcastInstance hazelcastInstance = Hazelcast.newInstance(hazelcastConfig);
HazelcastPropertySource ps = new HazelcastPropertySource(hazelcastInstance);
ps.setName("myHazelcast-config");
ps.setOrdinal(2000);
// Build your own configuration context
ConfigurationBuilder b = Configuration.createConfigurationBuilder();
b.addDefaultPropertyConverters().addDefaultPropertyFilter().addDefaultPropertySources();
// Add the hazelcast property source (as most significant)
b.addPropertySource(ps);
// build and use the configuration
Configuration config = b.build();
The AbstractHazelcastPropertySource is the baseclass used by HazelcastPropertySource. Use it to implement your own Hazelcast based property source.