List of usage examples for java.util.concurrent ConcurrentMap put
V put(K key, V value);
From source file:Main.java
public static void main(String[] args) { ConcurrentMap<String, String> cMap = new ConcurrentHashMap<>(); cMap.put("A", "A"); System.out.println("Concurrent Map: " + cMap); System.out.println(cMap.putIfAbsent("A", "1")); System.out.println(cMap.putIfAbsent("B", "B")); System.out.println(cMap.remove("A", "B")); System.out.println(cMap.replace("A", "B")); System.out.println("Concurrent Map: " + cMap); }
From source file:Test.java
private static void startUpdateThread(int i, final ConcurrentMap<Integer, String> concurrentMap) { Thread thread = new Thread(new Runnable() { public void run() { while (!Thread.interrupted()) { Random random = new Random(); int randomInt = random.nextInt(20); concurrentMap.put(randomInt, UUID.randomUUID().toString()); }/*from w w w . j a v a2s.c o m*/ } }); thread.setName("Update Thread " + i); updateThreads.add(thread); thread.start(); }
From source file:com.sm.store.cluster.Utils.java
public static ConcurrentMap<Short, String[]> buildServerMap(List<ClusterNodes> nodes) { ConcurrentMap<Short, String[]> map = new ConcurrentHashMap<Short, String[]>(nodes.size()); for (ClusterNodes node : nodes) { map.put(node.getId(), node.getServerArray()); }/*from ww w . j a v a 2 s . co m*/ return map; }
From source file:com.sm.store.cluster.Utils.java
public static ConcurrentMap<Integer, Short> buildPartitionMap(List<ClusterNodes> nodes) { ConcurrentMap<Integer, Short> map = new ConcurrentHashMap<Integer, Short>(nodes.size()); for (ClusterNodes node : nodes) { for (int i = 0; i < node.getPartitionArray().length; i++) { map.put(node.getPartitionArray()[i], node.getId()); }//from ww w . j a v a2 s. c o m } return map; }
From source file:org.unidle.test.LocationGenerator.java
private static ConcurrentMap<String, Boolean> locations() { final ConcurrentMap<String, Boolean> locations = new MapMaker().concurrencyLevel(THREADS).makeMap(); for (KnownLocation location : KnownLocation.values()) { final String name = formatLocation(location.continent, location.country, location.subdivision, location.city);/*from w w w .j ava 2s . c om*/ locations.put(name, !"".equals(location.address)); } return locations; }
From source file:org.xdi.oxauth.model.common.AbstractAuthorizationGrant.java
private static <T extends AbstractToken> void put(ConcurrentMap<String, T> p_map, List<T> p_list) { p_map.clear();/*from w w w. ja va 2 s . com*/ if (p_list != null && !p_list.isEmpty()) { for (T t : p_list) { p_map.put(t.getCode(), t); } } }
From source file:com.networknt.light.rule.rule.AbstractRuleRule.java
public static void loadCompileCache() { String sql = "SELECT FROM Rule"; Map<String, Object> compileMap = ServiceLocator.getInstance().getMemoryImage("compileMap"); ConcurrentMap<String, String> cache = (ConcurrentMap<String, String>) compileMap.get("cache"); if (cache == null) { cache = new ConcurrentLinkedHashMap.Builder<String, String>().maximumWeightedCapacity(10000).build(); compileMap.put("cache", cache); }/*from w w w.j av a2s. c o m*/ OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { for (Vertex rule : (Iterable<Vertex>) graph.command(new OCommandSQL(sql)).execute()) { cache.put((String) rule.getProperty("ruleClass"), (String) rule.getProperty("sourceCode")); } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } }
From source file:xbird.storage.io.RemoteVarSegments.java
public static void handleResponse(final TrackReadRequestMessage request, final ProtocolEncoderOutput out, final ConcurrentMap<String, FileChannel> fdCacheMap, final ConcurrentMap<String, IDescriptor> directoryCache) throws IOException { final String filePath = request.filePath; final long[] idxs = request.idxs; final int size = idxs.length; // look-up directory final File dataFile = new File(filePath); final long[] offsets = new long[size]; IDescriptor directory = directoryCache.get(filePath); try {/* w w w.ja va 2 s. c o m*/ if (directory == null) { directory = VarSegments.initDescriptor(dataFile); directoryCache.put(filePath, directory); } for (int i = 0; i < size; i++) { offsets[i] = directory.getRecordAddr(idxs[i]); } } catch (IOException e) { LOG.error(e); throw e; } FileChannel fileChannel = fdCacheMap.get(filePath); if (fileChannel == null) { if (!dataFile.exists()) { throw new IllegalStateException("file not exists: " + filePath); } final RandomAccessFile raf; try { raf = new RandomAccessFile(dataFile, "r"); } catch (FileNotFoundException e) { throw new IllegalStateException(e); } fileChannel = raf.getChannel(); fdCacheMap.put(filePath, fileChannel); } for (int i = 0; i < size; i++) { final long offset = offsets[i]; // get data length final ByteBuffer tmpBuf = ByteBuffer.allocate(4); try { fileChannel.read(tmpBuf, offset); } catch (IOException e) { LOG.error(e); throw e; } tmpBuf.flip(); final int length = tmpBuf.getInt(); tmpBuf.rewind(); IoBuffer ioBuf = IoBuffer.wrap(tmpBuf); out.write(ioBuf); // attempt zero-copy sendfile long position = offset + 4; long count = length; FileRegion fileRegion = new DefaultFileRegion(fileChannel, position, count); out.write(fileRegion); } }
From source file:org.apache.hadoop.hbase.master.replication.ReplicationPeerManager.java
public static ReplicationPeerManager create(ZKWatcher zk, Configuration conf) throws ReplicationException { ReplicationPeerStorage peerStorage = ReplicationStorageFactory.getReplicationPeerStorage(zk, conf); ConcurrentMap<String, ReplicationPeerDescription> peers = new ConcurrentHashMap<>(); for (String peerId : peerStorage.listPeerIds()) { ReplicationPeerConfig peerConfig = peerStorage.getPeerConfig(peerId); boolean enabled = peerStorage.isPeerEnabled(peerId); SyncReplicationState state = peerStorage.getPeerSyncReplicationState(peerId); peers.put(peerId, new ReplicationPeerDescription(peerId, enabled, peerConfig, state)); }// w w w.ja v a 2 s . c o m return new ReplicationPeerManager(peerStorage, ReplicationStorageFactory.getReplicationQueueStorage(zk, conf), peers); }
From source file:com.tamnd.core.util.ZConfig.java
private static void ConfigToMap(ConcurrentMap<String, String> map, Configuration config, boolean overwrDup) { if (config == null) { return;/*www .j a va 2 s .c om*/ } Iterator<String> keyIt = config.getKeys(); while (keyIt.hasNext()) { String key = keyIt.next(); if (key == null || key.isEmpty()) { continue; } try { String value = config.getString(key); if (value == null) { continue; } if (overwrDup) { String oldVal = map.put(key, value); if (oldVal != null) { System.out.println("Configuration key \"" + key + "\" has old value \"" + oldVal + "\" has been overwritten by new value \"" + value + "\""); } } else { String oldVal = map.putIfAbsent(key, value); if (oldVal != null) { System.out.println("Configuration key \"" + key + "\" has value \"" + oldVal + "\" NOT be overwrited by new value \"" + value + "\""); } } } catch (Exception ex) { System.err.println(ex); } } }