List of usage examples for java.util.concurrent ConcurrentHashMap put
public V put(K key, V value)
From source file:com.yj.smarthome.activity.control.MainControlActivity.java
/** * ??//from www .j a v a 2 s . com * * @param map * the map * @param json * the json * @throws JSONException * the JSON exception */ private void inputDataToMaps(ConcurrentHashMap<String, Object> map, String json) throws JSONException { Log.i("Apptest", json); JSONObject receive = new JSONObject(json); Iterator actions = receive.keys(); while (actions.hasNext()) { String action = actions.next().toString(); Log.i("revjson", "action=" + action); // if (action.equals("cmd") || action.equals("qos") || action.equals("seq") || action.equals("version")) { continue; } JSONObject params = receive.getJSONObject(action); Log.i("revjson", "params=" + params); Iterator it_params = params.keys(); while (it_params.hasNext()) { String param = it_params.next().toString(); Object value = params.get(param); map.put(param, value); Log.i(TAG, "Key:" + param + ";value" + value); } } //handler.sendEmptyMessage(handler_key.UPDATE_UI.ordinal()); }
From source file:org.getobjects.ofs.OFSFolder.java
public OFSFileContainerChildInfo childInfo() { final IOFSFileInfo info = this.fileInfo(); if (info == null) return null; final long currentTimestamp = info.lastModified(); // need to rebuild caches? if (this.childInfo != null && currentTimestamp != this.lastModified) this.childInfo = null; if (this.childInfo == null) { final ConcurrentHashMap<IOFSFileInfo, Object> pathToChildInfo = this.fileManager .cacheForSection("OFSFolderChildInfo"); /* check cache */ this.childInfo = (OFSFileContainerChildInfo) pathToChildInfo.get(info); if (this.childInfo != null) { // Hm, this does not seem to speedup the operation, even though we get // a good hitrate? Maybe the kernel cache is sufficient or the File // does some caching? if (currentTimestamp != this.childInfo.timestamp()) { // no gain in removing the old info? Will be overridden below this.childInfo = null; }/*from w ww.j av a 2s . c om*/ } /* fetch item if cache was empty or item got changed */ if (this.childInfo == null) { this.childInfo = OFSFileContainerChildInfo.infoForFile(this.fileManager(), this.fileInfo()); if (this.childInfo != null) { this.childInfo.load(); /* ensure a threadsafe state */ pathToChildInfo.put(info, this.childInfo); } } } return this.childInfo; }
From source file:org.apache.nifi.lookup.CSVRecordLookupService.java
private void loadCache() throws IllegalStateException, IOException { if (lock.tryLock()) { try {//from ww w . j a v a 2 s. c o m final ComponentLog logger = getLogger(); if (logger.isDebugEnabled()) { logger.debug("Loading lookup table from file: " + csvFile); } final FileReader reader = new FileReader(csvFile); final CSVParser records = csvFormat.withFirstRecordAsHeader().parse(reader); ConcurrentHashMap<String, Record> cache = new ConcurrentHashMap<>(); RecordSchema lookupRecordSchema = null; for (final CSVRecord record : records) { final String key = record.get(lookupKeyColumn); if (StringUtils.isBlank(key)) { throw new IllegalStateException("Empty lookup key encountered in: " + csvFile); } else if (!ignoreDuplicates && cache.containsKey(key)) { throw new IllegalStateException( "Duplicate lookup key encountered: " + key + " in " + csvFile); } else if (ignoreDuplicates && cache.containsKey(key)) { logger.warn("Duplicate lookup key encountered: {} in {}", new Object[] { key, csvFile }); } // Put each key/value pair (except the lookup) into the properties final Map<String, Object> properties = new HashMap<>(); record.toMap().forEach((k, v) -> { if (!lookupKeyColumn.equals(k)) { properties.put(k, v); } }); if (lookupRecordSchema == null) { List<RecordField> recordFields = new ArrayList<>(properties.size()); properties.forEach((k, v) -> recordFields .add(new RecordField(k, RecordFieldType.STRING.getDataType()))); lookupRecordSchema = new SimpleRecordSchema(recordFields); } cache.put(key, new MapRecord(lookupRecordSchema, properties)); } this.cache = cache; if (cache.isEmpty()) { logger.warn("Lookup table is empty after reading file: " + csvFile); } } finally { lock.unlock(); } } }
From source file:uk.co.tfd.symplectic.harvester.SymplecticFetch.java
/** * Executes the task//from ww w . j a v a2 s . 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:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java
private JTable createTable(final ViewState state) { JTable table;/* w w w .ja va2 s . c o m*/ final ModelGraph selected = state.getSelected(); if (selected != null) { final Vector<Vector<String>> rows = new Vector<Vector<String>>(); ConcurrentHashMap<String, String> keyToGroupMap = new ConcurrentHashMap<String, String>(); Metadata staticMet = selected.getModel().getStaticMetadata(); Metadata inheritedMet = selected.getInheritedStaticMetadata(state); Metadata completeMet = new Metadata(); if (staticMet != null) { completeMet.replaceMetadata(staticMet.getSubMetadata(state.getCurrentMetGroup())); } if (selected.getModel().getExtendsConfig() != null) { for (String configGroup : selected.getModel().getExtendsConfig()) { Metadata extendsMetadata = state.getGlobalConfigGroups().get(configGroup).getMetadata() .getSubMetadata(state.getCurrentMetGroup()); for (String key : extendsMetadata.getAllKeys()) { if (!completeMet.containsKey(key)) { keyToGroupMap.put(key, configGroup); completeMet.replaceMetadata(key, extendsMetadata.getAllMetadata(key)); } } } } if (inheritedMet != null) { Metadata inheritedMetadata = inheritedMet.getSubMetadata(state.getCurrentMetGroup()); for (String key : inheritedMetadata.getAllKeys()) { if (!completeMet.containsKey(key)) { keyToGroupMap.put(key, "__inherited__"); completeMet.replaceMetadata(key, inheritedMetadata.getAllMetadata(key)); } } } List<String> keys = completeMet.getAllKeys(); Collections.sort(keys); for (String key : keys) { if (key.endsWith("/envReplace")) { continue; } String values = StringUtils.join(completeMet.getAllMetadata(key), ","); Vector<String> row = new Vector<String>(); row.add(keyToGroupMap.get(key)); row.add(key); row.add(values); row.add(Boolean.toString(Boolean.parseBoolean(completeMet.getMetadata(key + "/envReplace")))); rows.add(row); } table = new JTable();// rows, new Vector<String>(Arrays.asList(new // String[] { "key", "values", "envReplace" }))); table.setModel(new AbstractTableModel() { public String getColumnName(int col) { switch (col) { case 0: return "group"; case 1: return "key"; case 2: return "values"; case 3: return "envReplace"; default: return null; } } public int getRowCount() { return rows.size() + 1; } public int getColumnCount() { return 4; } public Object getValueAt(int row, int col) { if (row >= rows.size()) { return null; } String value = rows.get(row).get(col); if (value == null && col == 3) { return "false"; } if (value == null && col == 0) { return "__local__"; } return value; } public boolean isCellEditable(int row, int col) { if (row >= rows.size()) { return selected.getModel().getStaticMetadata().containsGroup(state.getCurrentMetGroup()); } if (col == 0) { return false; } String key = rows.get(row).get(1); return key == null || (selected.getModel().getStaticMetadata() != null && selected.getModel().getStaticMetadata().containsKey(getKey(key, state))); } public void setValueAt(Object value, int row, int col) { if (row >= rows.size()) { Vector<String> newRow = new Vector<String>( Arrays.asList(new String[] { null, null, null, null })); newRow.add(col, (String) value); rows.add(newRow); } else { Vector<String> rowValues = rows.get(row); rowValues.add(col, (String) value); rowValues.remove(col + 1); } this.fireTableCellUpdated(row, col); } }); MyTableListener tableListener = new MyTableListener(state); table.getModel().addTableModelListener(tableListener); table.getSelectionModel().addListSelectionListener(tableListener); } else { table = new JTable(new Vector<Vector<String>>(), new Vector<String>(Arrays.asList(new String[] { "key", "values", "envReplace" }))); } // table.setFillsViewportHeight(true); table.setSelectionBackground(Color.cyan); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableCellRenderer cellRenderer = new TableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel field = new JLabel((String) value); if (column == 0) { field.setForeground(Color.gray); } else { if (isSelected) { field.setBorder(new EtchedBorder(1)); } if (table.isCellEditable(row, 1)) { field.setForeground(Color.black); } else { field.setForeground(Color.gray); } } return field; } }; TableColumn groupCol = table.getColumnModel().getColumn(0); groupCol.setPreferredWidth(75); groupCol.setCellRenderer(cellRenderer); TableColumn keyCol = table.getColumnModel().getColumn(1); keyCol.setPreferredWidth(200); keyCol.setCellRenderer(cellRenderer); TableColumn valuesCol = table.getColumnModel().getColumn(2); valuesCol.setPreferredWidth(300); valuesCol.setCellRenderer(cellRenderer); TableColumn envReplaceCol = table.getColumnModel().getColumn(3); envReplaceCol.setPreferredWidth(75); envReplaceCol.setCellRenderer(cellRenderer); table.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3 && DefaultPropView.this.table.getSelectedRow() != -1) { int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition()); String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state); Metadata staticMet = state.getSelected().getModel().getStaticMetadata(); override.setVisible(staticMet == null || !staticMet.containsKey(key)); delete.setVisible(staticMet != null && staticMet.containsKey(key)); tableMenu.show(DefaultPropView.this.table, e.getX(), e.getY()); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); return table; }
From source file:org.apache.impala.catalog.CatalogServiceCatalog.java
/** * Resets this catalog instance by clearing all cached table and database metadata. *///w w w. j a va2 s . c om public void reset() throws CatalogException { LOG.info("Invalidating all metadata."); // First update the policy metadata. if (sentryProxy_ != null) { // Sentry Service is enabled. try { // Update the authorization policy, waiting for the result to complete. sentryProxy_.refresh(); } catch (Exception e) { throw new CatalogException("Error updating authorization policy: ", e); } } catalogLock_.writeLock().lock(); try { // Not all Java UDFs are persisted to the metastore. The ones which aren't // should be restored once the catalog has been invalidated. Map<String, Db> oldDbCache = dbCache_.get(); // Build a new DB cache, populate it, and replace the existing cache in one // step. ConcurrentHashMap<String, Db> newDbCache = new ConcurrentHashMap<String, Db>(); List<TTableName> tblsToBackgroundLoad = Lists.newArrayList(); try (MetaStoreClient msClient = getMetaStoreClient()) { for (String dbName : msClient.getHiveClient().getAllDatabases()) { dbName = dbName.toLowerCase(); Db oldDb = oldDbCache.get(dbName); Pair<Db, List<TTableName>> invalidatedDb = invalidateDb(msClient, dbName, oldDb); if (invalidatedDb == null) continue; newDbCache.put(dbName, invalidatedDb.first); tblsToBackgroundLoad.addAll(invalidatedDb.second); } } dbCache_.set(newDbCache); // Submit tables for background loading. for (TTableName tblName : tblsToBackgroundLoad) { tableLoadingMgr_.backgroundLoad(tblName); } } catch (Exception e) { LOG.error(e); throw new CatalogException("Error initializing Catalog. Catalog may be empty.", e); } finally { catalogLock_.writeLock().unlock(); } LOG.info("Invalidated all metadata."); }
From source file:org.apache.oodt.cas.workflow.gui.model.repo.XmlWorkflowModelRepository.java
private void loadConfiguration(List<FileBasedElement> rootElements, FileBasedElement workflowNode, ModelNode modelNode, ConcurrentHashMap<String, ConfigGroup> globalConfGroups) { NodeList children = workflowNode.getElement().getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node curChild = children.item(i); if (curChild.getNodeName().equals("configuration")) { Metadata curMetadata = new Metadata(); if (modelNode != null && !((Element) curChild).getAttribute("extends").equals("")) { modelNode.setExtendsConfig( Arrays.asList(((Element) curChild).getAttribute("extends").split(","))); }// w w w.ja va2 s.co m curMetadata.replaceMetadata(this.loadConfiguration(rootElements, curChild, globalConfGroups)); if (!((Element) curChild).getAttribute("name").equals("")) { ConfigGroup configGroup = new ConfigGroup(((Element) curChild).getAttribute("name"), curMetadata); if (modelNode != null) { List<String> extendsConfig = new Vector<String>(modelNode.getExtendsConfig()); configGroup.addAllExtends(extendsConfig); extendsConfig.add(configGroup.getName()); modelNode.setExtendsConfig(extendsConfig); } globalConfGroups.put(((Element) curChild).getAttribute("name"), configGroup); } else if (modelNode != null) { modelNode.setStaticMetadata(curMetadata); } } } }
From source file:org.apache.hadoop.yarn.server.resourcemanager.TestClientRMService.java
private ConcurrentHashMap<ApplicationId, RMApp> getRMApps(RMContext rmContext, YarnScheduler yarnScheduler) throws IOException { ConcurrentHashMap<ApplicationId, RMApp> apps = new ConcurrentHashMap<ApplicationId, RMApp>(); ApplicationId applicationId1 = getApplicationId(1); ApplicationId applicationId2 = getApplicationId(2); ApplicationId applicationId3 = getApplicationId(3); YarnConfiguration config = new YarnConfiguration(); apps.put(applicationId1, getRMApp(rmContext, yarnScheduler, applicationId1, config, "testqueue", 10, 3, 3, null, null)); apps.put(applicationId2,//from www.j av a 2 s. com getRMApp(rmContext, yarnScheduler, applicationId2, config, "a", 20, 2, 2, null, "")); apps.put(applicationId3, getRMApp(rmContext, yarnScheduler, applicationId3, config, "testqueue", 40, 5, 5, "high-mem", "high-mem")); return apps; }
From source file:fastcall.FastCallSNP.java
private ConcurrentHashMap<String, List<List<String>>> getBamPileupResultMap(int currentChr, int binStart, int binEnd, HashMap<String, BufferedReader> bamPathPileupReaderMap, ConcurrentHashMap<BufferedReader, List<String>> readerRemainderMap) { ArrayList<String> empty = new ArrayList(); ConcurrentHashMap<String, List<List<String>>> bamPileupMap = new ConcurrentHashMap(2048); List<String> bamList = Arrays.asList(bamPaths); bamList.parallelStream().forEach(bamFileS -> { ArrayList<List<String>> lineList = new ArrayList(); BufferedReader br = bamPathPileupReaderMap.get(bamFileS); List<String> remainder = readerRemainderMap.get(br); boolean flag = false; if (remainder.size() == 0) { String temp = null;/* w w w. java 2 s.c om*/ try { temp = br.readLine(); } catch (Exception e) { } if (temp != null) { List<String> split = FStringUtils.fastSplit(temp, "\t"); int currentPos = Integer.valueOf(split.get(1)); if (currentPos > binEnd) { readerRemainderMap.put(br, split); } else { lineList.add(split); flag = true; } } } else { int currentPos = Integer.valueOf(remainder.get(1)); if (currentPos <= binEnd) { lineList.add(remainder); flag = true; readerRemainderMap.put(br, empty); } } if (flag == true) { try { String temp; while ((temp = br.readLine()) != null) { List<String> split = FStringUtils.fastSplit(temp, "\t"); int currentPos = Integer.valueOf(split.get(1)); if (currentPos < binEnd) { lineList.add(split); } else if (currentPos == binEnd) { lineList.add(split); readerRemainderMap.put(br, empty); break; } else { readerRemainderMap.put(br, split); break; } } } catch (Exception e) { e.printStackTrace(); } } bamPileupMap.put(bamFileS, lineList); }); return bamPileupMap; }
From source file:edu.berkeley.compbio.phyloutils.HugenholtzTaxonomyService.java
private synchronized void reloadNameToProkMSAidMap(HashMultimap<String, Integer> nameToIdsMap) { if (nameToProkMSAidFilename != null) { Map<String, Set<Integer>> nameToProkMSAidMap; try {//from w w w.j av a2 s.c om ConcurrentHashMap<String, Integer> nameToUniqueIdMap = new ConcurrentHashMap<String, Integer>(); nameToProkMSAidMap = StringSetIntMapReader.read(nameToProkMSAidFilename); for (Map.Entry<String, Set<Integer>> entry : nameToProkMSAidMap.entrySet()) { String key = entry.getKey(); Set<Integer> valueSet = entry.getValue(); logger.info("Loaded mapping: " + key + " -> " + DSStringUtils.join(valueSet, ", ")); nameToIdsMap.removeAll(key); nameToUniqueIdMap.remove(key); nameToIdsMap.putAll(key, valueSet); for (Integer id : valueSet) { nameToUniqueIdMap.put(key, id); } } nameToUniqueIdMapStub.put(nameToUniqueIdMap); } catch (IOException e) { throw new Error(e); } } }