Code Monkey home page Code Monkey logo

archaius's Introduction

Archaius is a configuration library for accessing a mixture of static as well as dynamic configurations as a single configuration unit.

There are two key concepts to note:

  • Properties that can be read by your code.
  • Configurations that organize properties into objects you can bootstrap your application with.

Features

  • Lock-free property reads.
  • Dependency Injection (i.e., Guice) friendly so you don't have to rely on static code execution.

2.x Changes

  • Not backwards compatible with 1.x.
  • Clean separation of API and backing configurations (i.e. commons-configuration, typesafe-configuration, etc).
  • Minimal external dependencies.
  • Improved bootstrapping process that doesn't rely on class loading.

Getting Started

Archaius provides a set of specialized configuration classes that may be combined using com.netflix.archaius.api.config.CompositeConfig into a specific override structure.
Check out com.netflix.archaius.ProxyFactoryTest (under archaius2-core/test/java/) for an example on how to bootstrap a config and access dynamic properties from it.

Accessing configuration

All com.netflix.archaius.api.Config (under archaius2-api/) derived classes provide access to their underlying configuration via the numerous getString(), getInt(), getBoolean() methods.
In addition to basic primitives and collections Config will allow parsing to any type that has a constructor that takes a single String argument or a static valueOf(String.class) method.

Replacements

Archaius supports standard variable replacement syntax such as ${other.property.name}.

Configuration loaders

Archaius has a default built in loader for .properties files but can also be extended with custom property specifications such as HOCON. In addition multiple contextual overrides for a single configuration resource name may be derived using a com.netflix.archaius.api.CascadeStrategy. The strategy may also specify replacements from already loaded configurations (such as System and Environment properties).

Dynamic Properties

One of the core differentiators between Archaius and other configuration libraries is its support for dynamically changing configuration. Traditionally applications require a restart whenever configuration changes. This can result in unnecessary service interruption during minor configuration changes, such as timeout values. Through Archaius, code can have direct access to the most recent configuration without the need to restart. In addition, code can react to configuration changes by registering a change handler.

Dynamic configuration support is split into the configuration loading and property value resolution.

Configuration loading

When adding a DynamicConfig derived configuration CompositeConfig will automatically register for configuration change notifications and incorporate new values into the main configuration.
Archaius provides a base PollingDynamicConfig for use with configuration sources that are polled frequently to refresh the entire configuration snapshot. Implement Config directly for fine grained configuration sources, such as ZooKeeper, which support updates at the individual property granularity.

config.addConfig(new PollingDynamicConfig(
            "REMOTE", 
            new URLConfigReader("http://remoteconfigservice/snapshot"), 
            new FixedPollingStrategy(30, TimeUnit.SECONDS)) 

Property access

Use the Property API for optimized access to any property that is expected to be updated at runtime. Access to dynamic configuration follows two access patterns. The first (and most common) is to get the most recent value directly from a Property object.
Property optimizes caching of the resolved property value (from the hierarchy) and is much more efficient than calling the Config object for frequently accessed properties.
The second, and more advanced, access pattern is to react to property value changes via a com.netflix.archaius.api.PropertyListener.

To create a fast property factory using any Config as the source

DefaultPropertyFactory factory = DefaultPropertyFactory.from(config);

To create a com.netflix.archaius.api.Property object

Property<Integer> timeout = factory.getProperty("server.timeout").asInteger(DEFAULT_TIMEOUT_VALUE);

To access the cached property value

Thread.sleep(timeout.get());

To react to property change notification

Property<Integer> timeout = factory
    .getProperty("server.timeout")
    .asInteger() 
    .addListener(new PropertyListener<Integer>() {
        public void onChange(Integer value) {
            socket.setReadTimeout(value);
        }
        
        public void onError(Throwable error) {
        }
    });

archaius's People

Contributors

elandau avatar rgallardo-netflix avatar akang31 avatar howardyuan avatar kilink avatar qiangdavidliu avatar twicksell avatar brharrington avatar rpalcolea avatar gorzell avatar tcellucci avatar codegass avatar jhspaybar avatar carl-mastrangelo avatar shanman190 avatar rspieldenner avatar asibross avatar dandew avatar gavinbunney avatar gdespres avatar jlisam avatar jkschneider avatar jonathanbond avatar drtechniko avatar noel-yap avatar rahulsom avatar smadappa avatar spencergibb avatar younver avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.