XML Variables
One of the new features in Hazelcast 3.0 are XML variables which provided a lot of flexibility for Hazelcast xml based configuration. Imagine that you have the following configuration:
group1 password1
As you can see the group name and password are hard coded. Apart from being a potential security risk it also makes the configuration less flexible since for every environment you need to have a different hazelcast.xml file. And this can lead to a lot of duplication and often is highly undesirable. One way to deal with this is to load the Config instance from XML and modify the unwanted parts. Although this approach is very flexible, it is a bit of a hassle. That is why variables have been added to the XML configuration, for example:
${group.name} ${group.password}
Here there are 2 variables: group.name and group.properties. If you load HazelcastInstance like this:
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
Hazelcast will automatically replace the variables by system properties if available. If not available an exception will be thrown. If you start up your JVM with “-Dgroup.name=dev -Dgroup.password=somepassword” the properties will automatically be put in the System properties and therefore be accessible in the XML configuration. In some cases you don’t want to rely on system properties but want to rely on an external system like LDAP or a database for example. In these cases you need to make use of the XmlConfigBuilder and set a Properties instance explicitly:
Properties properties = new Properties(); //fill the properties, e.g. from database/ldap etc XmlConfigBuilder builder = new XmlConfigBuilder(); builder.setProperties(properties) Config config = builder.build(); HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
This should provide all the flexibility you need. A planned XML improvements is the support for XML imports to assembly a Hazelcast XML configuration from smaller XML sections, for example:
This should provide another level of flexibility for the XML configuration