Example usage for org.apache.commons.configuration ConfigurationException ConfigurationException

List of usage examples for org.apache.commons.configuration ConfigurationException ConfigurationException

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationException ConfigurationException.

Prototype

public ConfigurationException(Throwable cause) 

Source Link

Document

Constructs a new ConfigurationException with specified nested Throwable.

Usage

From source file:org.topology.bgp_ls.config.nodes.impl.PeerConfigurationImpl.java

/**
 * @param automaticStartInterval the automaticStartInterval to set
 *//*from  ww  w .  j  a  v a 2  s .co m*/
public void setAutomaticStartInterval(int automaticStartInterval) throws ConfigurationException {
    if (automaticStartInterval < 0)
        throw new ConfigurationException("Illegal automatic start interval given: " + connectRetryTime);

    this.automaticStartInterval = automaticStartInterval;
}

From source file:org.topology.bgp_ls.config.nodes.impl.RoutingFilterConfigurationParser.java

RoutingFilterConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException {
    List<HierarchicalConfiguration> prefixList = config.configurationsAt("Prefixes");
    RoutingFilterConfigurationImpl rfc = null;

    if (prefixList.size() > 1)
        throw new ConfigurationException("more then one subnode specified");

    if (prefixList.size() == 1)
        rfc = parsePrefixFilter(prefixList.get(0));

    if (rfc == null)
        throw new ConfigurationException("no filter type specified");

    rfc.setName(config.getString("[@name]", ""));

    return rfc;//from   w w  w  . ja  va  2s.  c o  m
}

From source file:org.topology.bgp_ls.config.nodes.impl.RoutingFilterConfigurationParser.java

private RoutingFilterConfigurationImpl parsePrefixFilter(HierarchicalConfiguration config)
        throws ConfigurationException {
    PrefixRoutingFilterConfigurationImpl prfc = new PrefixRoutingFilterConfigurationImpl();

    for (HierarchicalConfiguration subConfig : config.configurationsAt("Prefix")) {
        String rep = subConfig.getString("[@value]");

        if (StringUtils.isBlank(rep))
            throw new ConfigurationException("empty prefix specified");

        prfc.getFilterPrefixes().add(nlriParser.parseNlri(rep));
    }/*from  w  w  w.j  a  va  2s  .c  om*/

    return prfc;
}

From source file:org.topology.bgp_ls.config.nodes.impl.ServerConfigurationImpl.java

public ServerConfigurationImpl(InetAddress addr, int port) throws ConfigurationException {
    if (port < 0 || port > 65535)
        throw new ConfigurationException("port " + port + " not allowed");

    this.port = port;
    this.listenAddress = new InetSocketAddress(addr, port);
}

From source file:org.ublog.benchmark.cassandra.DataStoreCassandra.java

public void initialize() throws Exception {
    this.keyspace = "Twitter";

    Configuration conf = new PropertiesConfiguration("cassandra.properties");
    String[] nodes = conf.getStringArray("node");
    this.max_active_connections = conf.getInt("maxActiveConnections");
    this.partitioner = conf.getString("partitioner");
    this.inst = new String[nodes.length];
    for (int i = 0; i < nodes.length; i++) {
        String[] split = nodes[i].split(":");
        if (split.length == 2) {
            int port = new Integer(split[1]);
            this.inst[i] = InetAddress.getByName(split[0]).getHostName() + ":" + port;
        } else {/* w  w w .ja va  2  s . c  o  m*/
            logger.error("Nodes configuration is wrong");
            throw new ConfigurationException("Nodes must be in the format hostName:port");
        }
    }

    String hosts = "";
    int i = 0;
    for (String str : inst) {
        if (i < this.inst.length - 1) {
            hosts += str + ",";
        } else {
            hosts += str;
        }
        i++;
    }
    System.out.println("HOSTS: " + hosts);
    CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator(hosts);

    cassandraHostConfigurator.setMaxActive(this.max_active_connections);
    cassandraHostConfigurator.setMaxIdle(CassandraHost.DEFAULT_MAX_IDLE);
    cassandraHostConfigurator.setExhaustedPolicy(ExhaustedPolicy.WHEN_EXHAUSTED_BLOCK);
    cassandraHostConfigurator.setMaxWaitTimeWhenExhausted(CassandraHost.DEFAULT_MAX_WAITTIME_WHEN_EXHAUSTED);
    cassandraHostConfigurator.setTimestampResolution("MICROSECONDS");
    System.out.println(cassandraHostConfigurator.toString());
    this.connPool = CassandraClientPoolFactory.getInstance().createNew(cassandraHostConfigurator);
}

