Example usage for java.lang Integer getInteger

List of usage examples for java.lang Integer getInteger

Introduction

In this page you can find the example usage for java.lang Integer getInteger.

Prototype

public static Integer getInteger(String nm, Integer val) 

Source Link

Document

Returns the integer value of the system property with the specified name.

Usage

From source file:org.wisdom.maven.utils.ChameleonInstanceHolder.java

/**
 * Methods call by the test framework to discover the server name and port.
 *
 * @throws Exception if the service is not running.
 *///  w w w  . j a  va 2 s  .co  m
private static void retrieveServerMetadata() throws Exception {
    if (get() == null) {
        throw new IllegalStateException(
                "Cannot retrieve the server metadata - no reference to Chameleon stored " + "in the holder");
    }

    int factor = Integer.getInteger("time.factor", 1);
    if (factor != 1) {
        TimeUtils.TIME_FACTOR = factor;
    }

    // Before checking, ensure stability.
    ServiceReference[] references = get().waitForStability().context()
            .getAllServiceReferences(WisdomEngine.class.getName(), null);

    if (references == null || references.length == 0) {
        references = get().waitForStability().context().getAllServiceReferences(WisdomEngine.class.getName(),
                null);
    }

    if (references == null || references.length == 0) {
        throw new IllegalStateException("Cannot retrieve the Wisdom Engine service");
    }

    Object engine = get().context().getService(references[0]);
    HOST_NAME = (String) engine.getClass().getMethod("hostname").invoke(engine);
    HTTP_PORT = (int) engine.getClass().getMethod("httpPort").invoke(engine);
    HTTPS_PORT = (int) engine.getClass().getMethod("httpsPort").invoke(engine);
}

From source file:org.tomitribe.tribestream.registryng.test.Registry.java

public <T> T withRetries(final Supplier<T> task, final String... description) {
    Throwable lastErr = null;/*www . j  a  v a  2  s. c o m*/
    final int max = Integer.getInteger("test.registry.retries", 3);
    final Client client = ClientBuilder.newClient();
    try {
        for (int i = 0; i < max; i++) {
            assertEquals(Response.Status.OK.getStatusCode(),
                    client.target("http://localhost:" + System.getProperty("test.elasticsearch.port"))
                            .path("_refresh").request(MediaType.APPLICATION_JSON_TYPE).get().getStatus());
            try {
                return task.get();
            } catch (final Throwable error) {
                lastErr = error;
                if (i % 3 == 0) {
                    Logger.getLogger(Registry.class.getName())
                            .info("Retry cause (" + (i + 1) + "/" + max + ")"
                                    + ofNullable(description).filter(d -> d.length >= 1)
                                            .map(d -> Stream.of(d).collect(joining(" "))).orElse("")
                                    + ": " + error.getMessage());
                }
                try {
                    sleep(1000);
                } catch (final InterruptedException e) {
                    Thread.interrupted();
                    fail("quitting");
                }
            }
        }
    } finally {
        client.close();
    }
    if (RuntimeException.class.isInstance(lastErr)) {
        throw RuntimeException.class.cast(lastErr);
    }
    throw new IllegalStateException(lastErr);
}

From source file:org.apache.stratos.autoscaler.monitor.component.GroupMonitor.java

/**
 * Constructor of GroupMonitor/* w w w.  j  a v a  2  s.com*/
 *
 * @param group Takes the group from the Topology
 * @throws DependencyBuilderException    throws when couldn't build the Topology
 * @throws TopologyInConsistentException throws when topology is inconsistent
 */
public GroupMonitor(Group group, String appId, List<String> parentInstanceId, boolean hasScalingDependents)
        throws DependencyBuilderException, TopologyInConsistentException {
    super(group);

    int threadPoolSize = Integer.getInteger(AutoscalerConstants.MONITOR_THREAD_POOL_SIZE, 100);
    this.executorService = StratosThreadPool.getExecutorService(AutoscalerConstants.MONITOR_THREAD_POOL_ID,
            threadPoolSize);

    this.groupScalingEnabled = group.isGroupScalingEnabled();
    this.appId = appId;
    this.hasScalingDependents = hasScalingDependents;
}

From source file:com.thoughtworks.selenium.SeleneseTestBaseVir.java

