List of usage examples for java.util.concurrent ConcurrentMap put
V put(K key, V value);
From source file:org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation.java
/** * Add a rate sample for a rate metric.// w ww. j a va 2 s . c o m * @param name of the rate metric * @param elapsed time */ public void add(String name, long elapsed) { ConcurrentMap<String, ThreadSafeSampleStat> localStats = threadLocalMetricsMap.get(); if (localStats == null) { localStats = new ConcurrentHashMap<>(); threadLocalMetricsMap.set(localStats); weakReferenceQueue.add(new WeakReference<>(localStats)); } ThreadSafeSampleStat stat = localStats.get(name); if (stat == null) { stat = new ThreadSafeSampleStat(); localStats.put(name, stat); } stat.add(elapsed); }
From source file:org.onosproject.store.trivial.impl.SimpleGroupStore.java
@Override public void addOrUpdateExtraneousGroupEntry(Group group) { ConcurrentMap<GroupId, Group> extraneousIdTable = getExtraneousGroupIdTable(group.deviceId()); extraneousIdTable.put(group.id(), group); // Check the reference counter if (group.referenceCount() == 0) { notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_REQUESTED, group)); }//from ww w . ja va 2 s . c om }
From source file:org.apereo.portal.layout.StylesheetUserPreferencesImpl.java
@Override public String setLayoutAttribute(String nodeId, String name, String value) { Validate.notEmpty(nodeId, "nodeId cannot be null"); Validate.notEmpty(name, "name cannot be null"); Validate.notEmpty(value, "value cannot be null"); ConcurrentMap<String, String> nodeAttributes; synchronized (this.layoutAttributes) { nodeAttributes = this.layoutAttributes.get(nodeId); if (nodeAttributes == null) { nodeAttributes = new ConcurrentHashMap<String, String>(); this.layoutAttributes.put(nodeId, nodeAttributes); }/*from ww w. jav a 2 s . co m*/ } return nodeAttributes.put(name, value); }
From source file:org.onosproject.store.trivial.impl.SimpleGroupStore.java
private void storeGroupDescriptionInternal(GroupDescription groupDesc) { // Check if a group is existing with the same key if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) { return;//w w w .j a va2s .c o m } // Get a new group identifier GroupId id = new DefaultGroupId(getFreeGroupIdValue(groupDesc.deviceId())); // Create a group entry object StoredGroupEntry group = new DefaultGroup(id, groupDesc); // Insert the newly created group entry into concurrent key and id maps ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(groupDesc.deviceId()); keyTable.put(groupDesc.appCookie(), group); ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(groupDesc.deviceId()); idTable.put(id, group); notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group)); }
From source file:com.engine.QuoteServlet.java
private String lookupNearestWarehouse(String originZip) { String zip = ""; java.sql.Connection con = null; java.sql.PreparedStatement stmt = null; java.sql.ResultSet rs = null; try {//from w w w. j ava 2 s . co m con = ControlPanelPool.getInstance().getConnection(); stmt = con.prepareStatement("SELECT * FROM tblWarehouse WHERE Active = 1"); ConcurrentMap<String, String> warehouseZip = new ConcurrentHashMap<>(); rs = stmt.executeQuery(); while (rs.next()) { if (rs.getString("WHZIP") != null) { warehouseZip.put(rs.getString("WHZIP"), ""); } } for (String key : warehouseZip.keySet()) { if (key.matches("[0-9]+")) { URL url = new URL("http://10.1.1.58:8080/zip/distance?zip1=" + originZip + "&zip2=" + key); URLConnection conn = url.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); String inputLine; while ((inputLine = br.readLine()) != null) { warehouseZip.put(key, inputLine.substring(1, inputLine.length() - 1)); } br.close(); } } double min = 10000.0; for (String key : warehouseZip.keySet()) { if (!warehouseZip.get(key).isEmpty() && warehouseZip.get(key) != null) { if (Double.valueOf(warehouseZip.get(key)) < min) { min = Double.valueOf(warehouseZip.get(key)); zip = key; } } } con.close(); } catch (IOException | SQLException | PropertyVetoException ex) { Logger.getLogger(QuoteServlet.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(con, stmt, rs); } return zip; }
From source file:com.flexive.war.beans.admin.main.LockBean.java
/** * Synchronizes the list of results with the marked Ids (GUI) *///from www . ja v a 2 s.c om private void synchMarkedMap() { if (results == null) { markedLocks = new ConcurrentHashMap<FxPK, Boolean>(0); return; } ConcurrentMap<FxPK, Boolean> tmp = new ConcurrentHashMap<FxPK, Boolean>(results.size()); for (FxLock l : results) { final FxPK resultPK = l.getLockedPK(); if (markedLocks.containsKey(resultPK)) tmp.put(resultPK, markedLocks.get(resultPK)); else tmp.put(resultPK, false); } markedLocks = new ConcurrentHashMap<FxPK, Boolean>(tmp.size()); markedLocks.putAll(tmp); }
From source file:org.polymap.p4.atlas.ui.SearchContentProvider.java
/** * *///from w ww. j a v a2 s. c o m protected void updateMap(IMap elm, int currentChildCount) { updateChildrenLoading(elm); ConcurrentMap<String, ILayer> children = new ConcurrentSkipListMap(); List<UIJob> jobs = new ArrayList(); for (ILayer layer : elm.layers) { UIJob job = UIJob.schedule(layer.label.get(), monitor -> { if (AtlasFeatureLayer.of(layer).get().isPresent()) { children.put(layer.label.get(), layer); } }); jobs.add(job); } ; jobs.forEach(job -> job.joinAndDispatch(5000)); updateChildren(elm, children.values().toArray(), currentChildCount); }
From source file:org.onosproject.store.trivial.impl.SimpleGroupStore.java
/** * Stores a new group entry using the information from group description. * * @param groupDesc group description to be used to create group entry *///from w w w . jav a 2s.c o m @Override public void storeGroupDescription(GroupDescription groupDesc) { // Check if a group is existing with the same key if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) { return; } if (deviceAuditStatus.get(groupDesc.deviceId()) == null) { // Device group audit has not completed yet // Add this group description to pending group key table // Create a group entry object with Dummy Group ID StoredGroupEntry group = new DefaultGroup(dummyGroupId, groupDesc); group.setState(GroupState.WAITING_AUDIT_COMPLETE); ConcurrentMap<GroupKey, StoredGroupEntry> pendingKeyTable = getPendingGroupKeyTable( groupDesc.deviceId()); pendingKeyTable.put(groupDesc.appCookie(), group); return; } storeGroupDescriptionInternal(groupDesc); }
From source file:org.sakaiproject.memory.impl.GenericMultiRefCacheImpl.java
/** * Make sure there's an entry in refs for this ref that includes this key. * * @param ref/*from w ww.ja v a 2s . c o m*/ * The entity reference string. * @param key * The cache entry key dependent on this entity ref. */ protected void addRefCachedKey(String ref, Object key) { // Isn't this a threading issue. Two thread hit this and both put their own data into m_refsStore. ConcurrentMap<Object, Object> cachedKeys = new ConcurrentHashMap<Object, Object>(); ConcurrentMap<Object, Object> oldCachedKeys = m_refsStore.putIfAbsent(ref, cachedKeys); if (oldCachedKeys != null) { cachedKeys = oldCachedKeys; } cachedKeys.put(key, key); }
From source file:com.phearom.um.model.MyMusicProvider.java
/** * Get the list of music tracks from a server and caches the track information * for future reference, keying tracks by musicId and grouping by genre. *//*w w w . j ava 2 s . com*/ private void buildListsByGenre() { ConcurrentMap<String, List<MediaMetadataCompat>> newMusicListByGenre = new ConcurrentHashMap<>(); for (MutableMediaMetadata m : mMusicListById.values()) { String genre = m.metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE); List<MediaMetadataCompat> list = newMusicListByGenre.get(genre); if (list == null) { list = new ArrayList<>(); newMusicListByGenre.put(genre, list); } list.add(m.metadata); } mMusicListByGenre = newMusicListByGenre; }