org.apache.commons.configuration2.ImmutableConfiguration Java Examples

The following examples show how to use org.apache.commons.configuration2.ImmutableConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CryptotraderImpl.java    From cryptotrader with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void configure() {

    bind(ConfigurationProvider.class).to(ConfigurationProviderImpl.class).asEagerSingleton();
    bind(Configuration.class).toProvider(ConfigurationProvider.class).asEagerSingleton();
    bind(ImmutableConfiguration.class).to(Configuration.class).asEagerSingleton();
    bind(PropertyController.class).to(PropertyManagerImpl.class).asEagerSingleton();
    bind(PropertyManager.class).to(PropertyController.class).asEagerSingleton();
    bind(ServiceFactory.class).to(ServiceFactoryImpl.class).asEagerSingleton();
    bind(ExecutorFactory.class).to(ExecutorFactoryImpl.class).asEagerSingleton();
    bind(CollectorRegistry.class).toInstance(CollectorRegistry.defaultRegistry);

    bind(Context.class).to(ContextImpl.class).asEagerSingleton();
    bind(Estimator.class).to(EstimatorImpl.class).asEagerSingleton();
    bind(Adviser.class).to(AdviserImpl.class).asEagerSingleton();
    bind(Instructor.class).to(InstructorImpl.class).asEagerSingleton();

    bind(Agent.class).to(AgentImpl.class).asEagerSingleton();
    bind(Pipeline.class).to(PipelineImpl.class).asEagerSingleton();
    bind(Trader.class).to(traderClass).asEagerSingleton();

    bind(Cryptotrader.class).to(CryptotraderImpl.class);

}
 
Example #2
Source File: BuilderConfigurationWrapperFactory.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@code ImmutableConfiguration} object which wraps the specified
 * {@code ConfigurationBuilder}. Each access of the configuration is
 * delegated to a corresponding call on the {@code ImmutableConfiguration} object
 * managed by the builder. This is a convenience method which allows
 * creating wrapper configurations without having to instantiate this class.
 *
 * @param <T> the type of the configuration objects returned by this method
 * @param ifcClass the class of the configuration objects returned by this
 *        method; this must be an interface class and must not be
 *        <b>null</b>
 * @param builder the wrapped {@code ConfigurationBuilder} (must not be
 *        <b>null</b>)
 * @param evSrcSupport the level of {@code EventSource} support
 * @return the wrapper configuration
 * @throws IllegalArgumentException if a required parameter is missing
 * @throws org.apache.commons.configuration2.ex.ConfigurationRuntimeException if an error
 *         occurs when creating the result {@code ImmutableConfiguration}
 */
public static <T extends ImmutableConfiguration> T createBuilderConfigurationWrapper(
        final Class<T> ifcClass, final ConfigurationBuilder<? extends T> builder,
        final EventSourceSupport evSrcSupport)
{
    if (ifcClass == null)
    {
        throw new IllegalArgumentException(
                "Interface class must not be null!");
    }
    if (builder == null)
    {
        throw new IllegalArgumentException("Builder must not be null!");
    }

    return ifcClass.cast(Proxy.newProxyInstance(
            BuilderConfigurationWrapperFactory.class.getClassLoader(),
            fetchSupportedInterfaces(ifcClass, evSrcSupport),
            new BuilderConfigurationWrapperInvocationHandler(builder,
                    evSrcSupport)));
}
 
Example #3
Source File: ServiceFactoryImplTest.java    From cryptotrader with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testLoadMap() throws Exception {

    Map<String, TestInterface> services = target.loadMap(TestInterface.class);
    assertTrue(services.get("TestImpl1") instanceof TestInterface.TestImpl1);
    assertTrue(services.get("TestImpl3") instanceof TestInterface.TestImpl3);
    assertEquals(services.size(), 2, services.toString());

    for (TestInterface s : services.values()) {

        assertNotNull(s.getInjector());

        assertNotNull(s.getInjector().getInstance(ImmutableConfiguration.class));

        try {
            s.getInjector().getInstance(ServiceFactory.class);
            fail();
        } catch (ConfigurationException e) {
            // Success
        }

    }

}
 
