List of usage examples for java.util.concurrent ConcurrentMap put
V put(K key, V value);
From source file:de.unentscheidbar.validation.internal.Beans.java
public static <T> T propertyValue(Object bean, String propertyName) { try {//from w ww. j a v a2 s .c om ConcurrentMap<String, MethodHandle> methodHandles = CACHE.get(bean.getClass(), new Callable<ConcurrentMap<String, MethodHandle>>() { @Override public ConcurrentMap<String, MethodHandle> call() throws Exception { return new MapMaker().concurrencyLevel(2).makeMap(); } }); /* * We may assume this map only grows and never shrinks. It does not matter if the same * getter is added twice by concurrent invocations of this method. */ MethodHandle getter = methodHandles.get(propertyName); if (getter == null) { getter = getterMethod(bean.getClass(), propertyName); methodHandles.put(propertyName, getter); } assert getter != null; return (T) getter.invoke(bean); } catch (Throwable t) { throw Throwables.propagate(t); } }
From source file:xbird.util.nio.RemoteMemoryMappedFile.java
public static void handleResponse(final ReadRequestMessage request, final ProtocolEncoderOutput out, final ConcurrentMap<String, FileChannel> fdCacheMap) { final String filePath = request.filePath; FileChannel fileChannel = fdCacheMap.get(filePath); if (fileChannel == null) { File file = new File(filePath); if (!file.exists()) { throw new IllegalStateException("file not exists: " + filePath); }/*from w ww .ja va2 s . c o m*/ final RandomAccessFile raf; try { raf = new RandomAccessFile(file, "r"); } catch (FileNotFoundException e) { throw new IllegalStateException(e); } fileChannel = raf.getChannel(); fdCacheMap.put(filePath, fileChannel); } long count = request.endOffset - request.startOffset; long position = request.startOffset; if (LOG.isDebugEnabled()) { LOG.debug("Transfer " + count + " bytes of file '" + filePath + "' from the offset " + position); } FileRegion fileRegion = new DefaultFileRegion(fileChannel, position, count); out.write(fileRegion); }
From source file:com.opengamma.component.ComponentConfigLoader.java
private ConcurrentMap<String, String> adjustProperties(ConcurrentMap<String, String> input) { ConcurrentMap<String, String> map = new ConcurrentHashMap<String, String>(); for (String key : input.keySet()) { map.put("${" + key + "}", input.get(key)); }//from www. ja va2 s . co m return map; }
From source file:org.opendaylight.ovsdb.plugin.NodeDB.java
public void updateRow(String tableName, String uuid, Table<?> row) { ConcurrentMap<String, Table<?>> tableCache = getTableCache(tableName); if (tableCache == null) { tableCache = Maps.newConcurrentMap(); setTableCache(tableName, tableCache); }/* w w w .ja v a 2 s . c o m*/ tableCache.put(uuid, row); }
From source file:com.splout.db.hazelcast.DistributedRegistry.java
public synchronized void register() { String myself = localMember(); log.info("Registering myself [" + myself + "] on registry [" + registryName + "]"); ConcurrentMap<String, Object> members = hzInstance.getMap(registryName); members.put(myself, nodeInfo); amIRegistered.set(true);/* w w w . ja v a 2s .c o m*/ }
From source file:com.splout.db.hazelcast.DistributedRegistry.java
public synchronized void changeInfo(Object nodeInfo) { // Changing memory information. Needed for future reregistration this.nodeInfo = nodeInfo; String myself = localMember(); log.info("Changing my info [" + myself + "] on registry [" + registryName + "]"); ConcurrentMap<String, Object> members = hzInstance.getMap(registryName); members.put(myself, nodeInfo); amIRegistered.set(true);//w w w.j a va 2 s .c o m }
From source file:org.opendaylight.controller.routing.dijkstrav2_implementation.internal.DijkstraImplementation.java
private static boolean updateTopo(Edge edge, Short bw, UpdateType type, ConcurrentMap<Short, Graph<Node, Edge>> topologyBWAware, ConcurrentHashMap<Short, DijkstraShortestPath<Node, Edge>> sptBWAware) { Short baseBW = Short.valueOf((short) 0); Graph<Node, Edge> topo = topologyBWAware.get(baseBW); DijkstraShortestPath<Node, Edge> spt = sptBWAware.get(baseBW); boolean edgePresentInGraph = false; if (topo == null) { // Create topology for this BW Graph<Node, Edge> g = new SparseMultigraph(); topologyBWAware.put(bw, g); topo = topologyBWAware.get(bw);//ww w . j a v a 2 s. com sptBWAware.put(bw, new DijkstraShortestPath(g)); spt = sptBWAware.get(bw); } if (topo != null) { NodeConnector src = edge.getTailNodeConnector(); NodeConnector dst = edge.getHeadNodeConnector(); if (spt == null) { spt = new DijkstraShortestPath(topo); sptBWAware.put(bw, spt); } switch (type) { case ADDED: // Make sure the vertex are there before adding the edge topo.addVertex(src.getNode()); topo.addVertex(dst.getNode()); // Add the link between edgePresentInGraph = topo.containsEdge(edge); if (edgePresentInGraph == false) { try { topo.addEdge(new Edge(src, dst), src.getNode(), dst.getNode(), EdgeType.DIRECTED); } catch (final ConstructionException e) { log.error("", e); return edgePresentInGraph; } } case CHANGED: // Mainly raised only on properties update, so not really useful // in this case break; case REMOVED: // Remove the edge try { topo.removeEdge(new Edge(src, dst)); } catch (final ConstructionException e) { log.error("", e); return edgePresentInGraph; } // If the src and dst vertex don't have incoming or // outgoing links we can get ride of them if (topo.containsVertex(src.getNode()) && (topo.inDegree(src.getNode()) == 0) && (topo.outDegree(src.getNode()) == 0)) { log.debug("Removing vertex {}", src); topo.removeVertex(src.getNode()); } if (topo.containsVertex(dst.getNode()) && (topo.inDegree(dst.getNode()) == 0) && (topo.outDegree(dst.getNode()) == 0)) { log.debug("Removing vertex {}", dst); topo.removeVertex(dst.getNode()); } break; } spt.reset(); if (bw.equals(baseBW)) { //TODO: for now this doesn't work // clearMaxThroughput(); } } else { log.error("Cannot find topology for BW {} this is unexpected!", bw); } return edgePresentInGraph; }
From source file:com.bt.aloha.dao.StateInfoDaoImpl.java
@SuppressWarnings(UNCHECKED) public ConcurrentMap<String, T> getAll(String collectionTypeName) { List<T> all;/* w w w . j av a 2 s. c om*/ Object[] params = new Object[] { collectionTypeName }; try { all = getJdbcTemplate().query(SELECT_ALL_SQL, params, new TRowMapper()); } catch (DataAccessException e) { throw new IllegalArgumentException("Cannot retrieve all info objects from database", e); } ConcurrentMap<String, T> map = new ConcurrentHashMap<String, T>(); for (T item : all) { map.put(item.getId(), item); } return map; }
From source file:org.apache.hadoop.mapreduce.v2.TestRMNMInfo.java
@Test public void testRMNMInfoMissmatch() throws Exception { RMContext rmc = mock(RMContext.class); ResourceScheduler rms = mock(ResourceScheduler.class); ConcurrentMap<NodeId, RMNode> map = new ConcurrentHashMap<NodeId, RMNode>(); RMNode node = MockNodes.newNodeInfo(1, MockNodes.newResource(4 * 1024)); map.put(node.getNodeID(), node); when(rmc.getRMNodes()).thenReturn(map); RMNMInfo rmInfo = new RMNMInfo(rmc, rms); String liveNMs = rmInfo.getLiveNodeManagers(); ObjectMapper mapper = new ObjectMapper(); JsonNode jn = mapper.readTree(liveNMs); Assert.assertEquals("Unexpected number of live nodes:", 1, jn.size()); Iterator<JsonNode> it = jn.iterator(); while (it.hasNext()) { JsonNode n = it.next();// www. j av a2 s.c om Assert.assertNotNull(n.get("HostName")); Assert.assertNotNull(n.get("Rack")); Assert.assertTrue("Node " + n.get("NodeId") + " should be RUNNING", n.get("State").asText().contains("RUNNING")); Assert.assertNotNull(n.get("NodeHTTPAddress")); Assert.assertNotNull(n.get("LastHealthUpdate")); Assert.assertNotNull(n.get("HealthReport")); Assert.assertNotNull(n.get("NodeManagerVersion")); Assert.assertNull(n.get("NumContainers")); Assert.assertNull(n.get("UsedMemoryMB")); Assert.assertNull(n.get("AvailableMemoryMB")); } }
From source file:com.bt.sdk.callcontrol.sip.util.EhCacheCollectionImpl.java
@SuppressWarnings("unchecked") public ConcurrentMap<String, T> getAll() { ConcurrentMap<String, T> result = new ConcurrentHashMap<String, T>(); for (Object key : cache.getKeys()) { result.put((String) key, (T) cache.get(key).getObjectValue()); }//w w w.j av a 2 s . c o m return result; }