In This Section

Overview

The platform provides the ability to initialize @Configured annotated fields and methods with configuration values from the XRuntime (alternative to using the XRuntime.getValue() API). Annotated fields and methods are discovered automatically for the main Talon application. Additional classes can be exposed using the @AppConfiguredAccessor annotation.

 

This article describes the usage of the configuration annotations:

Annotation Type 
@Configured

Used to annotate application fields and setter methods for population with settings from configuration.

@AppConfiguredAccessorUsed to expose additional configured applications to the Talon server.

Configuration Annotation Discovery

@Configured Annotation

The @Configured annotation is used to annotate application fields and methods to allow them to be discovered by a Talon Server. The Talon server will populate these fields and methods with settings given in Talon configuration.

The @Configured annotation supports following elements:

@Configured ElementType 
propertyString, requiredThe configuration property name.
requiredboolean, optionalFlag indicating whether the property is required or not. Default: false
defaultValueString, optionalThe default value of the property. Default: "<null>"
descriptionString, optionalA description of the property. Default: "<null>"

@AppConfiguredAccessor

Any @Configured annotated field or method in the main application class will be discovered by the Talon server. If additional classes in your application contain configured fields or methods, they can be exposed to the server using the @AppConfiguredAccessor annotation.

Example:

    @AppHAPolicy(HAPolicy.EventSourcing)
    public static class MyApp {
        MyOtherClass someOtherClass = new MyOtherClass();

        @AppConfiguredAccessor
        public void getConfiguredContainers(Set<Object> containers) {
            containers.add(someOtherClass );
        }
    }

    private static class MyOtherClass {
        @Configured(property = "simulator.ems.orderPreallocateCount", defaultValue = "1048576")
		private int orderPreallocateCount;
		MyOtherClass() {
        }
    }

Configuration Discovery in Hornet

For Topic Oriented Applications, any @Managed object will be introspected for @Configured fields and methods. See ManagedObjectLocator. The DefaultManagedObjectLocator for TOA calls TopicOrientedApplication.addConfiguredContainers(Set), so unless your application provides its own managed object locator, additional configured containers can be added by overriding addConfiguredContainers():

    @AppHAPolicy(HAPolicy.EventSourcing)
    public static class MyApp extends TopicOrientedApplication {
        MyOtherClass someOtherClass = new MyOtherClass();

        @Override
        public void addConfiguredContainers(Set<Object> containers) {
            containers.add(someOtherClass );
        }
    }

    private static class MyOtherClass {
        @Configured(property = "simulator.ems.orderPreallocateCount", defaultValue = "1048576")
		private int orderPreallocateCount;
		MyOtherClass() {
        }
    }

 

Supported Configuration Types

Configuration values can be of the following types:

 

Fields

When running in a Talon Server, it is possible to annotate @Configured fields:

 

 

import com.neeve.cli.annotations.Configured;
 
public class MyApp {

  @Configured(property = "simulator.ems.orderPreallocateCount", defaultValue = "1048576")
  private int orderPreallocateCount;
}

Setter Methods

When running in a Talon Server, it is possible to annotate @Configured setter methods:

import com.neeve.cli.annotations.Configured;
 
public class MyApp {
  private int orderPreallocateCount;

  @Configured(property = "simulator.ems.orderPreallocateCount", defaultValue = "1048576")
  void setOrderPreallocateCount(int orderPreallocateCount) {
	this.orderPreallocateCount = orderPreallocateCount;
  }
}

Limitations

In order to avoid potential race conditions with static fields and preserve the semantics of the "final" keyword, the @Configured annotation does not support injecting properties into fields that are declared static or final. In these cases, the framework will throw a CliException at initialization time.

Programmatic Access to Configuration

Configuration settings remain accessible via the XRuntime.getValue() API.