List of usage examples for java.util.concurrent ConcurrentMap put
V put(K key, V value);
From source file:rocks.stalin.android.app.model.MusicProvider.java
private synchronized void buildListsByGenre() { ConcurrentMap<String, List<MediaMetadataCompat>> newMusicListByGenre = new ConcurrentHashMap<>(); for (MutableMediaMetadata m : mMusicListById.values()) { String genre = ""; if (m.metadata.containsKey(MediaMetadataCompat.METADATA_KEY_GENRE)) { genre = m.metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE); }/*from ww w .j a v a2 s .c o m*/ List<MediaMetadataCompat> list = newMusicListByGenre.get(genre); if (list == null) { list = new ArrayList<>(); newMusicListByGenre.put(genre, list); } list.add(m.metadata); } mMusicListByGenre = newMusicListByGenre; }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceUtil.java
private static void prepareParallel(Counter counter, FileSystem fs, Path base, List<Path> list, ExecutorService executor) throws IOException, InterruptedException { ConcurrentMap<Path, Boolean> requiredDirs = new ConcurrentHashMap<>(); parallel(executor, list.stream().map(p -> new Path(base, p)).map(file -> (Callable<?>) () -> { try {/*from ww w .java 2 s.c om*/ FileStatus stat = fs.getFileStatus(file); if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("deleting file: {0}", //$NON-NLS-1$ file)); } if (stat.isDirectory()) { fs.delete(file, true); } else { fs.delete(file, false); } counter.add(1); } catch (FileNotFoundException e) { Path parent = file.getParent(); if (fs.exists(parent) == false) { requiredDirs.put(parent, Boolean.TRUE); } } return null; }).collect(Collectors.toList())); parallel(executor, requiredDirs.keySet().stream().map(parent -> (Callable<?>) () -> { if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("creating directory: {0}", //$NON-NLS-1$ parent)); } fs.mkdirs(parent); counter.add(1); return null; }).collect(Collectors.toList())); }
From source file:com.whitecloud.ron.musicplayer.model.MusicProvider.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. *//*from w w w .ja va2s . c om*/ // public void retrieveMediaAsync(final Callback callback, String spotifyId) { // LogHelper.d(TAG, "retrieveMediaAsync called"); // if (mCurrentState == State.INITIALIZED) { // // Nothing to do, execute callback immediately // callback.onMusicCatalogReady(true, mSongs); // return; // } // // // Asynchronously load the music catalog in a separate thread // new AsyncTask<String, Void, State>() { // @Override // protected State doInBackground(String... params) { // retrieveMedia(params[0]); // return mCurrentState; // } // // @Override // protected void onPostExecute(State current) { // if (callback != null) { // callback.onMusicCatalogReady(current == State.INITIALIZED, mSongs); // } // } // }.execute(spotifyId); // } private synchronized 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; }
From source file:org.onosproject.store.trivial.impl.SimpleDeviceStore.java
@Override public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> portStats) { ConcurrentMap<PortNumber, PortStatistics> statsMap = devicePortStats.get(deviceId); if (statsMap == null) { statsMap = Maps.newConcurrentMap(); devicePortStats.put(deviceId, statsMap); }//from ww w . ja v a2 s .com for (PortStatistics stat : portStats) { PortNumber portNumber = PortNumber.portNumber(stat.port()); statsMap.put(portNumber, stat); } return new DeviceEvent(PORT_STATS_UPDATED, devices.get(deviceId), null); }
From source file:robert843.o2.pl.player.model.MusicProvider.java
private synchronized void retrieveMedia() { PlaylistDB pdb = new PlaylistDB(this.mContext); ConcurrentMap<String, List<MediaMetadata>> newMusicListByGenre = new ConcurrentHashMap<>(); try {//from w w w.java 2 s .co m if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; for (String playlist : pdb.getListPlaylist()) { for (String id : pdb.getTracks(playlist)) { List<MediaMetadata> list = newMusicListByGenre.get(playlist); if (list == null) { list = new ArrayList<>(); newMusicListByGenre.put(playlist, list); } MediaMetadata item = buildFromJSON(id); String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); list.add(item); } } mMusicListByGenre = newMusicListByGenre; /*int slashPos = CATALOG_URL.lastIndexOf('/'); String path = CATALOG_URL.substring(0, slashPos + 1); JSONObject jsonObj = fetchJSONFromUrl(CATALOG_URL); if (jsonObj == null) { return; } JSONArray tracks = jsonObj.getJSONArray(JSON_MUSIC); if (tracks != null) { for (int j = 0; j < tracks.length(); j++) { MediaMetadata item = buildFromJSON(tracks.getJSONObject(j), path); String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); }*/ mCurrentState = State.INITIALIZED; } } catch (JSONException e) { LogHelper.e(TAG, e, "Could not retrieve music list"); } catch (ParserConfigurationException e) { LogHelper.e(TAG, e, "Could not retrieve music list"); } catch (IOException e) { // e.printStackTrace(); } finally { if (mCurrentState != State.INITIALIZED) { // Something bad happened, so we reset state to NON_INITIALIZED to allow // retries (eg if the network connection is temporary unavailable) mCurrentState = State.NON_INITIALIZED; } } }
From source file:com.networknt.light.rule.menu.AbstractMenuRule.java
protected String getJsonByRid(String rid) { String json = null;// www .j a v a2 s . c o m Map<String, Object> menuMap = (Map<String, Object>) ServiceLocator.getInstance().getMemoryImage("menuMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) menuMap.get("cache"); if (cache != null) { json = (String) cache.get("rid"); } if (json == null) { json = DbService.getJsonByRid(rid); // put it into the blog cache. if (json != null) { if (cache == null) { cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(1000) .build(); menuMap.put("cache", cache); } cache.put(rid, json); } } return json; }
From source file:com.networknt.light.rule.AbstractRule.java
public Map<String, Object> getAccessByRuleClass(String ruleClass) throws Exception { Map<String, Object> access = null; Map<String, Object> accessMap = ServiceLocator.getInstance().getMemoryImage("accessMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) accessMap.get("cache"); if (cache == null) { cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(1000).build(); accessMap.put("cache", cache); } else {/*from w w w.ja v a 2 s .c o m*/ access = (Map<String, Object>) cache.get(ruleClass); } if (access == null) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OrientVertex accessVertex = (OrientVertex) graph.getVertexByKey("Access.ruleClass", ruleClass); if (accessVertex != null) { String json = accessVertex.getRecord().toJSON(); access = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() { }); cache.put(ruleClass, access); } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } } return access; }
From source file:org.midonet.brain.southbound.vtep.VtepDataClientImplTest.java
private Map<String, ConcurrentMap<String, Table<?>>> createMockCache() { OvsDBSet<UUID> ports = new OvsDBSet<>(); OvsDBSet<String> ips = new OvsDBSet<>(); OvsDBSet<String> tunnelIps = new OvsDBSet<>(); ips.add(MOCK_END_POINT.mgmtIp.toString()); tunnelIps.add(TUNNEL_IP.toString()); ports.add(new UUID(PHYSICAL_PORT_0)); ports.add(new UUID(PHYSICAL_PORT_1)); Physical_Switch ps = new Physical_Switch(); ps.setDescription(MOCK_DESCRIPTION); ps.setName(MOCK_NAME);// w w w. j a v a 2 s . c o m ps.setManagement_ips(ips); ps.setTunnel_ips(tunnelIps); ps.setPorts(ports); Physical_Port p1 = new Physical_Port(); p1.setName(PHYSICAL_PORT_0); p1.setVlan_bindings(new OvsDBMap<BigInteger, UUID>()); p1.setVlan_stats(new OvsDBMap<BigInteger, UUID>()); Physical_Port p2 = new Physical_Port(); p2.setName(PHYSICAL_PORT_1); p2.setVlan_bindings(new OvsDBMap<BigInteger, UUID>()); p2.setVlan_stats(new OvsDBMap<BigInteger, UUID>()); Map<String, ConcurrentMap<String, Table<?>>> mockCache = new ConcurrentHashMap<>(); ConcurrentMap<String, Table<?>> psRows = new ConcurrentHashMap<>(); psRows.put(MOCK_PHYSICAL_SWITCH_ID.toString(), ps); ConcurrentMap<String, Table<?>> portRows = new ConcurrentHashMap<>(); portRows.put(PHYSICAL_PORT_0, p1); portRows.put(PHYSICAL_PORT_1, p2); mockCache.put(Physical_Switch.NAME.getName(), psRows); mockCache.put(Physical_Port.NAME.getName(), portRows); return mockCache; }
From source file:com.murati.oszk.audiobook.model.MusicProvider.java
private synchronized void buildAlbumList() { //TODO: rename album to ebook ConcurrentMap<String, List<MediaMetadataCompat>> newAlbumList = new ConcurrentHashMap<>(); // Add tracks to ebook for (MutableMediaMetadata m : mTrackListById.values()) { String album = m.metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM); List<MediaMetadataCompat> list = newAlbumList.get(album); if (list == null) { list = new ArrayList<>(); newAlbumList.put(album, list); }// w w w . j av a 2 s .com list.add(m.metadata); } //Sort Individual ebooks by track numbers for (List<MediaMetadataCompat> album : newAlbumList.values()) { //MediaMetadataCompat[] sortedOrder = album.toArray(new MediaMetadataCompat[album.size()]); java.util.Collections.sort(album, new Comparator<MediaMetadataCompat>() { @Override public int compare(final MediaMetadataCompat lhs, MediaMetadataCompat rhs) { if (lhs.getLong(METADATA_KEY_TRACK_NUMBER) < rhs.getLong(METADATA_KEY_TRACK_NUMBER)) return -1; return 1; } }); } mEbookList = newAlbumList; }
From source file:org.midonet.cluster.southbound.vtep.VtepDataClientImplTest.java
private Map<String, ConcurrentMap<String, Table<?>>> createMockCache() { OvsDBSet<UUID> ports = new OvsDBSet<>(); OvsDBSet<String> ips = new OvsDBSet<>(); OvsDBSet<String> tunnelIps = new OvsDBSet<>(); ips.add(MOCK_END_POINT.mgmtIp().toString()); tunnelIps.add(TUNNEL_IP.toString()); ports.add(new UUID(PHYSICAL_PORT_ID_0.toString())); ports.add(new UUID(PHYSICAL_PORT_ID_1.toString())); Physical_Switch ps = new Physical_Switch(); ps.setDescription(MOCK_DESCRIPTION); ps.setName(MOCK_NAME);/*from ww w . ja v a2 s. co m*/ ps.setManagement_ips(ips); ps.setTunnel_ips(tunnelIps); ps.setPorts(ports); Physical_Port p1 = new Physical_Port(); p1.setName(PHYSICAL_PORT_0); p1.setVlan_bindings(new OvsDBMap<BigInteger, UUID>()); p1.setVlan_stats(new OvsDBMap<BigInteger, UUID>()); Physical_Port p2 = new Physical_Port(); p2.setName(PHYSICAL_PORT_1); p2.setVlan_bindings(new OvsDBMap<BigInteger, UUID>()); p2.setVlan_stats(new OvsDBMap<BigInteger, UUID>()); Map<String, ConcurrentMap<String, Table<?>>> mockCache = new ConcurrentHashMap<>(); ConcurrentMap<String, Table<?>> psRows = new ConcurrentHashMap<>(); psRows.put(MOCK_PHYSICAL_SWITCH_ID.toString(), ps); ConcurrentMap<String, Table<?>> portRows = new ConcurrentHashMap<>(); portRows.put(PHYSICAL_PORT_ID_0.toString(), p1); portRows.put(PHYSICAL_PORT_ID_1.toString(), p2); mockCache.put(Physical_Switch.NAME.getName(), psRows); mockCache.put(Physical_Port.NAME.getName(), portRows); return mockCache; }