Skip to content

Features

allenxwang edited this page Jun 4, 2012 · 29 revisions

Pablo is a Java library that provides APIs to access and utilize properties that can change dynamically at runtime. It includes the following features:

Dynamic properties

Pablo provides classes that represent dynamic properties where the values are of specific types and can change at runtime.

Instead of writing code like this to deal with something hard to change at runtime:

  String prop = System.getProperty("myProperty");
  int x = DEFAULT_VALUE;
  try {
      x = Integer.parseInt(prop);
  } catch (NumberFormatException e) {
      // handle format issues
  }
  myMethod(x);
  // ...

You can write much cleaner code to take advantage of a changing and type specific property:

  DynamicIntProperty prop = 
      DynamicPropertyFactory.getInstance().createIntProperty("myProperty", DEFAULT_VALUE);
  // prop.get() may change value at runtime
  myMethod(prop.get());

In addition, you can add callback listener to be notified when the property is changed:

  prop.addCallback(new Runnable() {
      public void run() {
          // ...
      }
  });

A polling framework for dynamic changing configuration sources

Out of the box, in a fixed interval, Pablo will load configuration sources from a local file on classpath as well as a set of URLs defined in a system property.

You can define your own configuration source and poll scheduler by extending appropriate interface/class, and programmatically set it as the backing source of dynamic properties.

  PolledConfigurationSource source = createMyOwnSource();
  AbstractPollingScheduler scheduler = createMyOwnScheduler();
  DynamicPropertyFactory.initWithConfigurationSource(new DynamicConfiguration(source, scheduler));

High performant, thread-safe configurations

Pablo provides a set of configurations that extend from Apache’s Common Configuration which you can read/write properties concurrently. It also provides functionality to aggregate sub-configurations into one composite configuration and determine the value of a property from multiple sub-configurations.