Example usage for java.util Properties containsKey

List of usage examples for java.util Properties containsKey

Introduction

In this page you can find the example usage for java.util Properties containsKey.

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:com.metratech.metanga.api.impl.ClientHttpRequestFactorySelector.java

public static ClientHttpRequestFactory getRequestFactory() {
    Properties properties = System.getProperties();
    String proxyHost = properties.getProperty("http.proxyHost");
    int proxyPort = properties.containsKey("http.proxyPort")
            ? Integer.valueOf(properties.getProperty("http.proxyPort"))
            : 80;/*from   www  . j  a va  2s.  c  o m*/
    if (HTTP_COMPONENTS_AVAILABLE) {
        return HttpComponentsClientRequestFactoryCreator.createRequestFactory(proxyHost, proxyPort);
    } else {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        if (proxyHost != null) {
            requestFactory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
        }
        return requestFactory;
    }
}

From source file:com.hightail.metrics.reporter.NewRelicReporterFactory.java

private static NewRelicReporter buildNewRelicAgentInstance(Properties properties)
        throws CannotCreateInstanceException {

    if (!properties.containsKey(NewRelicConstants.METRIC_REGISTRY)
            || properties.get(NewRelicConstants.METRIC_REGISTRY) == null) {
        throw new CannotCreateInstanceException(NewRelicConstants.METRIC_REGISTRY + " is not provided");
    }/*from w  w  w.j  av a  2s .c o  m*/

    MetricRegistry registry = (MetricRegistry) properties.get(NewRelicConstants.METRIC_REGISTRY);
    String prefix = (properties.containsKey(NewRelicConstants.PREFIX))
            ? properties.getProperty(NewRelicConstants.PREFIX)
            : NewRelicConstants.DEFAULT_PREFIX;
    TimeUnit rateUnit = (properties.containsKey(NewRelicConstants.RATE_UNIT))
            ? (TimeUnit) properties.get(NewRelicConstants.RATE_UNIT)
            : NewRelicConstants.DEFAULT_RATE_UNIT;
    TimeUnit durationUnit = (properties.containsKey(NewRelicConstants.DURATION_UNIT))
            ? (TimeUnit) properties.get(NewRelicConstants.DURATION_UNIT)
            : NewRelicConstants.DEFAULT_DURATION_UNIT;
    MetricFilter filter = (properties.containsKey(NewRelicConstants.METRIC_FILTER))
            ? (MetricFilter) properties.get(NewRelicConstants.METRIC_FILTER)
            : NewRelicConstants.DEFAULT_METRIC_FILTER;

    return NewRelicAgentReporter.forRegistry(registry).prefixedWith(prefix).convertRatesTo(rateUnit)
            .convertDurationsTo(durationUnit).filter(filter).build();

}

From source file:org.springframework.social.openidconnect.api.impl.GAECompatibleClientHttpRequestFactorySelector.java

public static ClientHttpRequestFactory getRequestFactory() {
    Properties properties = System.getProperties();
    String proxyHost = properties.getProperty("http.proxyHost");
    int proxyPort = properties.containsKey("http.proxyPort")
            ? Integer.valueOf(properties.getProperty("http.proxyPort"))
            : 80;//  w  w  w  .  jav a  2 s  .  c om
    if (HTTP_COMPONENTS_AVAILABLE) {
        HttpClientBuilder httpClientBuilder = HttpClients.custom();
        if (proxyHost != null) {
            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
            httpClientBuilder.setProxy(proxy);
        }
        return HttpComponentsClientRequestFactoryCreator.createRequestFactory(httpClientBuilder.build(),
                proxyHost, proxyPort);
    } else {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        if (proxyHost != null) {
            requestFactory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
        }
        return requestFactory;
    }
}

From source file:org.apache.gobblin.hive.HiveMetastoreClientPool.java

private static final Cache<Optional<String>, HiveMetastoreClientPool> createPoolCache(
        final Properties properties) {
    long duration = properties.containsKey(POOL_CACHE_TTL_MINUTES_KEY)
            ? Long.parseLong(properties.getProperty(POOL_CACHE_TTL_MINUTES_KEY))
            : DEFAULT_POOL_CACHE_TTL_MINUTES;
    return CacheBuilder.newBuilder().expireAfterAccess(duration, TimeUnit.MINUTES)
            .removalListener(new RemovalListener<Optional<String>, HiveMetastoreClientPool>() {
                @Override/*from   w ww .j  av a  2 s.  c o m*/
                public void onRemoval(
                        RemovalNotification<Optional<String>, HiveMetastoreClientPool> notification) {
                    if (notification.getValue() != null) {
                        notification.getValue().close();
                    }
                }
            }).build();
}

