Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2014 dc-square GmbH
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *       http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.dcsquare.hivemq.spi.config;
import static com.google.common.collect.Lists.newArrayList;

General utilities and convenient methods for dealing with configurations and properties files.

Author(s):
Dominik Obermaier
Since:
1.4
public class Configurations {


    
Creates a new configuration provider with the given org.apache.commons.configuration.AbstractConfigurations.

Parameters:
configurations the configurations
Returns:
a provider for the given configurations
    public static Provider<Iterable<? extends AbstractConfiguration>> newConfigurationProvider(final AbstractConfiguration... configurations) {
        return new Provider<Iterable<? extends AbstractConfiguration>>() {
            @Override
            public Iterable<? extends AbstractConfigurationget() {
                return newArrayList(configurations);
            }
        };
    }

    
A utility method which returns an empty Configuration Provider. This is a convenient method which can be used by plugins which don't need configurations

Returns:
an empty Configuration Provider
    public static Provider<Iterable<? extends AbstractConfiguration>> noConfigurationNeeded() {
        return new Provider<Iterable<? extends AbstractConfiguration>>() {
            @Override
            public Iterable<? extends AbstractConfigurationget() {
                return newArrayList();
            }
        };
    }

    
Creates a new Properties file configuration which automatically reloads itself in the given interval.

Searches for the configuration file in the plugins folder of HiveMQ.

Parameters:
fileName the file name of the properties file which is located in the plugins folder of HiveMQ.
reReadSchedule the time schedule when a reload should occur
timeUnit the time unit of the reReadSchedule
Returns:
a reloadable properties file configuration
    public static AbstractConfiguration newReloadablePropertiesConfiguration(final String fileNamefinal int reReadSchedulefinal TimeUnit timeUnit) {
        final PropertiesFileDatasource datasource = new PropertiesFileDatasource(PathUtils.getPluginFolder(), fileName);
        final Long scheduleInMillis = timeUnit.toMillis(reReadSchedule);
        final AbstractPollingScheduler scheduler = new FixedDelayPollingScheduler(scheduleInMillis.intValue(), scheduleInMillis.intValue(), true);
        return new DynamicConfiguration(datasourcescheduler);
    }
New to GrepCode? Check out our FAQ X