Example usage for org.apache.commons.configuration Configuration getInt

List of usage examples for org.apache.commons.configuration Configuration getInt

Introduction

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

Prototype

int getInt(String key, int defaultValue);

Source Link

Document

Get a int associated with the given configuration key.

Usage

From source file:com.cisco.oss.foundation.message.RabbitMQMessagingFactory.java

static void connect() {
    try {//w w w  .j  av a2s.co m
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setAutomaticRecoveryEnabled(true);
        connectionFactory.setTopologyRecoveryEnabled(true);

        Configuration configuration = ConfigurationFactory.getConfiguration();
        Configuration subsetBase = configuration.subset("service.rabbitmq");
        Configuration subsetSecurity = subsetBase.subset("security");

        int requestHeartbeat = subsetBase.getInt("requestHeartbeat", 10);
        connectionFactory.setRequestedHeartbeat(requestHeartbeat);

        String userName = subsetSecurity.getString("userName");
        String password = subsetSecurity.getString("password");
        boolean isEnabled = subsetSecurity.getBoolean("isEnabled");

        final Map<String, Map<String, String>> serverConnections = ConfigUtil
                .parseComplexArrayStructure("service.rabbitmq.connections");
        final ArrayList<String> serverConnectionKeys = Lists.newArrayList(serverConnections.keySet());
        Collections.sort(serverConnectionKeys);

        if (isEnabled) {
            connectionFactory.setUsername(userName);
            connectionFactory.setPassword(password);

        }

        List<Address> addresses = new ArrayList<>(5);

        for (String serverConnectionKey : serverConnectionKeys) {

            Map<String, String> serverConnection = serverConnections.get(serverConnectionKey);

            String host = serverConnection.get("host");
            int port = Integer.parseInt(serverConnection.get("port"));
            addresses.add(new Address(host, port));
            //              connectionFactory.setHost(host);
            //              connectionFactory.setPort(Integer.parseInt(port));
        }
        Address[] addrs = new Address[0];
        connection = connectionFactory.newConnection(addresses.toArray(addrs));
        connection.addBlockedListener(new BlockedListener() {
            public void handleBlocked(String reason) throws IOException {
                LOGGER.error("RabbitMQ connection is now blocked. Port: {}, Reason: {}", connection.getPort(),
                        reason);
                IS_BLOCKED.set(true);
            }

            public void handleUnblocked() throws IOException {
                LOGGER.info("RabbitMQ connection is now un-blocked. Port: {}", connection.getPort());
                IS_BLOCKED.set(false);
            }
        });

        connection.addShutdownListener(new ShutdownListener() {
            @Override
            public void shutdownCompleted(ShutdownSignalException cause) {
                LOGGER.error("Connection shutdown detected. Reason: {}", cause.toString(), cause);
            }
        });

        IS_CONNECTED.set(true);
        INIT_LATCH.countDown();

    } catch (Exception e) {
        LOGGER.error("can't create RabbitMQ Connection: {}", e, e);
        //            triggerReconnectThread();
        throw new QueueException(e);
    }
}

From source file:com.comcast.viper.flume2storm.connection.parameters.SimpleConnectionParameters.java

/**
 * @param configuration/*  ww w.java 2s  .c  o m*/
 *          The configuration to use
 * @return The newly built {@link SimpleConnectionParameters} based on the
 *         configuration specified
 * @throws F2SConfigurationException
 *           If the configuration is invalid
 */