Example #4
Source File: App.java    From DataflowTemplates with Apache License 2.0 5 votes vote down vote up
static void startSender(
  String databaseName,
  String databaseUserName,
  String databasePassword,
  String databaseAddress,
  String databasePort,
  String gcpProject,
  String gcpPubsubTopic,
  String offsetStorageFile,
  String databaseHistoryFile,
  Boolean inMemoryOffsetStorage,
  Boolean singleTopicMode,
  String commaSeparatedWhiteListedTables,
  String rdbms,
  ImmutableConfiguration debeziumConfig) {
DebeziumToPubSubDataSender dataSender =
    new DebeziumToPubSubDataSender(
        databaseName,
        databaseUserName,
        databasePassword,
        databaseAddress,
        Integer.parseInt(databasePort),
        gcpProject,
        gcpPubsubTopic,
        offsetStorageFile,
        databaseHistoryFile,
        inMemoryOffsetStorage,
        singleTopicMode,
        new HashSet<>(Arrays.asList(commaSeparatedWhiteListedTables.split(","))),
        rdbms,
        debeziumConfig);
    dataSender.run();
}
 
Example #5
Source File: NaBL2ConfigReaderWriter.java    From spoofax with Apache License 2.0 5 votes vote down vote up
public static Collection<IMessage> validate(ImmutableConfiguration config, MessageBuilder mb) {
    final String allFlags = String.join(" ", Arrays.asList(Flag.values()).stream().map(Flag::name)
            .map(String::toLowerCase).collect(Collectors.toList()));
    List<IMessage> messages = Lists.newArrayList();
    for(String flag : splitString(config.getString(PROP_DEBUG, ""))) {
        try {
            Flag.valueOf(flag.toUpperCase());
        } catch(IllegalArgumentException ex) {
            messages.add(mb.withMessage("Invalid NaBL2 debug flag: " + flag + ", must be one of: " + allFlags + ".")
                    .build());
        }
    }
    return messages;
}
 
Example #6
Source File: ProjectConfig.java    From spoofax with Apache License 2.0 5 votes vote down vote up
private static void validateDeps(ImmutableConfiguration config, String key, String name, MessageBuilder mb,
        Collection<IMessage> messages) {
    final List<String> depStrs = config.getList(String.class, key, Lists.<String>newArrayList());
    for(String depStr : depStrs) {
        try {
            LanguageIdentifier.parse(depStr);
        } catch(IllegalArgumentException e) {
            messages.add(mb.withMessage("Invalid " + name + " dependency. " + e.getMessage()).build());
        }
    }
}
 
Example #7
Source File: BuilderConfigurationWrapperFactory.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of
 * {@code BuilderConfigurationWrapperInvocationHandler}.
 *
 * @param wrappedBuilder the wrapped builder
 * @param evSrcSupport the level of {@code EventSource} support
 */
public BuilderConfigurationWrapperInvocationHandler(
        final ConfigurationBuilder<? extends ImmutableConfiguration> wrappedBuilder,
        final EventSourceSupport evSrcSupport)
{
    builder = wrappedBuilder;
    eventSourceSupport = evSrcSupport;
}
 
Example #8
Source File: ConfigurationBuilderResultCreatedEvent.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of {@code ConfigurationBuilderResultCreatedEvent}
 * and initializes its properties.
 *
 * @param source the {@code ConfigurationBuilder} object which triggered
 *        this event (must not be <b>null</b>)
 * @param evType the type of this event (must not be <b>null</b>)
 * @param createdConfiguration the newly created {@code ImmutableConfiguration}
 *        object (must not be <b>null</b>)
 * @throws IllegalArgumentException if a required parameter is null
 */
public ConfigurationBuilderResultCreatedEvent(
        final ConfigurationBuilder<?> source,
        final EventType<? extends ConfigurationBuilderResultCreatedEvent> evType,
        final ImmutableConfiguration createdConfiguration)
{
    super(source, evType);
    if (createdConfiguration == null)
    {
        throw new IllegalArgumentException(
                "Configuration must not be null!");
    }
    configuration = createdConfiguration;
}
 