From source file:org.ublog.benchmark.social.SocialBenchmark.java

@Override
public void initialize(Configuration conf) throws ConfigurationException {
    this.initialTweetsFactor = conf.getDouble("benchmark.social.initialTweetsFactor");

    Utils.MAX_MESSAGES_IN_TIMELINE = conf.getInt("benchmark.social.maximumMessagesTimeline");
    Utils.MaxNTweets = conf.getInt("benchmark.social.maximumTweetsPerUser");
    long seedNextOperation = conf.containsKey("benchmark.social.seedNextOperation")
            ? conf.getLong("benchmark.social.seedNextOperation")
            : System.nanoTime();//from  ww w.  j a  v  a2s . c  o  m
    long seedOwner = conf.containsKey("benchmark.social.seedOwner") ? conf.getLong("benchmark.social.seedOwner")
            : System.nanoTime();
    long seedTopic = conf.containsKey("benchmark.social.seedTopic") ? conf.getLong("benchmark.social.seedTopic")
            : System.nanoTime();
    long seedStartFollow = conf.containsKey("benchmark.social.seedStartFollow")
            ? conf.getLong("benchmark.social.seedStartFollow")
            : System.nanoTime();

    this.rndOp = new Random(seedNextOperation);
    this.rndOwner = new Random(seedOwner);
    this.rndTopic = new Random(seedTopic);
    this.rndStartFollow = new Random(seedStartFollow);

    this.probabilitySearchPerTopic = conf.getDouble("benchmark.social.probabilities.probabilitySearchPerTopic");
    this.probabilitySearchPerOwner = conf.getDouble("benchmark.social.probabilities.probabilitySearchPerOwner");
    this.probabilityGetRecentTweets = conf
            .getDouble("benchmark.social.probabilities.probabilityGetRecentTweets");
    this.probabilityGetFriendsTimeline = conf
            .getDouble("benchmark.social.probabilities.probabilityGetFriendsTimeline");
    this.probabilityStartFollowing = conf.getDouble("benchmark.social.probabilities.probabilityStartFollowing");
    this.probabilityStopFollowing = conf.getDouble("benchmark.social.probabilities.probabilityStopFollowing");
    if (this.probabilityGetFriendsTimeline + this.probabilityGetRecentTweets + this.probabilitySearchPerOwner
            + this.probabilitySearchPerTopic + this.probabilityStartFollowing
            + this.probabilityStopFollowing > 1) {
        logger.warn("The sum of all probabilities must be less or equal than 1.");
        throw new ConfigurationException("The sum of all probabilities must be less or equal than 1.");
    }

    String serverName = conf.getString("benchmark.server.name");
    int serverPort = conf.getInt("benchmark.server.port");
    this.remoteGraphServer = this.getRemoteGraphServer(serverName, serverPort);
    try {
        this.hasInitiated = this.remoteGraphServer.init(this.totalSize);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:org.ublog.benchmark.voldemort.DataStoreVoldemort.java

public void initialize() throws Exception {
    Configuration conf = new PropertiesConfiguration("voldemort.properties");
    String[] nodes = conf.getStringArray("node");
    List<String> listNodes = new ArrayList<String>();
    for (String tmp : nodes) {
        String[] split = tmp.split(":");
        if (split.length == 2) {
            int port = new Integer(split[1]);
            listNodes.add("tcp://" + split[0] + ":" + port);
        } else {//from  w  w  w . ja  v  a2  s . co m
            logger.error("Nodes configuration is wrong");
            throw new ConfigurationException("Nodes must be in the format hostName:port");
        }
    }

    ClientConfig config = new ClientConfig();
    config.setBootstrapUrls(listNodes);
    config.setMaxConnectionsPerNode(3);
    config.setMaxThreads(3);
    this.factory = new SocketStoreClientFactory(config);
    this.users = factory.getStoreClient("users");
    this.friendsTimeLine = factory.getStoreClient("friendsTimeLine");
    this.tweets = factory.getStoreClient("tweets");
    this.tagsStore = factory.getStoreClient("tags");
}

From source file:org.veronicadb.core.configuration.ConfigurationManager.java

protected Configuration loadConfiguration(ConfigType type, String configPath) throws ConfigurationException {
    Configuration configuration = null;
    switch (type) {
    case PROP://from w w  w  . j  a  v a2s  . c o  m
        configuration = new PropertiesConfiguration(configPath);
        break;
    case XML:
        configuration = new XMLConfiguration(configPath);
        break;
    default:
        throw new ConfigurationException("Invalid configuration type");
    }
    return configuration;
}

From source file:org.veronicadb.core.server.VServer.java

public VServer() throws IOException, ConfigurationException {
    try {//from w  ww  .  j a v  a  2  s  . c  o  m
        this.port = ConfigurationManager.getInstance().getConfig().getInt(PROP_BIND_PORT, 7992);
    } catch (ConfigurationException | URISyntaxException e) {
        throw new ConfigurationException(e);
    }
    this.channel = ServerSocketChannel.open();
}

From source file:org.waveprotocol.wave.util.settings.SettingsBinder.java

/**
 * Bind configuration parameters into Guice Module.
 *
 * @return a Guice module configured with setting support.
 * @throws ConfigurationException on configuration error
 *//*from  w w w. ja v a  2 s .  c o  m*/
public static Module bindSettings(String propertiesFileKey, Class<?>... settingsArg)
        throws ConfigurationException {
    final CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    String propertyFile = config.getString(propertiesFileKey);
    if (propertyFile != null) {
        config.addConfiguration(new PropertiesConfiguration(propertyFile));
    }

    List<Field> fields = new ArrayList<Field>();
    for (Class<?> settings : settingsArg) {
        fields.addAll(Arrays.asList(settings.getDeclaredFields()));
    }

    // Reflect on settings class and absorb settings
    final Map<Setting, Field> settings = new LinkedHashMap<Setting, Field>();
    for (Field field : fields) {
        if (!field.isAnnotationPresent(Setting.class)) {
            continue;
        }

        // Validate target type
        SettingTypeValidator typeHelper = supportedSettingTypes.get(field.getType());
        if (typeHelper == null || !typeHelper.check(field.getGenericType())) {
            throw new IllegalArgumentException(field.getType() + " is not one of the supported setting types");
        }

        Setting setting = field.getAnnotation(Setting.class);
        settings.put(setting, field);
    }

    // Now validate them
    List<String> missingProperties = new ArrayList<String>();
    for (Setting setting : settings.keySet()) {
        if (setting.defaultValue().isEmpty()) {
            if (!config.containsKey(setting.name())) {
                missingProperties.add(setting.name());
            }
        }
    }
    if (missingProperties.size() > 0) {
        StringBuilder error = new StringBuilder();
        error.append("The following required properties are missing from the server configuration: ");
        error.append(Joiner.on(", ").join(missingProperties));
        throw new ConfigurationException(error.toString());
    }

    // bundle everything up in an injectable guice module
    return new AbstractModule() {

        @Override
        protected void configure() {
            // We must iterate the settings a third time when binding.
            // Note: do not collapse these loops as that will damage
            // early error detection. The runtime is still O(n) in setting count.
            for (Map.Entry<Setting, Field> entry : settings.entrySet()) {
                Class<?> type = entry.getValue().getType();
                Setting setting = entry.getKey();

                if (int.class.equals(type)) {
                    Integer defaultValue = null;
                    if (!setting.defaultValue().isEmpty()) {
                        defaultValue = Integer.parseInt(setting.defaultValue());
                    }
                    bindConstant().annotatedWith(Names.named(setting.name()))
                            .to(config.getInteger(setting.name(), defaultValue));
                } else if (boolean.class.equals(type)) {
                    Boolean defaultValue = null;
                    if (!setting.defaultValue().isEmpty()) {
                        defaultValue = Boolean.parseBoolean(setting.defaultValue());
                    }
                    bindConstant().annotatedWith(Names.named(setting.name()))
                            .to(config.getBoolean(setting.name(), defaultValue));
                } else if (String.class.equals(type)) {
                    bindConstant().annotatedWith(Names.named(setting.name()))
                            .to(config.getString(setting.name(), setting.defaultValue()));
                } else {
                    String[] value = config.getStringArray(setting.name());
                    if (value.length == 0 && !setting.defaultValue().isEmpty()) {
                        value = setting.defaultValue().split(",");
                    }
                    bind(new TypeLiteral<List<String>>() {
                    }).annotatedWith(Names.named(setting.name())).toInstance(ImmutableList.copyOf(value));
                }
            }
        }
    };
}