Example usage for java.util Dictionary put

List of usage examples for java.util Dictionary put

Introduction

In this page you can find the example usage for java.util Dictionary put.

Prototype

public abstract V put(K key, V value);

Source Link

Document

Maps the specified key to the specified value in this dictionary.

Usage

From source file:org.apache.sling.event.it.AbstractJobHandlingTest.java

public void setup() throws IOException {
    // set load delay to 3 sec
    final org.osgi.service.cm.Configuration c2 = this.configAdmin
            .getConfiguration("org.apache.sling.event.impl.jobs.jcr.PersistenceHandler", null);
    Dictionary<String, Object> p2 = new Hashtable<String, Object>();
    p2.put(JobManagerConfiguration.PROPERTY_BACKGROUND_LOAD_DELAY, 3L);
    // and startup.delay to 1sec - otherwise default of 30sec breaks tests!
    p2.put(JobManagerConfiguration.PROPERTY_STARTUP_DELAY, 1L);
    c2.update(p2);/*from w ww.j  a v a  2  s.c  om*/

    // SLING-5560 : since the above (re)config is now applied, we're safe
    // to go ahead and start the sling.event bundle.
    // this time, the JobManagerConfiguration will be activated
    // with the 'startup.delay' set to 1sec - so that ITs actually succeed
    try {
        Bundle[] bundles = bc.getBundles();
        for (Bundle bundle : bundles) {
            if (bundle.getSymbolicName().contains("sling.event")) {
                // assuming we only have 1 bundle that contains 'sling.event'
                LoggerFactory.getLogger(getClass()).info("starting bundle... " + bundle);
                bundle.start();
                break;
            }
        }
    } catch (BundleException e) {
        LoggerFactory.getLogger(getClass()).error("could not start sling.event bundle: " + e, e);
        throw new RuntimeException(e);
    }
}

From source file:org.wso2.carbon.user.core.common.DefaultRealmService.java

public DefaultRealmService(BundleContext bc, RealmConfiguration realmConfig) throws Exception {
    if (realmConfig != null) {
        this.bootstrapRealmConfig = realmConfig;
    } else {//from w  ww .  j  a  v a  2 s. c o m
        this.bootstrapRealmConfig = buildBootStrapRealmConfig();
    }
    this.tenantMgtConfiguration = buildTenantMgtConfig(bc, this.bootstrapRealmConfig
            .getUserStoreProperty(UserCoreConstants.TenantMgtConfig.LOCAL_NAME_TENANT_MANAGER));
    this.dataSource = DatabaseUtil.getRealmDataSource(bootstrapRealmConfig);
    initializeDatabase(dataSource);
    properties.put(UserCoreConstants.DATA_SOURCE, dataSource);
    properties.put(UserCoreConstants.FIRST_STARTUP_CHECK, isFirstInitialization);

    //this.tenantManager = this.initializeTenantManger(this.getTenantConfigurationElement(bc));
    this.tenantManager = this.initializeTenantManger(this.tenantMgtConfiguration);
    this.tenantManager.setBundleContext(bc);
    //initialize existing partitions if applicable with the particular tenant manager.
    this.tenantManager.initializeExistingPartitions();
    // initializing the bootstrapRealm
    this.bc = bc;
    bootstrapRealm = initializeRealm(bootstrapRealmConfig, MultitenantConstants.SUPER_TENANT_ID);
    Dictionary<String, String> dictionary = new Hashtable<String, String>();
    dictionary.put(UserCoreConstants.REALM_GENRE, UserCoreConstants.DELEGATING_REALM);
    if (bc != null) {
        // note that in a case of we don't run this in an OSGI envrionment
        // like checkin-client,
        // we need to avoid the registration of the service
        bc.registerService(UserRealm.class.getName(), bootstrapRealm, dictionary);
    }

}

From source file:org.sakaiproject.nakamura.solr.MultiMasterSolrClient.java

