List of usage examples for java.util.concurrent ConcurrentHashMap size
public int size()
From source file:Main.java
public static <T> List<T> getListFromConcHashMap(ConcurrentHashMap<Integer, T> map) { List<T> values = new ArrayList<T>(); for (int i = 0; i < map.size(); i++) { values.add(map.get(i));/*from www . j av a 2 s .co m*/ } return values; }
From source file:com.clustercontrol.repository.factory.NodeProperty.java
public static void init() { JpaTransactionManager jtm = null;/*from ww w . java 2 s .c o m*/ try { _lock.writeLock(); long startTime = System.currentTimeMillis(); jtm = new JpaTransactionManager(); jtm.getEntityManager().clear(); ConcurrentHashMap<String, NodeInfo> cache = new ConcurrentHashMap<String, NodeInfo>(); for (NodeInfo node : QueryUtil.getAllNode_NONE()) { cache.put(node.getFacilityId(), node); } storeCache(cache); m_log.info("init cache " + (System.currentTimeMillis() - startTime) + "ms. size=" + cache.size()); } finally { if (jtm != null) { jtm.close(); } _lock.writeUnlock(); } }
From source file:com.steffi.index.ImgMapIndex.java
@Override public long count(String key, Object value) { ConcurrentHashMap<Object, Boolean> curValues = getMap().get(new IndexKeyValue(key, value)); if (curValues != null) return curValues.size(); return 0;/* w ww . j a v a 2 s .c om*/ }
From source file:org.apache.hadoop.hdfs.TestReadSlowDataNode.java
/** * Test that copy on write for blocks works correctly * // w w w. j a v a 2s. c o m * @throws NoSuchFieldException * @throws SecurityException * @throws IllegalAccessException * @throws IllegalArgumentException */ public void testSlowDn() throws IOException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Configuration conf = new Configuration(); conf.setLong("dfs.bytes.to.check.read.speed", 128 * 1024); conf.setLong("dfs.min.read.speed.bps", 1024 * 200); conf.setBoolean("dfs.read.switch.for.slow", true); MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null); FileSystem fs = cluster.getFileSystem(); FSDataInputStream in = null; try { // create a new file, write to it and close it. // Path file1 = new Path("/filestatus.dat"); FSDataOutputStream stm = createFile(fs, file1, 2); writeFile(stm); stm.close(); in = fs.open(file1); in.readByte(); DFSInputStream dfsClientIn = findDFSClientInputStream(in); Field blockReaderField = DFSInputStream.class.getDeclaredField("blockReader"); blockReaderField.setAccessible(true); BlockReader blockReader = (BlockReader) blockReaderField.get(dfsClientIn); blockReader.setArtificialSlowdown(1000); blockReader.isReadLocal = false; blockReader.isReadRackLocal = false; for (int i = 0; i < 1024; i++) { in.readByte(); } blockReader.setArtificialSlowdown(0); for (int i = 1024; i < fileSize - 1; i++) { in.readByte(); } ConcurrentHashMap<DatanodeInfo, DatanodeInfo> deadNodes = getDeadNodes(dfsClientIn); TestCase.assertEquals(1, deadNodes.size()); } finally { if (in != null) { in.close(); } fs.close(); cluster.shutdown(); } }
From source file:com.steffi.index.ImgMapIndex.java
@Override public ImgIndexHits<T> get(String key, Object value) { IndexKeyValue indexKeyValue = new IndexKeyValue(key, value); ConcurrentHashMap<Object, Boolean> idElements = getMap().get(indexKeyValue); if (idElements == null || idElements.isEmpty()) return new ImgMapIndexHits<T>(IteratorUtils.emptyIterator(), 0, indexClass); else//from ww w. ja v a2s . c om return new ImgMapIndexHits<T>(idElements.keySet().iterator(), idElements.size(), indexClass); }
From source file:org.wso2.carbon.event.input.adaptor.soap.SoapEventAdaptorType.java
@Override public String subscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration, InputEventAdaptorListener inputEventAdaptorListener, InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration) { String subscriptionId = UUID.randomUUID().toString(); String operation = inputEventAdaptorMessageConfiguration.getInputMessageProperties() .get(SoapEventAdaptorConstants.ADAPTOR_MESSAGE_OPERATION_NAME); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); Map<String, ConcurrentHashMap<String, ConcurrentHashMap<String, SoapAdaptorListener>>> tenantSpecificListenerMap = inputEventAdaptorListenerMap .get(tenantId);//from w ww . j a v a2 s . co m if (tenantSpecificListenerMap == null) { tenantSpecificListenerMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, SoapAdaptorListener>>>(); inputEventAdaptorListenerMap.put(tenantId, tenantSpecificListenerMap); } ConcurrentHashMap<String, ConcurrentHashMap<String, SoapAdaptorListener>> adaptorSpecificListeners = tenantSpecificListenerMap .get(inputEventAdaptorConfiguration.getName()); if (adaptorSpecificListeners == null) { adaptorSpecificListeners = new ConcurrentHashMap<String, ConcurrentHashMap<String, SoapAdaptorListener>>(); if (null != tenantSpecificListenerMap.put(inputEventAdaptorConfiguration.getName(), adaptorSpecificListeners)) { adaptorSpecificListeners = tenantSpecificListenerMap.get(inputEventAdaptorConfiguration.getName()); } } AxisService axisService = null; ConcurrentHashMap<String, SoapAdaptorListener> operationSpecificListeners = adaptorSpecificListeners .get(operation); if (operationSpecificListeners == null || operationSpecificListeners.size() == 0) { try { axisService = Axis2Util.registerAxis2Service(inputEventAdaptorMessageConfiguration, inputEventAdaptorConfiguration, axisConfiguration); } catch (AxisFault axisFault) { throw new InputEventAdaptorEventProcessingException( "Can not create " + "the axis2 service to receive events", axisFault); } operationSpecificListeners = new ConcurrentHashMap<String, SoapAdaptorListener>(); if (null != adaptorSpecificListeners.put(operation, operationSpecificListeners)) { operationSpecificListeners = adaptorSpecificListeners.get(operation); } } if (axisService == null) { String axisServiceName = inputEventAdaptorConfiguration.getName(); try { axisService = axisConfiguration.getService(axisServiceName); } catch (AxisFault axisFault) { throw new InputEventAdaptorEventProcessingException( "There is no service with the name ==> " + axisServiceName, axisFault); } } String operationNameWithoutSlash = inputEventAdaptorMessageConfiguration.getInputMessageProperties() .get(SoapEventAdaptorConstants.ADAPTOR_MESSAGE_OPERATION_NAME).replaceAll("/", ""); AxisOperation axisOperation = axisService.getOperation(new QName("", operationNameWithoutSlash)); SubscriptionMessageReceiver messageReceiver = (SubscriptionMessageReceiver) axisOperation .getMessageReceiver(); messageReceiver.addEventAdaptorListener(subscriptionId, inputEventAdaptorListener); operationSpecificListeners.put(subscriptionId, new SoapAdaptorListener(subscriptionId, inputEventAdaptorListener)); return subscriptionId; }
From source file:org.deviceconnect.android.deviceplugin.hvcc2w.setting.fragment.HVCC2WRegisterFaceRecognitionDataFragment.java
/** * Initial List View.//from w ww .j a v a2 s . c o m */ private void initListView() { HVCManager.INSTANCE.getCameraList(new HVCManager.ResponseListener() { @Override public void onReceived(String json) { ConcurrentHashMap<String, HVCCameraInfo> camera = HVCManager.INSTANCE.getHVCDevices(); if (camera.size() == 0) { return; } String[] names = new String[camera.size()]; int i = 0; for (String key : camera.keySet()) { names[i] = key; i++; } final String[] serviceIds = names; final int[] pos = new int[1]; if (mServiceId == null) { HVCC2WDialogFragment.showSelectDialog(getActivity(), getString(R.string.select_dialog_message), serviceIds, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { pos[0] = i; } }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { mServiceId = serviceIds[pos[0]]; mRegister.setVisibility(View.VISIBLE); mUnregister.setVisibility(View.VISIBLE); List<FaceRecognitionObject> objects = HVCStorage.INSTANCE .getFaceRecognitionDatasForDeviceId(mServiceId); for (FaceRecognitionObject object : objects) { mAdapter.add(object.getName()); } mListView.setAdapter(mAdapter); } }, null); } else { List<FaceRecognitionObject> objects = HVCStorage.INSTANCE .getFaceRecognitionDatasForDeviceId(mServiceId); for (FaceRecognitionObject object : objects) { mAdapter.add(object.getName()); } mListView.setAdapter(mAdapter); } mAdapter.notifyDataSetChanged(); } }); mAdapter.clear(); }
From source file:de.hybris.platform.cache.CachePerformanceTest.java
@Test public void testConcurrentHashMap() { final ConcurrentHashMap<String, Object> chMap = new ConcurrentHashMap<String, Object>(FILL * 2, 0.75f, 8); fillCacheMap(chMap, FILL);//w ww . j av a 2 s. c om assertEquals(FILL, chMap.size()); writeResultTable("ConcurrentHashMap", 100, FILL, TOTALHITS, THREADS, executeMultithreadedCacheAccess(chMap, FILL, true, THREADS, TOTALHITS, MAX_WAIT_SECONDS)); writeResultTable("ConcurrentHashMap", 0, FILL, TOTALHITS, THREADS, executeMultithreadedCacheAccess(chMap, FILL, false, THREADS, TOTALHITS, MAX_WAIT_SECONDS)); }
From source file:uk.co.tfd.symplectic.harvester.SymplecticFetch.java
/** * Executes the task/* w w w .ja va2s .c om*/ * * @param baseUrl * * @throws UnsupportedEncodingException * * @throws IOException * error processing search * @throws TransformerException * @throws TransformerFactoryConfigurationError * @throws ParserConfigurationException * @throws SAXException * @throws DOMException * @throws NoSuchAlgorithmException * @throws AtomEntryLoadException */ private void execute() throws DOMException, NoSuchAlgorithmException, UnsupportedEncodingException, IOException, SAXException, ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException { ProgressTracker progress = null; try { progress = new JDBCProgressTrackerImpl(rh, limitListPages, updateLists, objectTypes, excludedRelationshipObjectTypes); } catch (SQLException e) { LOGGER.info(e.getMessage(), e); progress = new FileProgressTrackerImpl("loadstate", rh, limitListPages, updateLists, objectTypes, excludedRelationshipObjectTypes); } catch (IOException e) { LOGGER.info(e.getMessage(), e); progress = new FileProgressTrackerImpl("loadstate", rh, limitListPages, updateLists, objectTypes, excludedRelationshipObjectTypes); } // re-scan relationships to extract API objects // reScanRelationships(progress); // baseUrl + "/objects?categories=users&groups=3" progress.toload(seedQueryUrl, new APIObjects(rh, "users", progress, limitListPages, objectTypes)); // progress.toload(baseUrl+"publication", new APIObjects(rh, // "publications", progress)); int i = 0; int threadPoolSize = 20; ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize); final ConcurrentHashMap<String, FutureTask<String>> worklist = new ConcurrentHashMap<String, FutureTask<String>>(); while (i < maxUrlFetch) { Entry<String, AtomEntryLoader> next = progress.next(); if (next == null) { int startingWorklistSize = worklist.size(); while (worklist.size() > 0 && worklist.size() >= startingWorklistSize) { consumeTasks(worklist, progress); if (worklist.size() >= startingWorklistSize) { try { Thread.sleep(500); } catch (InterruptedException e) { } } } if (!progress.hasPending() && worklist.size() == 0) { break; // there are none left to come, the workers are empty, and so is pending } } else { final AtomEntryLoader loader = next.getValue(); final String key = next.getKey(); FutureTask<String> task = new FutureTask<String>(new Callable<String>() { @Override public String call() throws Exception { try { loader.loadEntry(key); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return "Done Loading " + key; } }); worklist.put(key, task); executorService.execute(task); i++; // dont overfill the queue while (worklist.size() > threadPoolSize * 2) { consumeTasks(worklist, progress); if (worklist.size() > threadPoolSize) { try { Thread.sleep(500); } catch (InterruptedException e) { } } } } } while (worklist.size() > 0) { consumeTasks(worklist, progress); Thread.yield(); } executorService.shutdown(); LOGGER.info("End ToDo list contains {} urls ", progress.pending()); progress.dumpLoaded(); progress.checkpoint(); }
From source file:com.athena.sqs.MessageAggregator.java
/** * Aggregate splitted messages into single message. * @param rawData base64 string/*from www. j a v a2 s.c o m*/ * @throws MessageException */ public void aggregate(String rawString) throws MessageException { try { BASE64Decoder decoder = new BASE64Decoder(); int index = rawString.indexOf(MessageContext.DATA_DELIMITER); // 1. Split header String[] header = parseHeader(rawString.substring(0, index)); String content = rawString.substring(index + 2); // 2. Assign header value to local variable MessageTransferType transferType = MessageTransferType.valueOf(header[0]); String businessName = header[1]; String transactionId = header[2]; MessageSplitType splitType = MessageSplitType.valueOf(header[3]); int current = Integer.parseInt(header[4]); int total = Integer.parseInt(header[5]); // 3 Check Message Single switch (splitType) { case SINGLE: // TODO single message work doProcess(transactionId, new String(decoder.decodeBuffer(content))); return; case MULTI: break; } logger.debug("Transaction ID : " + transactionId); // 4. Check Message Order // If transaction id is not exist in txMap, create new tx map object if (!txMap.containsKey(transactionId)) { ConcurrentHashMap<Integer, String> orderedMessages = new ConcurrentHashMap<Integer, String>(); orderedMessages.put(current, content); txMap.put(transactionId, orderedMessages); } else { // Already same transaction message was inserted ConcurrentHashMap<Integer, String> orderedMessages = txMap.get(transactionId); orderedMessages.put(current, content); // Message compare if (orderedMessages.size() == total) { // All messages arrived Object[] key = orderedMessages.keySet().toArray(); Arrays.sort(key); String finalMessage = ""; for (int i = 0; i < key.length; i++) { finalMessage += orderedMessages.get(key[i]); } logger.debug("===== [ " + transactionId + "] ======"); logger.debug(new String(decoder.decodeBuffer(finalMessage))); boolean isDelete = txMap.remove(transactionId, orderedMessages); if (!isDelete) { throw new MessageException("Can't delete message from transaction map"); } doProcess(transactionId, new String(decoder.decodeBuffer(finalMessage))); } } } catch (Exception e) { e.printStackTrace(); } }