public static SimpleConnectionParameters from(Configuration configuration) throws F2SConfigurationException {
    SimpleConnectionParameters result = new SimpleConnectionParameters();
    try {
        result.setHostname(configuration.getString(HOSTNAME, HOSTNAME_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(HOSTNAME, configuration.getProperty(HOSTNAME), e);
    }
    try {
        result.setPort(configuration.getInt(PORT, PORT_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(PORT, configuration.getProperty(PORT), e);
    }
    return result;
}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getAdminPasswordResetUrl(MerchantUserInformation information, MerchantStore store)
        throws Exception {

    Configuration conf = PropertiesUtil.getConfiguration();

    StringBuffer urlconstruct = new StringBuffer();
    StringBuffer downloadurl = new StringBuffer();
    Calendar endDate = Calendar.getInstance();
    endDate.add(Calendar.DATE, conf.getInt("core.product.file.downloadmaxdays", 2)); // add 2 days
    Date denddate = endDate.getTime();
    String sedate = DateUtil.formatDate(denddate);

    // order id and, expiration date and language
    urlconstruct.append(information.getMerchantUserId()).append("|").append(sedate);

    String lang = conf.getString("core.system.defaultlanguage", "en");
    if (information != null) {
        lang = information.getUserlang();
    }//from  w ww . j  a  v a  2 s. c o  m

    String file = EncryptionUtil.encrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant),
            urlconstruct.toString());

    downloadurl.append(ReferenceUtil.buildCentralUri(store))
            .append("/anonymous" + conf.getString("core.salesmanager.core.resetPasswordAction"))
            .append("?urlId=").append(file).append("&lang=").append(lang);

    return downloadurl.toString();

}

From source file:com.linkedin.pinot.core.query.scheduler.tokenbucket.TokenPriorityScheduler.java

public static TokenPriorityScheduler create(@Nonnull Configuration config, @Nonnull QueryExecutor queryExecutor,
        @Nonnull ServerMetrics metrics) {
    final ResourceManager rm = new PolicyBasedResourceManager(config);
    final SchedulerGroupFactory groupFactory = new SchedulerGroupFactory() {
        @Override/*  w  w  w  . ja va 2s .  co m*/
        public SchedulerGroup create(Configuration config, String groupName) {
            // max available tokens per millisecond equals number of threads (total execution capacity)
            // we are over provisioning tokens here because its better to keep pipe full rather than empty
            int maxTokensPerMs = rm.getNumQueryRunnerThreads() + rm.getNumQueryWorkerThreads();
            int tokensPerMs = config.getInt(TOKENS_PER_MS_KEY, maxTokensPerMs);
            int tokenLifetimeMs = config.getInt(TOKEN_LIFETIME_MS_KEY, DEFAULT_TOKEN_LIFETIME_MS);

            return new TokenSchedulerGroup(groupName, tokensPerMs, tokenLifetimeMs);
        }
    };

    MultiLevelPriorityQueue queue = new MultiLevelPriorityQueue(config, rm, groupFactory,
            new TableBasedGroupMapper());
    return new TokenPriorityScheduler(rm, queryExecutor, queue, metrics);
}

From source file:com.manydesigns.mail.quartz.MailScheduler.java

public static void setupMailScheduler(MailQueueSetup mailQueueSetup, String group) {
    Configuration mailConfiguration = mailQueueSetup.getMailConfiguration();
    if (mailConfiguration != null) {
        if (mailConfiguration.getBoolean(MailProperties.MAIL_QUARTZ_ENABLED, false)) {
            logger.info("Scheduling mail sends with Quartz job");
            try {
                String serverUrl = mailConfiguration.getString(MailProperties.MAIL_SENDER_SERVER_URL);
                logger.info("Scheduling mail sends using URL: {}", serverUrl);

                Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
                JobDetail job = JobBuilder.newJob(URLInvokeJob.class).withIdentity("mail.sender", group)
                        .usingJobData(URLInvokeJob.URL_KEY, serverUrl).build();

                int pollInterval = mailConfiguration.getInt(MailProperties.MAIL_SENDER_POLL_INTERVAL,
                        DEFAULT_POLL_INTERVAL);

                Trigger trigger = TriggerBuilder.newTrigger().withIdentity("mail.sender.trigger", group)
                        .startNow().withSchedule(SimpleScheduleBuilder.simpleSchedule()
                                .withIntervalInMilliseconds(pollInterval).repeatForever())
                        .build();//from w  ww  .  j a v a 2  s. co  m

                scheduler.scheduleJob(job, trigger);
            } catch (Exception e) {
                logger.error("Could not schedule mail sender job", e);
            }
        } else {
            logger.info("Mail scheduling using Quartz is disabled");
        }
    }
}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getInternalDownloadFileUrl(int merchantId, long downloadId) throws Exception {

    Configuration conf = PropertiesUtil.getConfiguration();

    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    MerchantStore store = mservice.getMerchantStore(merchantId);

    // ***build fileid***
    StringBuffer urlconstruct = new StringBuffer();
    StringBuffer downloadurl = new StringBuffer();
    Calendar endDate = Calendar.getInstance();
    endDate.add(Calendar.DATE, conf.getInt("core.product.file.downloadmaxdays", 2)); // add 2 days
    Date denddate = endDate.getTime();
    String sedate = DateUtil.formatDate(denddate);

    urlconstruct.append(downloadId).append("|").append(sedate).append("|").append(merchantId);

    String file = EncryptionUtil.encrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant),
            urlconstruct.toString());//from  w ww.j  a va2s . co m

    downloadurl.append(ReferenceUtil.buildCheckoutUri(store))
            .append(conf.getString("core.salesmanager.core.downloadFileAction")).append("?fileId=").append(file)
            .append("&mod=productfile");

    return downloadurl.toString();

}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getOrderDownloadFileUrl(Order order, Customer customer) throws Exception {

    Configuration conf = PropertiesUtil.getConfiguration();

    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    MerchantStore store = mservice.getMerchantStore(order.getMerchantId());

    // ***build fileid***
    StringBuffer urlconstruct = new StringBuffer();
    StringBuffer downloadurl = new StringBuffer();
    Calendar endDate = Calendar.getInstance();
    endDate.add(Calendar.DATE, conf.getInt("core.product.file.downloadmaxdays", 2)); // add 2 days
    Date denddate = endDate.getTime();
    String sedate = DateUtil.formatDate(denddate);

    // order id and, expiration date and language
    urlconstruct.append(order.getOrderId()).append("|").append("|").append(sedate);

    String lang = conf.getString("core.system.defaultlanguage", "en");
    if (customer != null) {
        lang = customer.getCustomerLang();
    }/* w  ww . j a v  a  2 s . c  o  m*/

    String file = EncryptionUtil.encrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant),
            urlconstruct.toString());

    downloadurl.append(ReferenceUtil.buildCheckoutUri(store))
            .append(conf.getString("core.salesmanager.core.viewFilesAction")).append("?fileId=").append(file)
            .append("&lang=").append(lang);

    return downloadurl.toString();

}

