List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.codice.pubsub.server.SubscriptionServer.java
private void processSubscriptions() { while (!Thread.currentThread().isInterrupted()) { //Fetch Subscriptions Dictionary subMap = getSubscriptionMap(); if (subMap != null) { Enumeration e = subMap.keys(); while (e.hasMoreElements()) { String subscriptionId = (String) e.nextElement(); if (!subscriptionId.equals("service.pid")) { String subscriptionMsg = (String) subMap.get(subscriptionId); int status = checkProcessingStatus(subscriptionId); if (status == PROCESS_STATUS_COMPLETE) { Future<QueryControlInfo> future = processMap.get(subscriptionId); if (future != null) { boolean done = future.isDone(); if (done) { try { QueryControlInfo ctrlInfo = future.get(); processMap.remove(subscriptionId); runQuery(subscriptionMsg, ctrlInfo.getQueryEndDateTime()); } catch (InterruptedException ie) { LOGGER.error(ie.getMessage()); } catch (ExecutionException ee) { LOGGER.error(ee.getMessage()); }//from www. ja v a 2 s .c om } } } else if (status == PROCESS_STATUS_NOT_EXIST) { runQuery(subscriptionMsg, new DateTime().minusSeconds(1)); } else if (status == PROCESS_STATUS_NOT_EXIST) { //Do Nothing For Now } } } } else { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
From source file:org.opencastproject.workflow.handler.TextAnalysisWorkflowOperationHandler.java
/** * Determine the stability threshold used to select the slide extraction timepoint. * /*from www. j ava 2s . c om*/ * @return the stability threshold in seconds */ private int getStabilityThreshold() { logger.debug("Looking up the videosegmenter's service configuration"); ServiceReference ref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName()); if (ref == null) return DEFAULT_STABILITY_THRESHOLD; ConfigurationAdmin configAdmin = (ConfigurationAdmin) bundleContext.getService(ref); if (configAdmin == null) return DEFAULT_STABILITY_THRESHOLD; try { Configuration config = configAdmin.getConfiguration(VIDEOSEGMENTER_PID); if (config == null) return DEFAULT_STABILITY_THRESHOLD; Dictionary<?, ?> properties = config.getProperties(); if (properties.get(OPT_STABILITY_THRESHOLD) != null) { String threshold = (String) properties.get(OPT_STABILITY_THRESHOLD); try { return Integer.parseInt(threshold); } catch (Exception e) { logger.warn("Found illegal value '{}' for videosegmenter's stability threshold", threshold); } } } catch (IOException e) { logger.warn("Error reading the videosegmenter's service configuration"); } return DEFAULT_STABILITY_THRESHOLD; }
From source file:org.openhab.binding.daikin.internal.DaikinBinding.java
/** * {@inheritDoc}// www .j av a 2 s. c o m */ @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { Enumeration keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = (String) config.get(key); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } if (key.equals(CONFIG_KEY_REFRESH)) { refreshInterval = Long.parseLong(value); continue; } String[] keyParts = key.split("\\."); String hostId = keyParts[0]; String configKey = keyParts[1]; if (!hosts.containsKey(hostId)) { hosts.put(hostId, new DaikinHost(hostId)); } DaikinHost host = hosts.get(hostId); if (configKey.equals(CONFIG_KEY_HOST)) { host.setHost(value); } else if (configKey.equals(CONFIG_KEY_USERNAME)) { host.setUsername(value); } else if (configKey.equals(CONFIG_KEY_PASSWORD)) { host.setPassword(value); } else { throw new ConfigurationException(key, "Unrecognised configuration parameter: " + configKey); } } // start the refresh thread setProperlyConfigured(true); } }
From source file:org.avineas.fins.osgi.Activator.java
/** * Create a gateway given the passed properties. If a gateway is already active, the original * is destroyed first./* w w w. j ava 2 s .co m*/ * * @param d The properties of the dictionary * @throws ConfigurationException In case of problems */ @SuppressWarnings("rawtypes") private synchronized void createGateway(Dictionary d) throws ConfigurationException { Dictionary dict = d; if (dict == null) dict = new Hashtable(); // Destroy the gateway after un-tracking the services. if (gateway != null) { untrackServices(); gateway.destroy(); } // Check the port, if it is an empty string, no gateway should be started. String port = (String) dict.get(PORT); if (port != null && port.trim().length() == 0) return; gateway = new Gateway(); try { if (port != null) gateway.setPort(Integer.parseInt(port)); } catch (Exception exc) { throw new ConfigurationException(PORT, exc.getMessage(), exc); } try { String tries = (String) dict.get(TRIES); if (tries != null) { gateway.setTries(Integer.parseInt(tries)); } } catch (Exception exc) { throw new ConfigurationException(TRIES, exc.getMessage(), exc); } try { String timeout = (String) dict.get(TIMEOUT); if (timeout != null) { gateway.setTimeout(Integer.parseInt(timeout)); } } catch (Exception exc) { throw new ConfigurationException(TIMEOUT, exc.getMessage(), exc); } String nodeMap = (String) dict.get(NODES); if (nodeMap != null) { String[] splitted = nodeMap.split("\\s+"); Map<String, String> remoteNodes = new HashMap<String, String>(); for (String entry : splitted) { String[] keyValue = entry.split("="); remoteNodes.put(keyValue[0].trim(), keyValue[1].trim()); } try { gateway.setRemoteNodes(remoteNodes); } catch (Exception exc) { throw new ConfigurationException(NODES, exc.getMessage(), exc); } } try { gateway.init(); } catch (Exception exc) { logger.error("gateway " + gateway + " cannot be initialized"); } // Start tracking the unit services. trackServices(); }
From source file:org.openhab.binding.insteonhub.internal.InsteonHubBinding.java
@Override public synchronized void updated(Dictionary<String, ?> config) throws ConfigurationException { logger.debug(BINDING_NAME + " updated"); try {//from w ww . j a v a 2 s.co m // Process device configuration if (config != null) { String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } // Stop all existing proxy async threads for (InsteonHubProxy proxy : proxies.values()) { proxy.stop(); } // Clear proxy map. It will be rebuilt. proxies.clear(); // Load new proxies Map<String, InsteonHubProxy> newProxies = InsteonHubProxyFactory.createInstances(config); proxies.putAll(newProxies); for (Map.Entry<String, InsteonHubProxy> entry : proxies.entrySet()) { String hubId = entry.getKey(); InsteonHubProxy proxy = entry.getValue(); proxy.addListener(new AsyncEventPublisher(hubId)); // If activated, start proxy now if (activated) { proxy.start(); } } // Set properly configured setProperlyConfigured(true); } } catch (Throwable t) { logger.error("Error configuring " + getName(), t); setProperlyConfigured(false); } }
From source file:ch.entwine.weblounge.contentrepository.impl.bundle.BundleContentRepository.java
/** * {@inheritDoc}//from ww w . ja v a 2s. c o m * * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ public void updated(Dictionary properties) throws ConfigurationException { if (properties == null) return; // Path to the root directory String rootDirPath = (String) properties.get(OPT_ROOT_DIR); if (StringUtils.isNotBlank(rootDirPath)) { this.rootDirPath = PathUtils.trim(rootDirPath); logger.info("Bundle content repository index data will be stored at {}", rootDirPath); } // Cleanup after shutdown? if (StringUtils.isNotBlank((String) properties.get(OPT_CLEANUP))) { cleanupTemporaryIndex = ConfigurationUtils.isTrue((String) properties.get(OPT_CLEANUP)); logger.info("Bundle content repository indicex will {} removed on shutdown", (cleanupTemporaryIndex ? "be" : "not be")); } }
From source file:org.openhab.binding.novelanheatpump.internal.HeatPumpBinding.java
/** * {@inheritDoc}// w w w. j ava2s . co m */ @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { String ip = (String) config.get("ip"); //$NON-NLS-1$ if (StringUtils.isNotBlank(ip) && !ip.equals(HeatPumpBinding.ip)) { // only do something if the ip has changed HeatPumpBinding.ip = ip; String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } setProperlyConfigured(true); } } }
From source file:ch.entwine.weblounge.kernel.mail.SmtpService.java
/** * Callback from the OSGi <code>ConfigurationAdmin</code> on configuration * changes.//from w w w . ja v a2 s . c o m * * @param properties * the configuration properties * @throws ConfigurationException * if configuration fails */ @Override public void updated(Dictionary properties) throws ConfigurationException { // Read the mail server properties mailProperties.clear(); // The mail host is mandatory String propName = getConfigurationKey(OPT_SMTP_HOST); mailHost = StringUtils.trimToNull((String) properties.get(propName)); if (mailHost == null) { mailHost = DEFAULT_SMTP_HOST; logger.debug("Mail server defaults to '{}'", mailHost); } else { logger.debug("Mail host is {}", mailHost); } mailProperties.put(getJavaMailSmtpKey(OPT_SMTP_HOST), mailHost); // Mail port propName = getConfigurationKey(OPT_SMTP_PORT); String mailPort = StringUtils.trimToNull((String) properties.get(propName)); if (mailPort == null) { mailPort = DEFAULT_SMTP_PORT; logger.debug("Mail server port defaults to '{}'", mailPort); } else { logger.debug("Mail server port is '{}'", mailPort); } mailProperties.put(getJavaMailSmtpKey(OPT_SMTP_PORT), mailPort); // TSL over SMTP support propName = getConfigurationKey(OPT_SMTP_TLS); String smtpStartTLSStr = StringUtils.trimToNull((String) properties.get(propName)); boolean smtpStartTLS = Boolean.parseBoolean(smtpStartTLSStr); if (smtpStartTLS) { mailProperties.put(getJavaMailSmtpKey(OPT_SMTP_TLS) + ".enable", "true"); logger.debug("TLS over SMTP is enabled"); } else { logger.debug("TLS over SMTP is disabled"); } // Mail user propName = getConfigurationKey(OPT_SMTP_USER); mailUser = StringUtils.trimToNull((String) properties.get(propName)); if (mailUser != null) { mailProperties.put(getJavaMailKey(OPT_SMTP_USER), mailUser); logger.debug("Mail user is '{}'", mailUser); } else { logger.debug("Sending mails to {} without authentication", mailHost); } // Mail password propName = getConfigurationKey(OPT_SMTP_PASSWORD); mailPassword = StringUtils.trimToNull((String) properties.get(propName)); if (mailPassword != null) { mailProperties.put(getJavaMailKey(OPT_SMTP_PASSWORD), mailPassword); logger.debug("Mail password set"); } // Mail sender propName = getConfigurationKey(OPT_SMTP_FROM); String mailFrom = StringUtils.trimToNull((String) properties.get(propName)); if (mailFrom == null) { try { mailFrom = "weblounge@" + InetAddress.getLocalHost().getCanonicalHostName(); logger.info("Mail sender defaults to '{}'", mailFrom); } catch (UnknownHostException e) { logger.error("Error retreiving localhost hostname used to create default sender address: {}", e.getMessage()); throw new ConfigurationException(OPT_SMTP_FROM, "Error retreiving localhost hostname used to create default sender address"); } } else { logger.debug("Mail sender is '{}'", mailFrom); } mailProperties.put(getJavaMailKey(OPT_SMTP_FROM), mailFrom); // Authentication propName = getConfigurationKey(OPT_SMTP_AUTH); mailProperties.put(getJavaMailSmtpKey(OPT_SMTP_AUTH), Boolean.toString(mailUser != null)); // Mail debugging propName = getConfigurationKey(OPT_SMTP_DEBUG); String mailDebug = StringUtils.trimToNull((String) properties.get(propName)); if (mailDebug != null) { boolean mailDebugEnabled = Boolean.parseBoolean(mailDebug); mailProperties.put(getJavaMailKey(OPT_SMTP_DEBUG), Boolean.toString(mailDebugEnabled)); logger.info("Mail debugging is {}", mailDebugEnabled ? "enabled" : "disabled"); } defaultMailSession = null; logger.info("Mail service configured with {}", mailHost); // Test propName = getConfigurationKey(OPT_SMTP_TEST); String mailTest = StringUtils.trimToNull((String) properties.get(propName)); if (mailTest != null) { try { sendTestMessage(mailTest); } catch (MessagingException e) { logger.error("Error sending test message to " + mailTest + ": " + e.getMessage()); throw new ConfigurationException(OPT_SMTP_PREFIX + MAIL_TRANSPORT + OPT_SMTP_HOST, "Failed to send test message to " + mailTest); } } }
From source file:org.openhab.io.gcal.internal.GCalEventDownloader.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { String usernameString = (String) config.get("username"); username = usernameString;/*from www . j ava2s .c o m*/ String passwordString = (String) config.get("password"); password = passwordString; String urlString = (String) config.get("url"); url = urlString; if (StringUtils.isBlank(url)) { throw new ConfigurationException("gcal:url", "url must not be blank - please configure an aproppriate url in openhab.cfg"); } filter = (String) config.get("filter"); String refreshString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshString)) { refreshInterval = Integer.parseInt(refreshString); } setProperlyConfigured(true); } }
From source file:org.nuxeo.stanbol.temis.engine.TemisLuxidEnhancementEngine.java
protected String getFromPropertiesOrEnv(Dictionary<String, String> properties, String propertyName, String defaultValue) throws ConfigurationException { String envVariableName = propertyName.replaceAll("\\.", "_").toUpperCase(); String propertyValue = System.getenv(envVariableName); if (properties.get(propertyName) != null && !properties.get(propertyName).trim().isEmpty()) { propertyValue = properties.get(propertyName); }//from w w w. ja va2 s. c o m if (propertyValue == null || propertyValue.trim().isEmpty()) { if (defaultValue == null) { throw new ConfigurationException(propertyName, String.format("%s is a required property", propertyName)); } else { return defaultValue; } } return propertyValue; }