Example #9
Source File: App.java    From DataflowTemplates with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    final Logger logger = LoggerFactory.getLogger(App.class);

    // Printing the information about the bindings for SLF4J:
    Configuration config = getConnectorConfiguration(args);
    final StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
    System.out.println("Logger Binding: " + binder.getLoggerFactory());
    System.out.println(binder.getLoggerFactoryClassStr());

    String dbPassword = config.getString("databasePassword");
    config.clearProperty("databasePassword");
    logger.info("Configuration for program (with DB password hidden) is: \n{}",
        ConfigurationUtils.toString(config));
    config.setProperty("databasePassword", dbPassword);

    logger.info("GOOGLE_APPLICATION_CREDENTIALS: {}",
        System.getenv("GOOGLE_APPLICATION_CREDENTIALS"));

// Properties to be passed directly to Debezium
ImmutableConfiguration debeziumConfig = config.immutableSubset("debezium");

startSender(
    config.getString("databaseName"),
    config.getString("databaseUsername"),
    config.getString("databasePassword"),
    config.getString("databaseAddress"),
    config.getString("databasePort", "3306"), // MySQL default port is 3306
    config.getString("gcpProject"),
    config.getString("gcpPubsubTopicPrefix"),
    config.getString("offsetStorageFile", DEFAULT_OFFSET_STORAGE_FILE),
    config.getString("databaseHistoryFile", DEFAULT_DATABASE_HISTORY_FILE),
    config.getBoolean("inMemoryOffsetStorage", false),
    config.getBoolean("singleTopicMode", false),
    config.getString("whitelistedTables"),
    config.getString("databaseManagementSystem", DEFAULT_RDBMS),
    debeziumConfig);
}
 
Example #10
Source File: DelegatedPropertiesConfiguration.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public ImmutableConfiguration immutableSubset(String prefix) {
    return configuration.immutableSubset(prefix);
}
 
Example #11
Source File: BaseSettings.java    From batfish with Apache License 2.0 4 votes vote down vote up
public ImmutableConfiguration getImmutableConfiguration() {
  return ConfigurationUtils.unmodifiableConfiguration(_config);
}
 
Example #12
Source File: IBatfishTestAdapter.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Override
public ImmutableConfiguration getSettingsConfiguration() {
  throw new UnsupportedOperationException();
}
 
Example #13
Source File: Batfish.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Override
public ImmutableConfiguration getSettingsConfiguration() {
  return _settings.getImmutableConfiguration();
}
 
Example #14
Source File: AbstractService.java    From cryptotrader with GNU Affero General Public License v3.0 4 votes vote down vote up
@Inject
@VisibleForTesting
public void setConfiguration(ImmutableConfiguration configuration) {
    this.configuration = configuration;
}
 
Example #15
Source File: CommonsConfigurationPropertySource.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
public CommonsConfigurationPropertySource(String name, ImmutableConfiguration configuration) {
    super(name);
    this.configuration = configuration;
}
 
Example #16
Source File: TemplateContextTest.java    From cryptotrader with GNU Affero General Public License v3.0 3 votes vote down vote up
@BeforeMethod
public void setUp() {

    configuration = mock(ImmutableConfiguration.class);

    target = spy(new TestContext());

    target.setConfiguration(configuration);

}
 
Example #17
Source File: ServiceFactoryImplTest.java    From cryptotrader with GNU Affero General Public License v3.0 3 votes vote down vote up
@Test
public void testLoad() throws Exception {

    List<TestInterface> services = target.load(TestInterface.class);
    assertEquals(services.size(), 2);

    for (TestInterface s : services) {

        if (s.getClass() == TestInterface.TestImpl1.class ||
                s.getClass() == TestInterface.TestImpl3.class) {

            assertNotNull(s.getInjector());

            assertNotNull(s.getInjector().getInstance(ImmutableConfiguration.class));

            try {
                s.getInjector().getInstance(ServiceFactory.class);
                fail();
            } catch (ConfigurationException e) {
                // Success
            }

            continue;

        }

        fail("Unknown class : " + s.get());

    }

}
 
