Example usage for java.util Hashtable put

List of usage examples for java.util Hashtable put

Introduction

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

Prototype

public synchronized V put(K key, V value) 

Source Link

Document

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

Usage

From source file:com.softlayer.messaging.messagequeue.client.Client.java

/**
 * adds the auth token to the request header
 * //from  www .jav a2s  .  c om
 * @return hashtable of token key value
 */
protected Hashtable<String, String> createHeaderToken() {

    Hashtable<String, String> params = new Hashtable<String, String>();
    params.put(TOKEN, this.token);
    return params;
}

From source file:sim.app.sugarscape.util.ResultsGrapher.java

public int[] getUniqueIntVals(int[] vals) {
    int count = 0;
    int size = vals.length;
    Hashtable h = new Hashtable(size);
    for (int a = 0; a < size; a++) {
        h.put(new Integer(vals[a]), "");
    }//  w  w w .  ja va 2 s .  com
    int[] unique = new int[h.size()];
    ArrayList dummy = new ArrayList(h.size());
    java.util.Enumeration e = h.keys();
    int counter = 0;
    while (e.hasMoreElements()) {
        unique[counter] = ((Integer) e.nextElement()).intValue();
        System.out.print(unique[counter] + " ");
        dummy.add(".");
        counter++;
    }
    FastQSortAlgorithm f = new FastQSortAlgorithm();
    f.sort(unique, dummy);
    return unique;
}

From source file:ancat.console.ConsoleModelChecker.java

/**
 * Creates a table with configuration data. Each time the function is called a
 * new object is created./*from w ww.j a  v a2s  .  c om*/
 * 
 * @return HashTable containing configuration data. Supported Keys: modelFile
 *         - The file containing the model description (the graph file)
 *         outFolder - The output folder inspectors - A Vector<String> object
 *         containing the names of the requested inspectors inspectorsRaw -
 *         Parsed XML configuration data inspectorObjects - The created
 *         inspector objects
 */
protected Hashtable<String, Object> getConfiguration() {
    Hashtable<String, Object> configuration = new Hashtable<String, Object>();

    configuration.put("modelFile", _modelFiles);

    if (null != _outFolder)
        configuration.put("outFolder", _outFolder);

    if (null != _inspectors)
        configuration.put("inspectors", _inspectors);

    if (null != _inspectorData)
        configuration.put("inspectorsRaw", _inspectorData);

    if (null != _inspectorObjects)
        configuration.put("inspectorObjects", _inspectorObjects);

    return configuration;
}

From source file:net.solarnetwork.node.util.BeanConfigurationServiceRegistrationListener.java

