Tutorials/howto use cluster config

From CubeiaWiki

Jump to: navigation, search

This is a simple example of how you can use and access the properties from cluster.props. The properties specified there will be propagated by the master node so it is a powerful way of keeping properties consistent over many servers.

The example below outlines how to make a configuration for a remote service URL in String format.

Documentation Links
References for documentation regarding the configuration API.
Configurable Javadoc
Config provider Javadoc
Developer manual

Configuration Placeholder

Create an interface, we will call it RemoteServiceConfig, let it extend Configurable. Add an annotation for the namespace(@Configurated) and a getter for remote URL with a @Property annotation with default value.

public interface RemoteServiceConfig extends Configurable {

    public int getCallerId();

    public String getRemoteUrl();

Note that the "callerId" returns an integer. The configuration service will be able to convert the configuration string value to any type that is either a primitive or have a constructor with a single string argument, and the special cases InetAddress, File and enumerations.

This interface has to be exported to the common classloader in your service deployment descriptor service.xml.

Configuration Accessor

In our example we will read the configuration from a deployed Service. The code snippet below is from the init-method of the Service's lifecycle. We provide null as namespace to the getConfiguration call since we are not interested in overriding the default namespace for the provided configuration class.

public void init(ServiceContext con) throws SystemException {
    try {
        ClusterConfigProviderContract contr = con.getParentRegistry().getServiceInstance(ClusterConfigProviderContract.class);
        RemoteServiceConfig configuration = contr.getConfiguration(RemoteServiceConfig .class, null);
        remoteUrl = configuration.getRemoteUrl();
	callerId = configuration.getCallerId();
    } catch (ConfigurationException e) {
        log.error("Failed to read remote service configuration. Will fall back on default value", e);


Add the configuration property to $FBHOME$/conf/cluster.props. If you are running a cluster you only need to add this on the master server(s).


That's it! The configuration should be set and ready to go.

Personal tools