public void enable(SolrClientListener listener) throws IOException, ParserConfigurationException, SAXException {
    if (enabled) {
        return;// w ww. j  a  v a  2  s.  co  m
    }

    String configLocation = "solrconfig.xml";
    String schemaLocation = "schema.xml";
    if (multiMasterProperties != null) {
        configLocation = (String) multiMasterProperties.get(PROP_SOLR_CONFIG);
        schemaLocation = (String) multiMasterProperties.get(PROP_SOLR_SCHEMA);
    }

    // Note that the following property could be set through JVM level
    // arguments too
    LOGGER.debug("Logger for Embedded Solr is in {slinghome}/log/solr.log at level INFO");
    Configuration logConfiguration = getLogConfiguration();

    // create a log configuration if none was found. leave alone any found
    // configurations
    // so that modifications will persist between server restarts
    if (logConfiguration == null) {
        logConfiguration = configurationAdmin
                .createFactoryConfiguration("org.apache.sling.commons.log.LogManager.factory.config", null);
        Dictionary<String, Object> loggingProperties = new Hashtable<String, Object>();
        loggingProperties.put("org.apache.sling.commons.log.level", "INFO");
        loggingProperties.put("org.apache.sling.commons.log.file", "logs/solr.log");
        loggingProperties.put("org.apache.sling.commons.log.names", "org.apache.solr");
        // add this property to give us something unique to re-find this
        // configuration
        loggingProperties.put(LOGGER_KEY, LOGGER_VAL);
        logConfiguration.update(loggingProperties);
    }

    System.setProperty("solr.solr.home", solrHome);
    File solrHomeFile = new File(solrHome);
    File coreDir = new File(solrHomeFile, NAKAMURA);
    // File coreConfigDir = new File(solrHomeFile,"conf");
    deployFile(solrHomeFile, "solr.xml");
    // deployFile(coreConfigDir,"solrconfig.xml");
    // deployFile(coreConfigDir,"schema.xml");
    ClassLoader contextClassloader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
    ClosableInputSource schemaSource = null;
    ClosableInputSource configSource = null;
    try {
        NakamuraSolrResourceLoader loader = new NakamuraSolrResourceLoader(solrHome,
                this.getClass().getClassLoader());
        coreContainer = new CoreContainer(loader);
        configSource = getStream(configLocation);
        schemaSource = getStream(schemaLocation);
        SolrConfig config = new NakamuraSolrConfig(loader, configLocation, configSource);
        IndexSchema schema = new IndexSchema(config, null, schemaSource);
        nakamuraCore = new SolrCore(NAKAMURA, coreDir.getAbsolutePath(), config, schema, null);
        coreContainer.register(NAKAMURA, nakamuraCore, false);
        server = new EmbeddedSolrServer(coreContainer, NAKAMURA);
        LoggerFactory.getLogger(this.getClass()).info("Contans cores {} ", coreContainer.getCoreNames());
    } finally {
        Thread.currentThread().setContextClassLoader(contextClassloader);
        safeClose(schemaSource);
        safeClose(configSource);
    }

    this.enabled = true;
    this.listener = listener;
}

From source file:ch.entwine.weblounge.kernel.publisher.EndpointPublishingService.java

/**
 * Creates a REST endpoint for the JAX-RS annotated service.
 * /* w w  w .  ja va2  s . co  m*/
 * @param service
 *          The jsr311 annotated service
 * @param contextPath
 *          the http context
 * @param bundle
 *          the registering bundle
 * @param the
 *          endpoint's path
 */
protected void registerEndpoint(Object service, String contextPath, String endpointPath, Bundle bundle) {
    try {
        JAXRSServlet servlet = new JAXRSServlet(endpointPath, service, bundle);
        servlet.setSite(sites.findSiteByBundle(bundle));
        servlet.setEnvironment(environment);
        Dictionary<String, String> initParams = new Hashtable<String, String>();
        initParams.put(SharedHttpContext.ALIAS, contextPath);
        initParams.put(SharedHttpContext.SERVLET_NAME, service.toString());
        initParams.put(SharedHttpContext.CONTEXT_ID, SharedHttpContext.WEBLOUNGE_CONTEXT_ID);
        ServiceRegistration reg = bundleContext.registerService(Servlet.class.getName(), servlet, initParams);
        endpointRegistrations.put(contextPath, reg);
        endpointServlets.put(contextPath, servlet);
        logger.debug("Registering {} at {}", service, contextPath);
    } catch (Throwable t) {
        logger.error("Error registering rest service at " + contextPath, t);
        return;
    }
}

From source file:org.opennaas.core.security.acl.ACLManager.java

/**
 * It is necessary to register the OSGi service here, because OSGi ConfigurationAdmin service has access to "ws.rest.url", required to register
 * our REST API//from w w w.  j  ava  2s. co  m
 * 
 * @throws IOException
 */