/**
 * Gets the default port./*from w ww .j ava2 s  .co m*/
 * 
 * @return the default port
 */
private int getDefaultPort() {
    final int num = 4444;
    try {
        Class<?> c = Class.forName("org.openqa.selenium.server.RemoteControlConfiguration");
        Method getDefaultPort = c.getMethod("getDefaultPort", new Class[0]);
        Integer portNumber = (Integer) getDefaultPort.invoke(null, new Object[0]);
        return portNumber.intValue();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {

        e.printStackTrace();
    }
    return Integer.getInteger("selenium.port", num).intValue();
}

From source file:com.talis.platform.sequencing.zookeeper.ZooKeeperProvider.java

private ZooKeeper newKeeperInstance() throws IOException {
    int sessionTimeout = Integer.getInteger(SESSION_TIMEOUT_PROPERTY, DEFAULT_SESSION_TIMEOUT);

    if (LOG.isInfoEnabled()) {
        LOG.info(String.format("Creating new ZooKeeper instance. Servers: %s | Session Timeout: %s",
                getEnsembleList(), sessionTimeout));
    }// w  w w  .j ava  2  s. c o m
    connected = false;
    ZooKeeper keeper = new ZooKeeper(getEnsembleList(), sessionTimeout, this);

    if (LOG.isInfoEnabled()) {
        LOG.info("Created ZooKeeper instance");
    }
    return keeper;
}

From source file:org.opendaylight.genius.utils.batching.ResourceBatchingManager.java

public void registerDefaultBatchHandlers(DataBroker broker) {
    LOG.trace("Registering default batch handlers");
    Integer batchSize = Integer.getInteger("resource.manager.batch.size", BATCH_SIZE);
    Integer batchInterval = Integer.getInteger("resource.manager.batch.periodicity.ms", PERIODICITY_IN_MS);

    for (ShardResource shardResource : ShardResource.values()) {
        if (resourceHandlerMapper.containsKey(shardResource.name())) {
            continue;
        }/*from   w  ww .  jav  a 2s  .c o  m*/
        DefaultBatchHandler batchHandler = new DefaultBatchHandler(broker, shardResource.datastoreType,
                batchSize, batchInterval);
        registerBatchableResource(shardResource.name(), shardResource.getQueue(), batchHandler);
    }
}

From source file:org.apache.stratos.cloud.controller.iaases.openstack.networking.NovaNetworkingApi.java

@Override
public List<String> associateAddresses(NodeMetadata node) {

    ComputeServiceContext context = iaasProvider.getComputeService().getContext();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasProvider);

    if (StringUtils.isEmpty(region)) {
        throw new RuntimeException("Could not find region in iaas provider: " + iaasProvider.getName());
    }//from  w w w.ja v  a 2 s .c om

    NovaApi novaApi = context.unwrapApi(NovaApi.class);
    FloatingIPApi floatingIPApi = novaApi.getFloatingIPExtensionForZone(region).get();

    String ip = null;
    // first try to find an unassigned IP.
    FluentIterable<FloatingIP> floatingIPs = floatingIPApi.list();
    ArrayList<FloatingIP> unassignedIps = Lists
            .newArrayList(Iterables.filter(floatingIPs, new Predicate<FloatingIP>() {
                @Override
                public boolean apply(FloatingIP floatingIP) {
                    return floatingIP.getInstanceId() == null;
                }
            }));

    if (!unassignedIps.isEmpty()) {
        // try to prevent multiple parallel launches from choosing the same ip.
        Collections.shuffle(unassignedIps);
        ip = Iterables.getLast(unassignedIps).getIp();
    }

    // if no unassigned IP is available, we'll try to allocate an IP.
    if (StringUtils.isEmpty(ip)) {
        String floatingIpPool = iaasProvider.getProperty(CloudControllerConstants.DEFAULT_FLOATING_IP_POOL);
        FloatingIP allocatedFloatingIP;
        if (StringUtils.isEmpty(floatingIpPool)) {
            allocatedFloatingIP = floatingIPApi.create();
        } else {
            log.debug(
                    String.format("Trying to allocate a floating IP address from IP pool %s", floatingIpPool));
            allocatedFloatingIP = floatingIPApi.allocateFromPool(floatingIpPool);
        }
        if (allocatedFloatingIP == null) {
            String msg = String.format("Floating IP API did not return a floating IP address from IP pool %s",
                    floatingIpPool);
            log.error(msg);
            throw new CloudControllerException(msg);
        }
        ip = allocatedFloatingIP.getIp();
    }

    // wait till the fixed IP address gets assigned - this is needed before
    // we associate a public IP
    log.info(String.format("Waiting for private IP addresses get allocated: [node-id] %s", node.getId()));
    while (node.getPrivateAddresses() == null) {
        CloudControllerUtil.sleep(1000);
    }
    log.info(String.format("Private IP addresses allocated: %s", node.getPrivateAddresses()));

    if ((node.getPublicAddresses() != null) && (node.getPublicAddresses().iterator().hasNext())) {
        log.info("Public IP address " + node.getPublicAddresses().iterator().next()
                + " is already allocated to the instance: [node-id]  " + node.getId());
        return null;
    }

    int retries = 0;
    int retryCount = Integer.getInteger("stratos.public.ip.association.retry.count", 5);
    while ((retries < retryCount) && (!associateIp(floatingIPApi, ip, node.getProviderId()))) {
        // wait for 5s
        CloudControllerUtil.sleep(5000);
        retries++;
    }

    log.info(String.format("Successfully associated an IP address: [node-id] %s [ip] %s", node.getId(), ip));

    List<String> allocatedIPAddresses = new ArrayList<String>();
    allocatedIPAddresses.add(ip);
    return allocatedIPAddresses;
}

