Table of Contents
Just a second...

Using the configuration API

General use

From within a Java™ application the root of the configuration tree can be obtained at any time using ConfigManager.getConfig(). This provides access to the general objects and can be used from within server-side or client-side code.

From within server-side code (for example, a publisher) the server configuration root can be obtained using ConfigManager.getServerConfig() which exposes all of the server side configuration also.

From the configuration root you can navigate to any subordinate configuration objects to view them or set their properties.

On the server side most properties cannot be changed after the server has started and they become locked so any attempt to change them results in an exception. Certain properties (such as conflation and connection policies) can be changed at runtime. The API documentation makes it clear which properties can be changed at runtime.

In client-side Java code the configuration does not become locked and can be changed at any time. However, some values are read at the start only. Ideally, set all properties before creating any client side objects.

For configuration objects which are optional but there can be many (multiplicity 0..n), there are appropriate add methods to add new objects. For example to add a publisher and set a property on it:

PublisherConfig publisher = 
    ConfigManager.getServerConfig().addPublisher( 
        "MyPublisher", 
        "com.pub.MyPublisher"); 
publisher.setTopicAliasing(false);

In these cases there are also methods to obtain the full list (for example, getPublishers()) or to obtain a specific one by name (for example, getPublisher("MyPublisher")). In many cases there are also methods to remove an object.

Note: When there must be at least one object (multiplicity 1..n), you must configure at least one. However, if a server is started with missing configuration of this kind, suitable defaults are normally created and a warning logged.

Single instance configuration objects (multiplicity 1..1) subordinate to the root can be obtained so that their properties can be changed (or read). So, for example the Queues object (an instance of QueuesConfig) can be obtained using the getQueues() method.

When a single configuration object is optional (multiplicity 0..1), the get method can return null if it has not been defined. In this case to set it the set method (as opposed to add) returns the object created. An example of this is the file service (FileServiceConfig) on a web server (WebServerConfig) as shown in the following example code:

ServerConfig config = ConfigManager.getServerConfig(); 
WebServerConfig webServer = config.addWebServer("MyWebServer"); 
FileServiceConfig fileService = webServer.setFileService("File Service");

Configuring a server

After instantiating a Diffusion™ server in Java the root of the server configuration tree can be obtained from the server object itself and configuration objects can be navigated to and changed as required before starting the server.

For example, the following code shows how to add a connector that accepts client connections on port 9090:

DiffusionServer server = new DiffusionServer(); 
ServerConfig config = server.getConfig(); 
ConnectorConfig connector = config.addConnector("Client Connector"); 
connector.setPort(9090); 
connector.setType(Type.CLIENT); 
server.start();

In reality, it is best to configure far more values. However, if any essential objects are omitted (such as queues), suitable defaults are created when the server starts and a warning is logged.

Configuration access from a publisher

Within a publisher the configuration object for the publisher itself can be obtained using the getConfig method which returns the publisher configuration (PublisherConfig) object.