From source file:gobblin.util.SchedulerUtils.java

private static Properties resolveTemplate(Properties jobProps) throws IOException {
    try {//from   w ww . ja v a 2  s  . co m
        if (jobProps.containsKey(ConfigurationKeys.JOB_TEMPLATE_PATH)) {
            Config jobConfig = ConfigUtils.propertiesToConfig(jobProps);
            Properties resolvedProps = ConfigUtils.configToProperties((ResourceBasedJobTemplate.forResourcePath(
                    jobProps.getProperty(ConfigurationKeys.JOB_TEMPLATE_PATH),
                    new PackagedTemplatesJobCatalogDecorator())).getResolvedConfig(jobConfig));
            return resolvedProps;
        } else {
            return jobProps;
        }
    } catch (JobTemplate.TemplateException | SpecNotFoundException | URISyntaxException exc) {
        throw new IOException(exc);
    }
}

From source file:gobblin.metrics.kafka.KafkaSchemaRegistry.java

@SuppressWarnings("unchecked")
public static <K, S> KafkaSchemaRegistry<K, S> get(Properties props) {
    Preconditions.checkArgument(props.containsKey(KAFKA_SCHEMA_REGISTRY_CLASS),
            "Missing required property " + KAFKA_SCHEMA_REGISTRY_CLASS);
    Class<? extends KafkaSchemaRegistry<?, ?>> clazz;
    try {//w w w.ja v  a 2  s  . co m
        clazz = (Class<? extends KafkaSchemaRegistry<?, ?>>) Class
                .forName(props.getProperty(KAFKA_SCHEMA_REGISTRY_CLASS));
        return (KafkaSchemaRegistry<K, S>) ConstructorUtils.invokeConstructor(clazz, props);
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException
            | InstantiationException e) {
        log.error("Failed to instantiate " + KafkaSchemaRegistry.class, e);
        throw Throwables.propagate(e);
    }
}

From source file:gobblin.source.extractor.extract.kafka.KafkaDeserializerExtractor.java

private static Optional<Deserializers> getDeserializerType(Properties props) {
    Preconditions.checkArgument(props.containsKey(KAFKA_DESERIALIZER_TYPE),
            "Missing required property " + KAFKA_DESERIALIZER_TYPE);
    return Enums.getIfPresent(Deserializers.class, props.getProperty(KAFKA_DESERIALIZER_TYPE).toUpperCase());
}

From source file:gobblin.kafka.writer.KafkaDataWriter.java

private static void setDefaultIfUnset(Properties props, String key, String value) {
    if (!props.containsKey(key)) {
        props.setProperty(key, value);/*from  ww  w.j av  a2 s .  co m*/
    }
}

From source file:gobblin.source.extractor.extract.kafka.KafkaDeserializerExtractor.java

/**
 * Gets {@link Properties} from a {@link WorkUnitState} and sets the config <code>schema.registry.url</code> to value
 * of {@link KafkaSchemaRegistry#KAFKA_SCHEMA_REGISTRY_URL} if set. This way users don't need to specify both
 * properties as <code>schema.registry.url</code> is required by the {@link ConfluentKafkaSchemaRegistry}.
 *///from w ww  .j  a  v  a  2 s  . c om
private static Properties getProps(WorkUnitState workUnitState) {
    Properties properties = workUnitState.getProperties();
    if (properties.containsKey(KafkaSchemaRegistry.KAFKA_SCHEMA_REGISTRY_URL)) {
        properties.setProperty(CONFLUENT_SCHEMA_REGISTRY_URL,
                properties.getProperty(KafkaSchemaRegistry.KAFKA_SCHEMA_REGISTRY_URL));
    }
    return properties;
}

From source file:Main.java

public static String getCurrentProject() {
    try {//w ww  . j  ava  2  s.com
        String value = "";
        Properties properties = new Properties();
        FileInputStream inputFile = new FileInputStream(System.getProperty("user.dir") + "/system.properties");
        properties.load(inputFile);
        inputFile.close();

        if (properties.containsKey("ProjectPath")) {
            value = properties.getProperty("ProjectPath");
            String resultName = new String(value.getBytes("ISO-8859-1"), "gbk");
            return resultName;
        } else
            return value;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return "";
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    } catch (Exception ex) {
        ex.printStackTrace();
        return "";
    }
}