List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:it.txt.ens.client.subscriber.printer.osgi.test.ENSEventPrinterTest.java
private void declareEventPrinter(Properties properties) throws Exception { LOGGER.fine("Declaring an event printer"); Configuration eventListenerConfig = configAdmin .createFactoryConfiguration(RegisteredServices.EVENT_PRINTER_LISTENER_SERVICE_PID, null); Dictionary<String, Object> configuration = MapConverter.convert(properties); configuration.put(FilterAttributes.EVENT_PRINTER_OWNER_ID, context.getBundle().getBundleId()); // configuration.put(FilterAttributes.IMPLEMENTATION_KEY, EventPrinterListenersMSF.IMPLEMENTATION_ID); eventListenerConfig.update(configuration); // Object patternOBJ = properties.get(ENSResourceFactory.PATTERN); // String pattern = null; // if (patternOBJ == null) { // Object resourceOBJ = properties.get(ENSResourceFactory.URI); // if (resourceOBJ == null) // throw new Exception("Missing property " + ENSResourceFactory.URI); // else { // ServiceReference<ENSResourceFactory> resourceFactorySR = context.getServiceReference( // ENSResourceFactory.class); // ENSResourceFactory resourceFactory = context.getService(resourceFactorySR); // try { // pattern = resourceFactory.create(new URI(resourceOBJ.toString())).getPattern(); // } finally { // context.ungetService(resourceFactorySR); // } // } // } else { // pattern = (String) patternOBJ; // }// www. j av a 2 s . c o m EqualsFilter ownership = new EqualsFilter(FilterAttributes.EVENT_PRINTER_OWNER_ID, (int) context.getBundle().getBundleId()); // EqualsFilter implementation = new EqualsFilter(FilterAttributes.IMPLEMENTATION_KEY, // EventPrinterListenersMSF.IMPLEMENTATION_ID); // EqualsFilter patternFilter = new EqualsFilter(ENSResource.PATTERN_PARAMETER_NAME, pattern); AndFilter filter = new AndFilter()/*.and(implementation)*/.and(ownership)/*.and(patternFilter)*/; // Filter f; try { f = FrameworkUtil.createFilter(filter.encode()); } catch (InvalidSyntaxException e) { throw new ConfigurationException(null, "An error occurred while tracking subscription services using filter " + filter.encode(), e); } ServiceTracker<ENSEventPrinter, ENSEventPrinter> tracker = new ServiceTracker<ENSEventPrinter, ENSEventPrinter>( context, f, null); tracker.open(); ENSEventPrinter eventPrinter = tracker.waitForService(TIMEOUT); tracker.close(); assertNotNull("No event printer has been found using the filter " + f.toString(), eventPrinter); // Collection<ServiceReference<ENSEventPrinter>> references; // long startTime = System.currentTimeMillis(); // do { // references = context.getServiceReferences(ENSEventPrinter.class, f.toString()); // } while (references.isEmpty() && (System.currentTimeMillis() - startTime) <= TIMEOUT); // // assertTrue("No event printer has been found using the filter " + f.toString(),references.iterator().hasNext()); // ServiceReference<ENSEventPrinter> eventPrinterSR = references.iterator().next(); // assertNotNull(eventPrinterSR); // serviceReferences.add(eventPrinterSR); // ENSEventPrinter eventPrinter = context.getService(eventPrinterSR); LOGGER.fine("Created ENS event printer with configuration: " + properties.toString()); eventPrinter.start(); }
From source file:org.wso2.carbon.uuf.internal.deployment.AppCreator.java
private void addAPIs(List<ComponentConfig.API> apis, String appContextPath, String componentContextPath, String componentName, ClassLoader classLoader) { if ((apis == null) || apis.isEmpty()) { return;/*from ww w . j a v a 2 s . c o m*/ } for (ComponentConfig.API api : apis) { String className = api.getClassName(); String uri = appContextPath + componentContextPath + "/apis" + api.getUri(); Object apiImplementation; try { apiImplementation = classLoader.loadClass(className).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new UUFException( "Cannot deploy REST API '" + className + "' for component '" + componentName + "'.", e); } Dictionary<String, String> serviceProperties = new Hashtable<>(); serviceProperties.put("contextPath", uri); classLoaderProvider.deployAPI(apiImplementation, serviceProperties); LOGGER.info("Deployed REST API '{}' for component '{}' with context path '{}'.", className, componentName, uri); } }
From source file:org.opendaylight.netvirt.openstack.netvirt.ConfigActivator.java
private void registerAbstractHandlerService(BundleContext context, Class[] interfaces, AbstractEvent.HandlerType handlerType, AbstractHandler handler) { Dictionary<String, Object> properties = new Hashtable<>(); properties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, handlerType); String[] interfaceNames = new String[interfaces.length + 1]; for (int i = 0; i < interfaces.length; i++) { interfaceNames[i] = interfaces[i].getName(); }// w w w . j a va 2 s .c o m interfaceNames[interfaces.length] = AbstractHandler.class.getName(); registerService(context, interfaceNames, properties, handler); }
From source file:org.millr.slick.impl.services.OsgiServiceImpl.java
public boolean setProperty(final String pid, final String property, final Object value) { try {//from www .j av a2s . c o m Configuration conf = configAdmin.getConfiguration(pid); @SuppressWarnings("unchecked") Dictionary<String, Object> props = conf.getProperties(); if (props == null) { props = new Hashtable<String, Object>(); } props.put(property, value != null ? value : StringUtils.EMPTY); conf.update(props); } catch (IOException e) { LOGGER.error("Could not set property", e); return false; } return true; }
From source file:org.energy_home.jemma.osgi.ah.io.CedacIO.java
public void start(BundleContext bc) { String[] topics = new String[] { "ah/provision/BEGIN", "org/osgi/framework/ServiceEvent/*", "org/osgi/framework/BundleEvent/*", "ah/START_IDENTIFY", "ah/eh/overload/*" }; Dictionary props = new Hashtable(); props.put(EventConstants.EVENT_TOPIC, topics); sr = bc.registerService(EventHandler.class.getName(), this, props); this.activate(bc); }
From source file:org.apache.sling.replication.transport.impl.HttpTransportHandlerFactory.java
protected TransportHandler createTransportHandler(Map<String, ?> config, Dictionary<String, Object> props, TransportAuthenticationProvider transportAuthenticationProvider, ReplicationEndpoint[] endpoints, TransportEndpointStrategyType endpointStrategyType) { boolean useCustomHeaders = PropertiesUtil.toBoolean(config.get(USE_CUSTOM_HEADERS), false); props.put(USE_CUSTOM_HEADERS, useCustomHeaders); String[] customHeaders = PropertiesUtil.toStringArray(config.get(CUSTOM_HEADERS), new String[0]); props.put(CUSTOM_HEADERS, customHeaders); boolean useCustomBody = PropertiesUtil.toBoolean(config.get(USE_CUSTOM_BODY), false); props.put(USE_CUSTOM_BODY, useCustomBody); String customBody = PropertiesUtil.toString(config.get(CUSTOM_BODY), ""); props.put(CUSTOM_BODY, customBody);/* w w w . j a va2s .co m*/ return new HttpTransportHandler(useCustomHeaders, customHeaders, useCustomBody, customBody, (TransportAuthenticationProvider<Executor, Executor>) transportAuthenticationProvider, endpoints, endpointStrategyType); }
From source file:it.txt.ens.authorisationService.test.IntegrationTest.java
@Test public void test2() throws Exception { //configure and start the ENS ServiceReference<ConfigurationAdmin> configAdminSR = context.getServiceReference(ConfigurationAdmin.class); assertNotNull("No service reference found for " + ConfigurationAdmin.class.getName(), configAdminSR); ConfigurationAdmin configAdmin = context.getService(configAdminSR); assertNotNull("No instance found for " + ConfigurationAdmin.class.getName(), configAdminSR); File file = new File(System.getProperty(CONFIG_FILE_PROPERTY)); FileInputStream stream = new FileInputStream(file); Properties p = new Properties(); try {//from ww w . j a v a2s .com p.load(stream); } finally { if (stream != null) stream.close(); } Dictionary<String, Object> prop = new Hashtable<String, Object>(p.size()); for (Object key : p.keySet()) { if (key.equals(PropertiesKeys.CONFIGURATION_FILE_PATH_ATTRIBUTE)) prop.put((String) key, p.getProperty((String) key)); else if (key.equals(PropertiesKeys.ENS_GUI_ATTRIBUTE)) prop.put((String) key, Boolean.parseBoolean(p.getProperty((String) key))); else if (key.equals(PropertiesKeys.THREAD_POOL_SIZE_ATTRIBUTE)) prop.put((String) key, Integer.parseInt(p.getProperty((String) key))); else continue; } Configuration config = configAdmin.getConfiguration(ENSAuthorisationServiceMS.SERVICE_PID); config.update(prop); Thread.sleep(60000); //delete the configuration config.delete(); }
From source file:ch.entwine.weblounge.kernel.command.TestCommand.java
/** * Callback for OSGi's declarative services component activation. * // www . j a va 2 s . c om * @param context * the component context * @throws Exception * if component activation fails */ void activate(ComponentContext context) { BundleContext bundleContext = context.getBundleContext(); logger.debug("Registering test commands"); Dictionary<String, Object> commands = new Hashtable<String, Object>(); commands.put("osgi.command.scope", "weblounge"); commands.put("osgi.command.function", new String[] { "lt", "test", "tests" }); bundleContext.registerService(getClass().getName(), this, commands); }
From source file:org.opencastproject.composer.impl.EncodingProfileScanner.java
/** * {@inheritDoc}/*from w w w.j a va 2 s. c o m*/ * * @see org.apache.felix.fileinstall.ArtifactInstaller#install(java.io.File) */ @Override public void install(File artifact) throws Exception { logger.info("Registering encoding profiles from {}", artifact); try { Map<String, EncodingProfile> profileMap = loadFromProperties(artifact); for (Entry<String, EncodingProfile> entry : profileMap.entrySet()) { logger.info("Installed profile {}", entry.getValue().getIdentifier()); profiles.put(entry.getKey(), entry.getValue()); } sumInstalledFiles++; } catch (Exception e) { logger.error("Encoding profiles could not be read from {}: {}", artifact, e.getMessage()); } // Determine the number of available profiles String[] filesInDirectory = artifact.getParentFile().list(new FilenameFilter() { public boolean accept(File arg0, String name) { return name.endsWith(".properties"); } }); // Once all profiles have been loaded, announce readiness if (filesInDirectory.length == sumInstalledFiles) { Dictionary<String, String> properties = new Hashtable<String, String>(); properties.put(ARTIFACT, "encodingprofile"); logger.debug("Indicating readiness of encoding profiles"); bundleCtx.registerService(ReadinessIndicator.class.getName(), new ReadinessIndicator(), properties); logger.info("All {} encoding profiles installed", filesInDirectory.length); } else { logger.debug("{} of {} encoding profiles installed", sumInstalledFiles, filesInDirectory.length); } }
From source file:org.wso2.carbon.appfactory.jenkins.build.internal.JenkinsBuildServiceComponent.java
@SuppressWarnings("UnusedDeclaration") protected void activate(ComponentContext context) { if (log.isDebugEnabled()) { log.debug("Jenkins build service bundle is activated"); }// w w w .j a v a 2s . c o m try { if (isJenkinsEnabled()) { String jenkinsDefaultGlobalRoles = ServiceContainer.getAppFactoryConfiguration() .getFirstProperty(JenkinsCIConstants.DEFAULT_GLOBAL_ROLES_CONFIG_SELECTOR); String listenerPriority = ServiceContainer.getAppFactoryConfiguration() .getFirstProperty(JenkinsCIConstants.LISTENER_PRIORITY_CONFIG_SELECTOR); if (log.isDebugEnabled()) { log.debug(String.format("Default Global Roles : %s", jenkinsDefaultGlobalRoles)); log.debug(String.format("Listener Priority : %s", listenerPriority)); } RestBasedJenkinsCIConnector connector = RestBasedJenkinsCIConnector.getInstance(); String[] globalRoles = jenkinsDefaultGlobalRoles.split(","); if (globalRoles == null) { globalRoles = new String[] {}; } @SuppressWarnings("UnusedAssignment") int jenkinsListenerPriority = -1; try { jenkinsListenerPriority = Integer.parseInt(listenerPriority); } catch (NumberFormatException nef) { throw new IllegalArgumentException("Invalid priority specified for jenkins " + "application event listener. Please " + "provide a number", nef); } JenkinsCISystemDriver jenkinsCISystemDriver = new JenkinsCISystemDriver(connector, globalRoles); ServiceContainer.setJenkinsCISystemDriver(jenkinsCISystemDriver); BundleContext bundleContext = context.getBundleContext(); // Note: register the service only if its enabled in the // appfactory // configuration file. bundleContext.registerService(ContinuousIntegrationSystemDriver.class.getName(), jenkinsCISystemDriver, null); // Registering the Jenkins application event listener. bundleContext.registerService(ApplicationEventsHandler.class.getName(), new JenkinsApplicationEventsListener("JenkinsApplicationEventsListener", jenkinsListenerPriority), null); bundleContext.registerService(TenantUserEventListner.class.getName(), new JenkinsTenantUserEventListner(), null); Dictionary<String, Object> propsBuild = new Hashtable<String, Object>(); propsBuild.put(AppFactoryConstants.STORAGE_TYPE, AppFactoryConstants.BUILDABLE_STORAGE_TYPE); JenkinsStorage jenkinsStorage = new JenkinsStorage(connector); try { bundleContext.registerService(Storage.class.getName(), jenkinsStorage, propsBuild); } catch (Exception e1) { log.error("Appfactory jenkins Storage register problem ," + e1.getMessage()); } Dictionary<String, Object> propsNonBuild = new Hashtable<String, Object>(); propsNonBuild.put(AppFactoryConstants.STORAGE_TYPE, AppFactoryConstants.NONBUILDABLE_STORAGE_TYPE); try { bundleContext.registerService(Storage.class.getName(), new NonBuildableStorage(), propsNonBuild); } catch (Exception e1) { log.error("Appfactory Non-Build Storage register problem ," + e1.getMessage()); } bundleContext.registerService(TenantBuildManagerInitializer.class.getName(), new TenantBuildManagerInitializerImpl(), null); ClassLoader loader = getClass().getClassLoader(); SetBucketStrategy(loader); SetJenkinsClusterStrategy(loader); } else { log.info("Jenkins is not enabled"); } } catch (Throwable e) { log.error("Error in registering Jenkins build service ", e); } }