private void registerOSGiService() throws IOException {
    Dictionary<String, String> props = new Hashtable<String, String>();
    ConfigurationAdminUtil configurationAdmin = new ConfigurationAdminUtil(Activator.getBundleContext());
    String url = configurationAdmin.getProperty("org.opennaas", "ws.rest.url");

    if (props != null) {
        props.put("service.exported.interfaces", "*");
        props.put("service.exported.configs", "org.apache.cxf.rs");
        props.put("service.exported.intents", "HTTP");
        props.put("org.apache.cxf.rs.httpservice.context", url + "/aclmanager");
        props.put("org.apache.cxf.rs.address", "/");
        props.put("org.apache.cxf.httpservice.requirefilter", "true");
    }
    log.info("Registering ws in url: " + props.get("org.apache.cxf.rs.httpservice.context"));
    Activator.getBundleContext().registerService(IACLManager.class.getName(), this, props);
}

From source file:com.whizzosoftware.hobson.bootstrap.api.hub.OSGIHubManager.java

@Override
public void setSetupWizardComplete(String userId, String hubId, boolean complete) {
    try {/*w  w w .  j ava  2  s  .c  o  m*/
        Configuration config = getConfiguration();
        Dictionary props = config.getProperties();
        if (props == null) {
            props = new Hashtable();
        }
        props.put(SETUP_COMPLETE, complete);

        updateConfiguration(config, props);
    } catch (IOException e) {
        throw new HobsonRuntimeException("Error setting setup wizard completion status", e);
    }
}

From source file:in.andres.kandroid.kanboard.KanboardProject.java

public void setExtra(@NonNull List<KanboardColumn> columns, @NonNull List<KanboardSwimlane> swimlanes,
        @NonNull List<KanboardCategory> categories, @NonNull List<KanboardTask> activetasks,
        @NonNull List<KanboardTask> inactivetasks, @NonNull List<KanboardTask> overduetasks,
        @NonNull Dictionary<Integer, String> projectusers) {
    Columns = columns;/* w  w w.ja v a 2 s.  co m*/
    Swimlanes = swimlanes;
    for (KanboardColumn col : Columns) {
        Dictionary<Integer, List<KanboardTask>> tmpTable = new Hashtable<>();
        for (KanboardSwimlane swim : Swimlanes) {
            tmpTable.put(swim.getId(), new ArrayList<KanboardTask>());
            GroupedInactiveTasks.put(swim.getId(), new ArrayList<KanboardTask>());
            GroupedOverdueTasks.put(swim.getId(), new ArrayList<KanboardTask>());
        }
        GroupedActiveTasks.put(col.getId(), tmpTable);
    }
    Categories = categories;
    for (KanboardCategory cat : Categories)
        CategoryHashtable.put(cat.getId(), cat);
    ActiveTasks = activetasks;
    for (KanboardTask task : ActiveTasks) {
        GroupedActiveTasks.get(task.getColumnId()).get(task.getSwimlaneId()).add(task);
        TaskHashtable.put(task.getId(), task);
    }
    InactiveTasks = inactivetasks;
    for (KanboardTask task : InactiveTasks) {
        GroupedInactiveTasks.get(task.getSwimlaneId()).add(task);
        TaskHashtable.put(task.getId(), task);
    }
    for (KanboardTask task : overduetasks) {
        OverdueTasks.add(TaskHashtable.get(task.getId()));
        GroupedOverdueTasks.get(TaskHashtable.get(task.getId()).getSwimlaneId())
                .add(TaskHashtable.get(task.getId()));
    }
    ProjectUsers = projectusers;
}

From source file:org.opennaas.itests.core.resources.CoreTest.java

