/** * Returns the parameter as an array of Strings. If * the parameter is a scalar value its string value is returned as a single * element array. If the parameter is an array, the elements are converted to * String objects and returned as an array. If the parameter is a collection, the * collection elements are converted to String objects and returned as an array. * Otherwise (if the parameter is {@code null}) {@code null} is * returned. * * @param propValue The object to convert. */ public static String[] toStringArray(Object propValue) { return toStringArray(propValue, null); }
private void bootstrapMaster(ComponentContext context) throws CertificateException, SSLException { Dictionary<?, ?> props = context.getProperties(); int port = PropertiesUtil.toInteger(props.get(PORT), PORT_DEFAULT); String[] ranges = PropertiesUtil.toStringArray(props.get(ALLOWED_CLIENT_IP_RANGES), ALLOWED_CLIENT_IP_RANGES_DEFAULT); boolean secure = PropertiesUtil.toBoolean(props.get(SECURE), SECURE_DEFAULT); primary = new StandbyServer(port, segmentStore, ranges, secure); primary.start(); log.info("started primary on port {} with allowed ip ranges {}.", port, ranges); }
private static String getServicePidOrComponentName(Map<String, Object> properties) { String servicePid = PropertiesUtil.toString(properties.get(Constants.SERVICE_PID), null); if ( servicePid != null ) { return servicePid; } return PropertiesUtil.toString(properties.get(OAK_SECURITY_NAME), null); } }
protected void activate(ComponentContext ctx) { invalidNodeType = checkNotNull(PropertiesUtil.toString(ctx.getProperties().get(INVALID_NODE_TYPE), null), INVALID_NODE_TYPE); errorLabel = checkNotNull(PropertiesUtil.toString(ctx.getProperties().get(ERROR_LABEL), null), ERROR_LABEL); excludedNodeTypes = ImmutableSet.copyOf(PropertiesUtil.toStringArray(ctx.getProperties().get(EXCLUDED_NODE_TYPES), new String[0])); }
@Activate protected void activate(ComponentContext context, Map<String, ?> config) throws IOException, CommitFailedException { this.context = context; seedMount = PropertiesUtil.toString(config.get(PROP_SEED_MOUNT), null); pathStats = PropertiesUtil.toBoolean(config.get(PATH_STATS), false); enableChecks = PropertiesUtil.toBoolean(config.get(ENABLE_CHECKS), true); registerCompositeNodeStore(); }
} else if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class)) { setter.invoke(instance, toBoolean(value, false)); } else if (type.isAssignableFrom(Integer.TYPE) || type.isAssignableFrom(Integer.class)) { setter.invoke(instance, toInteger(value,0)); } else if (type.isAssignableFrom(Long.TYPE) || type.isAssignableFrom(Long.class)) { setter.invoke(instance, toLong(value, 0)); } else if (type.isAssignableFrom(Double.TYPE) || type.isAssignableFrom(Double.class)) { setter.invoke(instance, toDouble(value,0)); } else { throw new RuntimeException(
private void initializeExtractedTextCache(BundleContext bundleContext, Map<String, ?> config) { int cacheSizeInMB = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_SIZE), PROP_EXTRACTED_TEXT_CACHE_SIZE_DEFAULT); int cacheExpiryInSecs = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_EXPIRY), PROP_EXTRACTED_TEXT_CACHE_EXPIRY_DEFAULT); boolean alwaysUsePreExtractedCache = PropertiesUtil.toBoolean(config.get(PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE), PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE_DEFAULT); extractedTextCache = new ExtractedTextCache( cacheSizeInMB * ONE_MB, cacheExpiryInSecs, alwaysUsePreExtractedCache, indexDir); if (extractedTextProvider != null){ registerExtractedTextProvider(extractedTextProvider); } CacheStats stats = extractedTextCache.getCacheStats(); if (stats != null){ oakRegs.add(registerMBean(whiteboard, CacheStatsMBean.class, stats, CacheStatsMBean.TYPE, stats.getName())); log.info("Extracted text caching enabled with maxSize {} MB, expiry time {} secs", cacheSizeInMB, cacheExpiryInSecs); } }
@Activate private void activate(BundleContext bundleContext, Map<String, ?> config) { String[] paths = PropertiesUtil.toStringArray(config.get(PROP_MOUNT_PATHS)); String mountName = PropertiesUtil.toString(config.get(PROP_MOUNT_NAME), PROP_MOUNT_NAME_DEFAULT); boolean readOnly = PropertiesUtil.toBoolean(config.get(PROP_MOUNT_READONLY), PROP_MOUNT_READONLY_DEFAULT); String[] pathsSupportingFragments = PropertiesUtil.toStringArray(config.get(PROP_PATHS_SUPPORTING_FRAGMENTS), PROP_PATHS_SUPPORTING_FRAGMENTS_DEFAULT); MountInfoProvider mip = Mounts.defaultMountInfoProvider(); if (paths != null) { mip = Mounts.newBuilder() .mount(mountName.trim(), readOnly, trim(pathsSupportingFragments), trim(paths)) .build(); log.info("Enabling mount for {}", mip); } else { log.info("No mount config provided. Mounting would be disabled"); } reg = bundleContext.registerService(MountInfoProvider.class.getName(), mip, null); }
private static boolean hasDynamicMembership(ServiceReference reference) { return PropertiesUtil.toBoolean(reference.getProperty(DefaultSyncConfigImpl.PARAM_USER_DYNAMIC_MEMBERSHIP), DefaultSyncConfigImpl.PARAM_USER_DYNAMIC_MEMBERSHIP_DEFAULT); }
boolean encodeLengthInId = PropertiesUtil.toBoolean(config.get(PROP_ENCODE_LENGTH), true); int cacheSizeInMB = PropertiesUtil.toInteger(config.get(PROP_CACHE_SIZE), DataStoreBlobStore.DEFAULT_CACHE_SIZE); log.info("Initializing the DataStore with homeDir [{}]", homeDir); PropertiesUtil.populate(ds, config, false); ds.init(homeDir); this.dataStore = new DataStoreBlobStore(ds, encodeLengthInId, cacheSizeInMB); this.dataStore.setBlobStatsCollector(stats); PropertiesUtil.populate(dataStore, config, false);
private void bootstrapSlave(ComponentContext context) throws SSLException { Dictionary<?, ?> props = context.getProperties(); int port = PropertiesUtil.toInteger(props.get(PORT), PORT_DEFAULT); long interval = PropertiesUtil.toInteger(props.get(INTERVAL), INTERVAL_DEFAULT); String host = PropertiesUtil.toString(props.get(PRIMARY_HOST), PRIMARY_HOST_DEFAULT); boolean secure = PropertiesUtil.toBoolean(props.get(SECURE), SECURE_DEFAULT); int readTimeout = PropertiesUtil.toInteger(props.get(READ_TIMEOUT), READ_TIMEOUT_DEFAULT); boolean clean = PropertiesUtil.toBoolean(props.get(AUTO_CLEAN), AUTO_CLEAN_DEFAULT); sync = new StandbyClient(host, port, segmentStore, secure, readTimeout, clean); Dictionary<Object, Object> dictionary = new Hashtable<Object, Object>(); dictionary.put("scheduler.period", interval); dictionary.put("scheduler.concurrent", false); // dictionary.put("scheduler.runOn", "SINGLE"); syncReg = context.getBundleContext().registerService( Runnable.class.getName(), sync, dictionary); log.info("started standby sync with {}:{} at {} sec.", host, port, interval); } }
private static void configure(Object o, Map<String, ?> config) { PropertiesUtil.populate(o, config, false); }
@Activate public void activate(Map<String, ?> config) throws Exception { String pathToJoshuaConfig = PropertiesUtil.toString(config.get(CONFIG_PATH), "."); String[] nts = PropertiesUtil.toStringArray(config.get(NODE_TYPES), new String[]{"Oak:unstructured"}); float minScore = (float) PropertiesUtil.toDouble(config.get(MIN_SCORE), DEFAULT_MIN_SCORE); log.info("activating MT FulltextQueryTermProvider from Joshua config at {} on {} nodetypes, minScore {}", pathToJoshuaConfig, nts, minScore); Decoder decoder = null; try { log.debug("reading joshua config"); JoshuaConfiguration configuration = new JoshuaConfiguration(); configuration.readConfigFile(pathToJoshuaConfig); configuration.setConfigFilePath(new File(pathToJoshuaConfig).getCanonicalFile().getParent()); configuration.use_structured_output = true; decoder = new Decoder(configuration, pathToJoshuaConfig); log.debug("decoder initialized"); Set<String> nodeTypes = new HashSet<>(); nodeTypes.addAll(Arrays.asList(nts)); queryTermsProvider = new MTFulltextQueryTermsProvider(decoder, nodeTypes, minScore); } catch (Exception e) { log.error("could not initialize MTFulltextQueryTermProvider", e); if (decoder != null) { decoder.cleanUp(); } } }
private void configureBooleanClauseLimit(Map<String, ?> config) { int booleanClauseLimit = PropertiesUtil.toInteger(config.get(PROP_BOOLEAN_CLAUSE_LIMIT), PROP_BOOLEAN_CLAUSE_LIMIT_DEFAULT); if (booleanClauseLimit != BooleanQuery.getMaxClauseCount()){ BooleanQuery.setMaxClauseCount(booleanClauseLimit); log.info("Changed the Max boolean clause limit to {}", booleanClauseLimit); } }
@Override protected DataStore createDataStore(ComponentContext context, Map<String, Object> config) { long cacheSize = PropertiesUtil.toLong(config.get(CACHE_SIZE), 0L); // return CachingFDS when cacheSize > 0 if (cacheSize > 0) { String fsBackendPath = PropertiesUtil.toString(config.get(PATH), null); Preconditions.checkNotNull(fsBackendPath, "Cannot create " + "FileDataStoreService with caching. [{path}] property not configured."); config.remove(PATH); config.remove(CACHE_SIZE); config.put(FS_BACKEND_PATH, fsBackendPath); config.put("cacheSize", cacheSize); String cachePath = PropertiesUtil.toString(config.get(CACHE_PATH), null); if (cachePath != null) { config.remove(CACHE_PATH); config.put(PATH, cachePath); } Properties properties = new Properties(); properties.putAll(config); log.info("Initializing with properties " + properties); return getCachingDataStore(properties, context); } else { log.info("OakFileDataStore initialized"); return new OakFileDataStore(); } }
@Override public Future addingService(ServiceReference<Runnable> reference) { Runnable runnable = context.getService(reference); long period = PropertiesUtil.toLong(reference.getProperty("scheduler.period"), -1); boolean concurrent = PropertiesUtil.toBoolean(reference.getProperty("scheduler.concurrent"), false); Future future = null; if (period != -1) { if (concurrent) { future = getExecutor().scheduleAtFixedRate( runnable, period, period, TimeUnit.SECONDS); } else { future = getExecutor().scheduleWithFixedDelay( runnable, period, period, TimeUnit.SECONDS); } } return future; }
private void registerLastRevRecoveryJob(final DocumentNodeStore nodeStore) { long leaseTime = toLong(context.getProperties().get(PROP_REV_RECOVERY_INTERVAL), ClusterNodeInfo.DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS); addRegistration(scheduleWithFixedDelay(whiteboard, new LastRevRecoveryJob(nodeStore), TimeUnit.MILLISECONDS.toSeconds(leaseTime), false/*runOnSingleClusterNode*/, true /*use dedicated pool*/)); }
@SuppressWarnings({"deprecation", "UnnecessaryBoxing"}) @Test public void testToDouble() { // we test getProperty which calls toDouble - so we can test both // methods in one go assertEquals(2.0, PropertiesUtil.toDouble(null, 2.0), 0); assertEquals(1.0, PropertiesUtil.toDouble(1.0, 2.0), 0); assertEquals(1.0, PropertiesUtil.toDouble(new Double(1.0), 2.0), 0); assertEquals(5.0, PropertiesUtil.toDouble(new Long(5), 2.0), 0); assertEquals(2.0, PropertiesUtil.toDouble("abc", 2.0), 0); }
} else if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class)) { setter.invoke(instance, toBoolean(value, false)); } else if (type.isAssignableFrom(Integer.TYPE) || type.isAssignableFrom(Integer.class)) { setter.invoke(instance, toInteger(value,0)); } else if (type.isAssignableFrom(Long.TYPE) || type.isAssignableFrom(Long.class)) { setter.invoke(instance, toLong(value, 0)); } else if (type.isAssignableFrom(Double.TYPE) || type.isAssignableFrom(Double.class)) { setter.invoke(instance, toDouble(value,0)); } else { throw new RuntimeException(
private void initializeExtractedTextCache(BundleContext bundleContext, Map<String, ?> config) { int cacheSizeInMB = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_SIZE), PROP_EXTRACTED_TEXT_CACHE_SIZE_DEFAULT); int cacheExpiryInSecs = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_EXPIRY), PROP_EXTRACTED_TEXT_CACHE_EXPIRY_DEFAULT); boolean alwaysUsePreExtractedCache = PropertiesUtil.toBoolean(config.get(PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE), PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE_DEFAULT); extractedTextCache = new ExtractedTextCache( cacheSizeInMB * ONE_MB, cacheExpiryInSecs, alwaysUsePreExtractedCache, indexDir); if (extractedTextProvider != null){ registerExtractedTextProvider(extractedTextProvider); } CacheStats stats = extractedTextCache.getCacheStats(); if (stats != null){ oakRegs.add(registerMBean(whiteboard, CacheStatsMBean.class, stats, CacheStatsMBean.TYPE, stats.getName())); log.info("Extracted text caching enabled with maxSize {} MB, expiry time {} secs", cacheSizeInMB, cacheExpiryInSecs); } }