Example #18
Source File: TestModule.java    From cryptotrader with GNU Affero General Public License v3.0 3 votes vote down vote up
public TestModule() throws ConfigurationException {

        this.injector = Guice.createInjector();

        ExecutorService service = setMock(ExecutorService.class, newDirectExecutorService());

        when(getMock(ExecutorFactory.class).get(any(Class.class), anyInt())).thenReturn(service);

        Configuration configuration = spy(new Configurations().properties(getResource(CONFIGURATION)));

        setMock(Configuration.class, configuration);

        setMock(ImmutableConfiguration.class, configuration);

    }
 
Example #19
Source File: BuilderConfigurationWrapperFactory.java    From commons-configuration with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a wrapper {@code ImmutableConfiguration} on top of the specified
 * {@code ConfigurationBuilder}. This implementation delegates to
 * {@link #createBuilderConfigurationWrapper(Class, ConfigurationBuilder, EventSourceSupport)}
 * .
 *
 * @param <T> the type of the configuration objects returned by this method
 * @param ifcClass the class of the configuration objects returned by this
 *        method; this must be an interface class and must not be
 *        <b>null</b>
 * @param builder the wrapped {@code ConfigurationBuilder} (must not be
 *        <b>null</b>)
 * @return the wrapper configuration
 * @throws IllegalArgumentException if a required parameter is missing
 * @throws org.apache.commons.configuration2.ex.ConfigurationRuntimeException if an error
 *         occurs when creating the result {@code ImmutableConfiguration}
 */
public <T extends ImmutableConfiguration> T createBuilderConfigurationWrapper(
        final Class<T> ifcClass, final ConfigurationBuilder<? extends T> builder)
{
    return createBuilderConfigurationWrapper(ifcClass, builder,
            getEventSourceSupport());
}
 
Example #20
Source File: ServiceFactoryImpl.java    From cryptotrader with GNU Affero General Public License v3.0 3 votes vote down vote up
@Inject
public ServiceFactoryImpl(Injector injector) {

    this.injector = Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() {

            Configuration c = injector.getInstance(Configuration.class);

            bind(ImmutableConfiguration.class).toInstance(c);

        }
    });

}
 
Example #21
Source File: CustomPropertySourceConfigurer.java    From airsonic with GNU General Public License v3.0 3 votes vote down vote up
public void initialize(ConfigurableWebApplicationContext ctx) {

        ApacheCommonsConfigurationService configurationService = new ApacheCommonsConfigurationService();
        ImmutableConfiguration snapshot = configurationService.getImmutableSnapshot();

        PropertySource ps = new CommonsConfigurationPropertySource("airsonic-pre-init-configs", snapshot);


        ctx.getEnvironment().getPropertySources().addLast(ps);

        addDataSourceProfile(ctx);
    }
 
Example #22
Source File: IBatfish.java    From batfish with Apache License 2.0 2 votes vote down vote up
/**
 * Get batfish settings
 *
 * @return the {@link ImmutableConfiguration} that represents batfish settings.
 */
ImmutableConfiguration getSettingsConfiguration();
 
Example #23
Source File: IncrementalDataPlaneSettings.java    From batfish with Apache License 2.0 2 votes vote down vote up
/**
 * Create new settings, initialize with defaults, but also copy over settings from {@code
 * configSource}
 *
 * @param configSource the configuration options to override the defaults
 */
public IncrementalDataPlaneSettings(ImmutableConfiguration configSource) {
  this();
  ConfigurationUtils.copy(configSource, _config);
}
 
Example #24
Source File: ConfigurationBuilderResultCreatedEvent.java    From commons-configuration with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the newly created {@code ImmutableConfiguration} object.
 *
 * @return the newly created {@code ImmutableConfiguration}
 */
public ImmutableConfiguration getConfiguration()
{
    return configuration;
}