@Test
public void registerHandlerAndPublishEventTest() throws InterruptedException {
    EventFilter filter1 = new EventFilter(new String[] { eventTopic });

    EventFilter filter2 = new EventFilter(new String[] { eventTopic },
            "(" + filterPropertyName + "=" + filterPropertyValue + ")");

    EventHandler handler1 = new EventHandler() {
        @Override/*from  ww w .  java2s . co  m*/
        public void handleEvent(Event event) {

            log.info("Handler1 Received event");
            log.info("Topic: " + event.getTopic());
            log.info("Properties: ");
            for (String propName : event.getPropertyNames())
                log.info(propName + " : " + event.getProperty(propName));

            h1Received.add(event);
        }
    };

    EventHandler handler2 = new EventHandler() {
        @Override
        public void handleEvent(Event event) {

            log.info("Handler2 Received event");
            log.info("Topic: " + event.getTopic());
            log.info("Properties: ");
            for (String propName : event.getPropertyNames())
                log.info(propName + " : " + event.getProperty(propName));

            h2Received.add(event);
        }
    };

    log.info("Registering Handlers...");
    int handler1Id = eventManager.registerEventHandler(handler1, filter1);
    int handler2Id = eventManager.registerEventHandler(handler2, filter2);
    log.info("Registering Handlers... DONE");

    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put(filterPropertyName, filterPropertyValue);

    Event event = new Event(eventTopic, properties);

    log.info("Publishing event...");
    eventManager.publishEvent(event);
    log.info("Publishing event... DONE");

    Event h1Event = h1Received.poll(10, SECONDS);
    Event h2Event = h2Received.poll(10, SECONDS);

    log.info("Checking reception...");
    assertNotNull(h1Event);
    assertNotNull(h2Event);
    assertNotNull(h2Event.getProperty(filterPropertyName));
    assertTrue(h2Event.getProperty(filterPropertyName).equals(filterPropertyValue));
    log.info("Checking reception... DONE");

    log.info("Unregistering Handlers...");
    eventManager.unregisterHandler(handler1Id);
    eventManager.unregisterHandler(handler2Id);
    log.info("Unregistering Handlers... DONE");

}

From source file:ddf.catalog.metrics.SourceMetricsImpl.java

/**
 * Creates the JMX Collector for an associated metric's JMX MBean.
 * /*from  ww w.  j  a v  a 2 s.  co  m*/
 * @param sourceId
 * @param collectorName
 * @return the PID of the JmxCollector Managed Service Factory created
 */
private String createMetricsCollector(String sourceId, String collectorName) {

    LOGGER.trace("ENTERING: createMetricsCollector - sourceId = {},   collectorName = {}", sourceId,
            collectorName);

    String pid = null;

    String rrdPath = getRrdFilename(sourceId, collectorName);

    // Create the Managed Service Factory for the JmxCollector, setting its service properties
    // to the MBean it will poll and the RRD file it will populate
    try {
        Configuration config = configurationAdmin.createFactoryConfiguration(JMX_COLLECTOR_FACTORY_PID, null);
        Dictionary<String, String> props = new Hashtable<String, String>();
        props.put("mbeanName", MBEAN_PACKAGE_NAME + ":name=" + sourceId + "." + collectorName);
        props.put("mbeanAttributeName", "Count");
        props.put("rrdPath", rrdPath);
        props.put("rrdDataSourceName", "data");
        props.put("rrdDataSourceType", "COUNTER");
        config.update(props);
        pid = config.getPid();
        LOGGER.debug("JmxCollector pid = {} for sourceId = {}", pid, sourceId);
    } catch (IOException e) {
        LOGGER.warn("Unable to create " + collectorName + " JmxCollector for source " + sourceId, e);
    }

    LOGGER.trace("EXITING: createMetricsCollector");

    return pid;
}

From source file:org.codice.ddf.configuration.admin.ExportMigrationConfigurationAdminEntry.java

public boolean store() {
    if (!stored) {
        LOGGER.debug("Exporting configuration [{}] to [{}]...", configuration.getPid(), entry.getPath());
        final Dictionary<String, Object> props = configuration.getProperties();

        // just make sure the pid, bundle location, and factory pid are correct as sometimes they
        // might/*from   ww w.  j  a  v a 2  s  . c  o m*/
        // get out of sync by an invalid update to the properties and we do rely on those at import
        // time
        final String factoryPid = configuration.getFactoryPid();

        if (factoryPid != null) {
            props.put(ConfigurationAdmin.SERVICE_FACTORYPID, factoryPid);
        } else {
            props.remove(ConfigurationAdmin.SERVICE_FACTORYPID);
        }
        props.put(Constants.SERVICE_PID, configuration.getPid());
        final String location = configuration.getBundleLocation();

        if (location != null) {
            props.put(ConfigurationAdmin.SERVICE_BUNDLELOCATION, location);
        } else {
            props.remove(ConfigurationAdmin.SERVICE_BUNDLELOCATION);
        }
        this.stored = entry.store((r, out) -> persister.write(out, props));
    }
    return stored;
}