/**
 * Callback when an object has been registered.
 * /*from   www  .ja v a 2 s .c o m*/
 * <p>
 * This method will instantiate a new instance of {@link #getServiceClass()}
 * and configure its properties via the Map returned by
 * {@link BeanConfiguration#getConfiguration()}. Afterwards it will register
 * the instance as a service, using the {@link #getServiceInterfaces()} as
 * the service interfaces and {@link #getServiceProperties()} as the service
 * properties (if available) combined with the
 * {@link BeanConfiguration#getAttributes()} (if available).
 * </p>
 * 
 * @param config
 *        the configuration object
 * @param properties
 *        the service properties
 */
public void onBind(BeanConfiguration config, Map<String, ?> properties) {
    if (log.isDebugEnabled()) {
        log.debug("Bind called on [" + config + "] with props " + properties);
    }
    Object service;
    try {
        service = serviceClass.newInstance();
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    Hashtable<String, Object> props = new Hashtable<String, Object>();
    if (serviceProperties != null) {
        props.putAll(serviceProperties);
    }
    if (config.getAttributes() != null) {
        props.putAll(config.getAttributes());
    }
    props.put(org.osgi.framework.Constants.SERVICE_RANKING, config.getOrdering());
    BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(service);
    wrapper.setPropertyValues(config.getConfiguration());

    addRegisteredService(new BeanConfigurationRegisteredService(config, properties), service, serviceInterfaces,
            props);
}

From source file:com.smartmarmot.orabbix.Orabbixmon.java

@Override
public void run() {
    try {//  www.j av  a2 s  .  c  o  m
        Configurator cfg = null;
        try {
            cfg = new Configurator(configFile);
        } catch (Exception e) {
            SmartLogger.logThis(Level.ERROR, "Error while creating configurator with " + configFile + " " + e);
        }
        RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
        String pid = rmxb.getName();
        SmartLogger.logThis(Level.INFO,
                Constants.PROJECT_NAME + " started with pid:" + pid.split("@")[0].toString());
        // System.out.print("pid: "+pid.split("@")[0].toString());
        String pidfile = cfg.getPidFile();
        try {
            Utility.writePid(pid.split("@")[0].toString(), pidfile);
        } catch (Exception e) {
            SmartLogger.logThis(Level.ERROR, "Error while trying to write pidfile " + e);
        }

        Locale.setDefault(Locale.US);

        DBConn[] myDBConn = cfg.getConnections();

        if (myDBConn == null) {
            SmartLogger.logThis(Level.ERROR, "ERROR on main - Connections is null");
            throw new Exception("ERROR on main - Connections is null");

        } else if (myDBConn.length == 0) {
            SmartLogger.logThis(Level.ERROR, "ERROR on main - Connections is empty");
            throw new Exception("ERROR on main - Connections is empty");
        }

        /**
         * retrieve maxThread
         */
        Integer maxThread = 0;
        try {
            maxThread = cfg.getMaxThread();
        } catch (Exception e) {
            SmartLogger.logThis(Level.WARN,
                    "MaxThread not defined calculated maxThread = " + myDBConn.length * 3);
        }
        if (maxThread == null)
            maxThread = 0;
        if (maxThread == 0) {
            maxThread = myDBConn.length * 3;
        }

        ExecutorService executor = Executors.newFixedThreadPool(maxThread.intValue());
        /**
         * populate qbox
         */
        Hashtable<String, Querybox> qbox = new Hashtable<String, Querybox>();
        for (int i = 0; i < myDBConn.length; i++) {
            Querybox qboxtmp = Configurator.buildQueryBoxbyDBName(myDBConn[i].getName());
            qbox.put(myDBConn[i].getName(), qboxtmp);
        } // for (int i = 0; i < myDBConn.length; i++) {

        cfg = null;
        /**
         * daemon begin here
         */
        while (running) {
            /**
             * istantiate a new configurator
             */
            Configurator c = new Configurator(configFile);

            /*
             * here i rebuild DB's List
             */
            if (!c.isEqualsDBList(myDBConn)) {

                // rebuild connections DBConn[]

                myDBConn = c.rebuildDBList(myDBConn);
                for (int i = 1; i < myDBConn.length; i++) {
                    if (!qbox.containsKey(myDBConn[i].getName())) {
                        Querybox qboxtmp = Configurator.buildQueryBoxbyDBName(myDBConn[i].getName());
                        qbox.put(myDBConn[i].getName(), qboxtmp);
                    }
                }
            } // if (!c.isEqualsDBList(myDBConn)) {

            /*
             * ready to run query
             */

            for (int i = 0; i < myDBConn.length; i++) {
                Querybox actqb = qbox.get(myDBConn[i].getName());
                actqb.refresh();
                Query[] q = actqb.getQueries();

                SharedPoolDataSource spds = myDBConn[i].getSPDS();

                Hashtable<String, Integer> zabbixServers = c.getZabbixServers();
                SmartLogger.logThis(Level.DEBUG, "Ready to run DBJob for dbname ->" + myDBConn[i].getName());
                Runnable runner = new DBJob(spds, q, Constants.QUERY_LIST, zabbixServers,
                        myDBConn[i].getName());
                executor.execute(runner);

            } // for (int i = 0; i < myDBConn.length; i++) {
            Thread.sleep(60 * 1000);
            SmartLogger.logThis(Level.DEBUG, "Waking up Goood Morning");
        }
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        System.out.println("Stopping");
        e1.printStackTrace();
        stopped = true;
    }

}

From source file:com.softlayer.messaging.messagequeue.client.Client.java

/**
 * This authenticates users for interactions with the softlayer message
 * queue/*from  ww  w .  j av  a2  s. c o m*/
 * 
 * @param username
 *            your username for IMS
 * @param password
 *            your API key for IMS
 * @return the auth token for interacting with the message queue service
 * @throws IOException
 * @throws JSONException
 * @throws UnexpectedReplyTypeException
 */
private String auth(String username, String apikey)
        throws IOException, JSONException, UnexpectedReplyTypeException {

    Hashtable<String, String> headers = new Hashtable<String, String>();
    headers.put(USERNAME, username);
    headers.put(APIKEY, apikey);
    String url = baseurl + AUTHURL;
    JSONObject reply = this.post(headers, null, null, url);

    return reply.getString("token");
}

From source file:net.sourceforge.floggy.persistence.fr2422928.FR2422928MigrationTest.java

/**
 * DOCUMENT ME!//from w w w .  j a  v a 2  s  .  c om
*/
public void testThrowExceptionWhenFieldNotMigratedWithLazyTrue() {
    MigrationManager um = MigrationManager.getInstance();

    try {
        Hashtable properties = new Hashtable();
        properties.put(MigrationManager.LAZY_LOAD, Boolean.TRUE);
        properties.put(MigrationManager.MIGRATE_FROM_PREVIOUS_1_3_0_VERSION, Boolean.TRUE);

        Enumeration enumeration = um.start(FR2422928Holder.class, properties);
        assertNotNull(enumeration);
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
}

From source file:net.ripe.rpki.commons.provisioning.cms.ProvisioningCmsObjectBuilder.java

private AttributeTable createSignedAttributes() {
    Hashtable<ASN1ObjectIdentifier, Attribute> attributes = new Hashtable<ASN1ObjectIdentifier, Attribute>(); // NOPMD
    // -//  ww w  . ja  v a2s.c om
    // ReplaceHashtableWithMap
    Attribute signingTimeAttribute = new Attribute(CMSAttributes.signingTime,
            new DERSet(new Time(new Date(DateTimeUtils.currentTimeMillis()))));
    attributes.put(CMSAttributes.signingTime, signingTimeAttribute);
    return new AttributeTable(attributes);
}

From source file:mypackage.FeedlyClient.java

public void addIntegerToPersistentDB(String key, int value) {
     synchronized (_persist) {
         Hashtable _tmp_ht = (Hashtable) _persist.getContents(codeSigningKey);
         _tmp_ht.put(key, new Integer(value));
         _persist.setContents(new ControlledAccess(_tmp_ht, codeSigningKey));
         PersistentObject.commit(_persist);
     }//from  w  w w  .  ja  va  2 s .  c  o m
 }

From source file:mypackage.FeedlyClient.java

public void addLongToPersistentDB(String key, long value) {
     synchronized (_persist) {
         Hashtable _tmp_ht = (Hashtable) _persist.getContents(codeSigningKey);
         _tmp_ht.put(key, new Long(value));
         _persist.setContents(new ControlledAccess(_tmp_ht, codeSigningKey));
         PersistentObject.commit(_persist);
     }/* w  w  w .  j  a  va 2  s .  c  o m*/
 }