From source file:example.app.geode.server.GeodeServerApplication.java

int jmxManagerPort() {
    return Integer.getInteger("gemfire.manager.port", DEFAULT_GEMFIRE_JMX_MANAGER_PORT);
}

From source file:org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient.java

/**
 * <p> Constructs a new XmlRpcFileManagerClient with the given <code>url</code>. </p>
 *
 * @param url            The url pointer to the xml rpc file manager service.
 * @param testConnection Whether or not to check if server at given url is alive.
 *//*w ww  .  j a v  a2  s. co m*/
public XmlRpcFileManagerClient(final URL url, boolean testConnection) throws ConnectionException {
    // set up the configuration, if there is any
    if (System.getProperty("org.apache.oodt.cas.filemgr.properties") != null) {
        String configFile = System.getProperty("org.apache.oodt.cas.filemgr.properties");
        LOG.log(Level.INFO, "Loading File Manager Configuration Properties from: [" + configFile + "]");
        try {
            System.getProperties().load(new FileInputStream(new File(configFile)));
        } catch (Exception e) {
            LOG.log(Level.INFO, "Error loading configuration properties from: [" + configFile + "]");
        }

    }

    XmlRpcTransportFactory transportFactory = new XmlRpcTransportFactory() {

        public XmlRpcTransport createTransport() throws XmlRpcClientException {
            HttpClient client = new HttpClient();
            client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

                public boolean retryMethod(HttpMethod method, IOException e, int count) {
                    if (count < Integer
                            .getInteger("org.apache.oodt.cas.filemgr.system.xmlrpc.connection.retries", 3)) {
                        try {
                            Thread.sleep(Integer.getInteger(
                                    "org.apache.oodt.cas.filemgr.system.xmlrpc.connection.retry.interval.seconds",
                                    0) * 1000);
                            return true;
                        } catch (Exception ignored) {
                        }
                    }
                    return false;
                }

            });
            CommonsXmlRpcTransport transport = new CommonsXmlRpcTransport(url, client);
            transport.setConnectionTimeout(Integer.getInteger(
                    "org.apache.oodt.cas.filemgr.system.xmlrpc.connectionTimeout.minutes", 20) * 60 * 1000);
            transport.setTimeout(
                    Integer.getInteger("org.apache.oodt.cas.filemgr.system.xmlrpc.requestTimeout.minutes", 60)
                            * 60 * 1000);

            return transport;
        }

        public void setProperty(String arg0, Object arg1) {
        }

    };

    client = new XmlRpcClient(url, transportFactory);
    fileManagerUrl = url;

    if (testConnection && !isAlive()) {
        throw new ConnectionException("Exception connecting to filemgr: [" + this.fileManagerUrl + "]");
    }

}