From source file:com.comcast.viper.flume2storm.connection.parameters.KryoNetConnectionParameters.java

/**
 * @param config//  w  w w  . ja v  a2s .com
 *          The configuration to use
 * @return The newly constructed {@link KryoNetConnectionParameters} based on
 *         the {@link Configuration} specified
 * @throws F2SConfigurationException
 *           If the configuration specified is invalid
 */
public static KryoNetConnectionParameters from(Configuration config) throws F2SConfigurationException {
    KryoNetConnectionParameters result = new KryoNetConnectionParameters();
    try {
        String hostname = config.getString(ADDRESS);
        if (hostname == null) {
            try {
                hostname = InetAddress.getLocalHost().getHostAddress();
            } catch (final UnknownHostException e) {
                hostname = ADDRESS_DEFAULT;
            }
        }
        assert hostname != null;
        result.setAddress(hostname);
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, ADDRESS, e);
    }
    try {
        result.setServerPort(config.getInt(PORT, PORT_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, PORT, e);
    }
    try {
        result.setObjectBufferSize(config.getInt(OBJECT_BUFFER_SZ, OBJECT_BUFFER_SIZE_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, OBJECT_BUFFER_SZ, e);
    }
    try {
        result.setWriteBufferSize(config.getInt(WRITE_BUFFER_SZ, WRITE_BUFFER_SIZE_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, WRITE_BUFFER_SZ, e);
    }
    return result;
}

From source file:com.yahoo.ads.pb.PistachiosServer.java

public static void simple(Pistachios.Processor processor) {
    try {/*from   w  ww . j  a  v a2 s  .c om*/
        Configuration conf = ConfigurationManager.getConfiguration();

        TServerTransport serverTransport = new TServerSocket(9090);
        //TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));

        // Use this for a multithreaded server
        TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport);
        args.processor(processor);
        args.minWorkerThreads = conf.getInt("Pistachio.Thrift.MinWorkerThreads", 50);
        args.maxWorkerThreads = conf.getInt("Pistachio.Thrift.MaxWorkerThreads", 200);
        args.stopTimeoutUnit = TimeUnit.SECONDS;
        args.stopTimeoutVal = conf.getInt("Pistachio.Thrift.StopTimeoutVal", 60);
        TServer server = new TThreadPoolServer(args);

        System.out.println("Starting the simple server...");
        server.serve();
    } catch (Exception e) {
        logger.info("error ", e);
        e.printStackTrace();
    }
}

From source file:com.boozallen.cognition.ingest.storm.topology.StormParallelismConfig.java

StormParallelismConfig(Configuration conf) {
    this.parallelismHint = conf.getInt(PARALLELISM_HINT, PARALLELISM_HINT_DEFAULT);
    this.numTasks = conf.getInt(NUM_TASKS, parallelismHint);
}