List of usage examples for java.util.concurrent ConcurrentNavigableMap put
V put(K key, V value);
From source file:com.whizzosoftware.hobson.mqtt.MQTTPlugin.java
protected void registerDevice(String id, String name, Collection<VariableUpdate> initialData) { DeviceContext ctx = DeviceContext.create(getContext(), id); if (!hasDevice(ctx)) { MQTTDevice device = new MQTTDevice(this, id, name, DeviceType.SENSOR, initialData); publishDevice(device);/*from w ww.j a va2 s.com*/ ConcurrentNavigableMap<String, String> devices = db.getTreeMap("devices"); devices.put(id, device.toJSON().toString()); db.commit(); } getDeviceManager().setDeviceAvailability(ctx, true, System.currentTimeMillis()); }
From source file:actions.DownloadSPDX.java
/** * Adds a repository to our queue/* www . j a v a 2s.c o m*/ * @param repository A repository line as extracted from the text file */ private void queueAdd(final String repository) { // this is a good moment to save a recovery point right here ConcurrentNavigableMap<String, Long> map = dbQueue.getTreeMap("queue"); // put on the database, if it is already there then it gets overwritten map.put(repository, System.currentTimeMillis()); dbQueue.commit(); }
From source file:org.apache.sling.models.impl.AdapterImplementations.java
/** * Add implementation mapping for the given adapter type. * @param adapterType Adapter type//from ww w.ja va2 s.c o m * @param implType Implementation type */ @SuppressWarnings("unchecked") public void add(Class<?> adapterType, Class<?> implType) { String key = adapterType.getName(); if (adapterType == implType) { modelClasses.put(key, new ModelClass(implType, sortedStaticInjectAnnotationProcessorFactories)); } else { // although we already use a ConcurrentMap synchronize explicitly because we apply non-atomic operations on it synchronized (adapterImplementations) { ConcurrentNavigableMap<String, ModelClass<?>> implementations = adapterImplementations.get(key); if (implementations == null) { // to have a consistent ordering independent of bundle loading use a ConcurrentSkipListMap that sorts by class name implementations = new ConcurrentSkipListMap<String, ModelClass<?>>(); adapterImplementations.put(key, implementations); } implementations.put(implType.getName(), new ModelClass(implType, sortedStaticInjectAnnotationProcessorFactories)); } } }
From source file:com.jivesoftware.os.upena.service.UpenaTable.java
@Override @SuppressWarnings("unchecked") public ConcurrentNavigableMap<K, TimestampedValue<V>> find(boolean removeBadKeysEnabled, final KeyValueFilter<K, V> filter) throws Exception { final ConcurrentNavigableMap<K, TimestampedValue<V>> results = filter == null ? null : filter.createCollector();/* w ww .jav a 2 s . co m*/ List<RowIndexKey> badKeys = Lists.newArrayList(); store.scan((transactionId, key, value) -> { K k = null; try { if (!value.getTombstoned()) { k = mapper.readValue(key.getKey(), keyClass); } } catch (Exception x) { LOG.warn("Failed to scan. {}", new Object[] { filter }, x); badKeys.add(key); } if (k != null) { V v = mapper.readValue(value.getValue(), valueClass); if (results != null && filter != null && filter.filter(k, v)) { results.put(k, new BasicTimestampedValue(v, value.getTimestampId(), value.getTombstoned())); } } return true; }); if (!badKeys.isEmpty()) { if (removeBadKeysEnabled) { for (RowIndexKey key : badKeys) { store.remove(key); } LOG.info("Removed {} bad keys", badKeys.size()); } else { LOG.warn("Find for filter:{} has {} bad keys.", filter, badKeys.size()); } } return results; }