List of usage examples for java.util.concurrent ConcurrentHashMap get
public V get(Object key)
From source file:com.redhat.red.offliner.ftest.SinglePlaintextDownloadOfTarballFTest.java
/** * In general, we should only have one test method per functional test. This allows for the best parallelism when we * execute the tests, especially if the setup takes some time. * * @throws Exception In case anything (anything at all) goes wrong! *//*ww w . j av a2 s .com*/ @Test public void run() throws Exception { // Generate some test content String path = contentGenerator.newArtifactPath("tar.gz"); Map<String, byte[]> entries = new HashMap<>(); entries.put(contentGenerator.newArtifactPath("jar"), contentGenerator.newBinaryContent(2400)); entries.put(contentGenerator.newArtifactPath("jar"), contentGenerator.newBinaryContent(2400)); final File tgz = makeTarball(entries); System.out.println("tar content array has length: " + tgz.length()); // We only need one repo server. ExpectationServer server = new ExpectationServer(); server.start(); // Register the generated content by writing it to the path within the repo server's dir structure. // This way when the path is requested it can be downloaded instead of returning a 404. server.expect("GET", server.formatUrl(path), (req, resp) -> { // Content-Length: 47175 // Content-Type: application/x-gzip resp.setHeader("Content-Encoding", "gzip"); resp.setHeader("Content-Type", "application/x-gzip"); byte[] raw = FileUtils.readFileToByteArray(tgz); ByteArrayOutputStream baos = new ByteArrayOutputStream(); GzipCompressorOutputStream gzout = new GzipCompressorOutputStream(baos); gzout.write(raw); gzout.finish(); byte[] content = baos.toByteArray(); resp.setHeader("Content-Length", Long.toString(content.length)); OutputStream respStream = resp.getOutputStream(); respStream.write(content); respStream.flush(); System.out.println("Wrote content with length: " + content.length); }); byte[] content = FileUtils.readFileToByteArray(tgz); server.expect("GET", server.formatUrl(path + Main.SHA_SUFFIX), 200, sha1Hex(content)); server.expect("GET", server.formatUrl(path + Main.MD5_SUFFIX), 200, md5Hex(content)); // Write the plaintext file we'll use as input. File plaintextList = temporaryFolder.newFile("artifact-list." + getClass().getSimpleName() + ".txt"); String pathWithChecksum = contentGenerator.newPlaintextEntryWithChecksum(path, content); FileUtils.write(plaintextList, pathWithChecksum); Options opts = new Options(); opts.setBaseUrls(Collections.singletonList(server.getBaseUri())); // Capture the downloads here so we can verify the content. File downloads = temporaryFolder.newFolder(); opts.setDownloads(downloads); opts.setLocations(Collections.singletonList(plaintextList.getAbsolutePath())); opts.setConnections(1); // run `new Main(opts).run()` and return the Main instance so we can query it for errors, etc. Main finishedMain = run(opts); ConcurrentHashMap<String, Throwable> errors = finishedMain.getErrors(); System.out.printf("ERRORS:\n\n%s\n\n\n", StringUtils.join(errors.keySet().stream() .map(k -> "ERROR: " + k + ": " + errors.get(k).getMessage() + "\n " + StringUtils.join(errors.get(k).getStackTrace(), "\n ")) .collect(Collectors.toList()), "\n\n")); File downloaded = new File(downloads, path); assertThat("File: " + path + " doesn't seem to have been downloaded!", downloaded.exists(), equalTo(true)); // assertThat( "Downloaded file: " + path + " contains the wrong content!", // FileUtils.readFileToByteArray( downloaded ), equalTo( content ) ); File tarball = new File(downloads, path); System.out.println("Length of downloaded file: " + tarball.length()); File tmp = new File("/tmp/download.tar.gz"); File tmp2 = new File("/tmp/content.tar.gz"); FileUtils.writeByteArrayToFile(tmp2, content); FileUtils.copyFile(tarball, tmp); try (TarArchiveInputStream tarIn = new TarArchiveInputStream( new GzipCompressorInputStream(new FileInputStream(tarball)))) { TarArchiveEntry entry = null; while ((entry = tarIn.getNextTarEntry()) != null) { byte[] entryData = new byte[(int) entry.getSize()]; int read = tarIn.read(entryData, 0, entryData.length); assertThat("Not enough bytes read for: " + entry.getName(), read, equalTo((int) entry.getSize())); assertThat(entry.getName() + ": data doesn't match input", Arrays.equals(entries.get(entry.getName()), entryData), equalTo(true)); } } assertThat("Wrong number of downloads logged. Should have been 3 including checksums.", finishedMain.getDownloaded(), equalTo(3)); assertThat("Errors should be empty!", errors.isEmpty(), equalTo(true)); }
From source file:ru.runa.wfe.user.cache.ExecutorCacheImpl.java
@Override public <T extends Executor> VersionedCacheData<List<T>> getAllExecutor(Class<T> clazz, BatchPresentation batch) {// ww w.ja va 2s. c o m synchronized (this) { ConcurrentHashMap<BatchPresentationFieldEquals, List<Executor>> map = batchAllExecutors.get(clazz); if (map == null) { return getVersionnedData(null); } List<Executor> cachedExecutors = map.get(new BatchPresentationFieldEquals(batch)); if (cachedExecutors == null) { return getVersionnedData(null); } return getVersionnedData((List<T>) Collections.unmodifiableList(cachedExecutors)); } }
From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java
/** * //from ww w . ja va2 s.c o m * @param rowKey * @param columnKey * @param timesplice * ?:201572701 * @param value * @return */ public boolean put(final String rowKey, final String columnKey, final String timesplice, final T value) { Preconditions.checkState(StringUtils.isNotBlank(rowKey), "rowKey is blank"); Preconditions.checkState(StringUtils.isNotBlank(columnKey), "columnKey is blank"); Preconditions.checkState(StringUtils.isNotBlank(timesplice), "timesplice is blank"); Preconditions.checkNotNull(value, "value is null"); ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>> row = table.get(rowKey); if (row == null) { table.putIfAbsent(rowKey, new ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>>()); } row = table.get(rowKey); ConcurrentSkipListMap<String, ConcurrentSet<T>> column = row.get(columnKey); if (column == null) { row.putIfAbsent(columnKey, new ConcurrentSkipListMap<String, ConcurrentSet<T>>()); } column = row.get(columnKey); ConcurrentSet<T> values = column.get(timesplice); if (values == null) { column.putIfAbsent(timesplice, new ConcurrentSet<>()); } values = column.get(timesplice); return values.add(value); }
From source file:org.objectweb.proactive.extensions.dataspaces.vfs.VFSSpacesMountManagerImpl.java
/** * Internal method for resolving a file, will mount the file system if it is not mounted yet * @param uri virtual uri of the file/* ww w . j ava2 s . com*/ * @param ownerActiveObjectId Id of active object requesting this file * @param spaceRootFOUri root file system to use * @return * @throws FileSystemException */ private DataSpacesFileObject doResolveFile(final DataSpacesURI uri, final String ownerActiveObjectId, String spaceRootFOUri) throws FileSystemException { DataSpacesURI spacePart = uri.getSpacePartOnly(); if (spaceRootFOUri != null) { ensureFileSystemIsMounted(spacePart, spaceRootFOUri); } else { try { readLock.lock(); LinkedHashSet<String> los = accessibleFileObjectUris.get(spacePart); spaceRootFOUri = los.iterator().next(); } finally { readLock.unlock(); } ensureFileSystemIsMounted(spacePart, spaceRootFOUri); } final String relativeToSpace = uri.getRelativeToSpace(); try { readLock.lock(); if (!mountedSpaces.containsKey(spacePart)) { throw new FileSystemException("Could not access file that should exist (be mounted)"); } final ConcurrentHashMap<String, FileObject> spaceRoots = mountedSpaces.get(spacePart); FileObject spaceRoot = spaceRoots.get(spaceRootFOUri); FileName dataSpaceVFSFileName = null; final FileObject file; // the dataspace "File name" (it is actually a File Path) is computed using the Virtual Space root if (dataSpaceVFSFileName == null) { dataSpaceVFSFileName = spaceRoot.getName(); } try { if (relativeToSpace == null) file = spaceRoot; else file = spaceRoot.resolveFile(relativeToSpace); final DataSpacesLimitingFileObject limitingFile = new DataSpacesLimitingFileObject(file, spacePart, spaceRoot.getName(), ownerActiveObjectId); return new VFSFileObjectAdapter(limitingFile, spacePart, dataSpaceVFSFileName, new ArrayList<String>(accessibleFileObjectUris.get(spacePart)), spaceRootFOUri, this, ownerActiveObjectId); } catch (org.apache.commons.vfs.FileSystemException x) { logger.error("[VFSMountManager] Could not access file within a space: " + uri); throw new FileSystemException(x); } catch (FileSystemException e) { ProActiveLogger.logImpossibleException(logger, e); throw new ProActiveRuntimeException(e); } } finally { readLock.unlock(); } }
From source file:com.web.messaging.MessagingClassConstruct.java
/** * This method parses the messagingclass.xml which is obtained after undeploying the War file and metadata which is constructed in removed from the messaingclassMap * @param messagedigester//w w w . j av a2 s . c om * @param configFile * @param messagingClassMap * @throws FileNotFoundException * @throws IOException * @throws SAXException */ public void removeMessagingClass(Digester messagedigester, File configFile, Hashtable messagingClassMap) throws FileNotFoundException, IOException, SAXException { try { MessagingClasses messagingClasses = (MessagingClasses) messagedigester .parse(new InputSource(new FileInputStream(configFile))); for (MessagingClass messagingclass : messagingClasses.messagingClasses) { if (messagingclass.getMessagetype().equals("RandomQueue")) { ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue"); //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()+"Random Queue Map"+randomqueuemap); if (randomqueuemap != null) { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { for (int count = 0; count < queueclassList.size(); count++) { MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count); //System.out.println(messagingClassTmp); //System.out.println(messagingClassTmp.getMessageelemname()+" "+messagingclass.getMessageelemname() ); //System.out.println(messagingClassTmp.getMessagetype()+" "+messagingclass.getMessagetype() ); //System.out.println(messagingClassTmp.getMessagingclass()+" "+messagingclass.getMessagingclass() ); if (messagingClassTmp.getMessageelemname().trim() .equals(messagingclass.getMessageelemname().trim()) && messagingClassTmp.getMessagetype().trim() .equals(messagingclass.getMessagetype().trim()) && messagingClassTmp.getMessagingclass().trim() .equals(messagingclass.getMessagingclass().trim())) { queueclassList.remove(messagingClassTmp); } //System.out.println(count); //System.out.println("MessageElemName="+messagingClassTmp); } } } } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) { ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap .get("RoundRobinQueue"); //System.out.println("RoundRobinQueueMap"+roundrobinqueuemap); if (roundrobinqueuemap != null) { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { for (int count = 0; count < queueclassList.size(); count++) { MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count); if (messagingClassTmp.getMessageelemname() .equals(messagingclass.getMessageelemname()) && messagingClassTmp.getMessagetype() .equals(messagingclass.getMessagetype()) && messagingClassTmp.getMessagingclass() .equals(messagingclass.getMessagingclass())) { queueclassList.remove(messagingClassTmp); } } } } //System.out.println("End RoundRobinQueueMap"+roundrobinqueuemap); } else if (messagingclass.getMessagetype().equals("Topic")) { ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic"); //System.out.println("TopicMap"+topicmap); if (topicmap != null) { CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap .get(messagingclass.getMessageelemname().trim()); if (topicclassList != null) { for (int count = 0; count < topicclassList.size(); count++) { MessagingClass messagingClassTmp = (MessagingClass) topicclassList.get(count); if (messagingClassTmp.getMessageelemname() .equals(messagingclass.getMessageelemname()) && messagingClassTmp.getMessagetype() .equals(messagingclass.getMessagetype()) && messagingClassTmp.getMessagingclass() .equals(messagingclass.getMessagingclass())) { topicclassList.remove(messagingClassTmp); } } } } //System.out.println("End TopicMap"+topicmap); } } } catch (Exception ex) { //ex.printStackTrace(); } //System.out.println(messagingClassMap); }
From source file:com.app.messaging.MessagingClassConstruct.java
/** * This method parses the messagingclass.xml which is obtained after undeploying the War file and metadata which is constructed in removed from the messaingclassMap * @param messagedigester// ww w . jav a2s .c o m * @param configFile * @param messagingClassMap * @throws FileNotFoundException * @throws IOException * @throws SAXException */ public void removeMessagingClass(Digester messagedigester, File configFile, Hashtable messagingClassMap) throws FileNotFoundException, IOException, SAXException { try { MessagingClasses messagingClasses = (MessagingClasses) messagedigester .parse(new InputSource(new FileInputStream(configFile))); for (MessagingClass messagingclass : messagingClasses.messagingClasses) { if (messagingclass.getMessagetype().equals("RandomQueue")) { ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue"); //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()+"Random Queue Map"+randomqueuemap); if (randomqueuemap != null) { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { for (int count = 0; count < queueclassList.size(); count++) { MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count); //System.out.println(messagingClassTmp); //System.out.println(messagingClassTmp.getMessageelemname()+" "+messagingclass.getMessageelemname() ); //System.out.println(messagingClassTmp.getMessagetype()+" "+messagingclass.getMessagetype() ); //System.out.println(messagingClassTmp.getMessagingclass()+" "+messagingclass.getMessagingclass() ); if (messagingClassTmp.getMessageelemname().trim() .equals(messagingclass.getMessageelemname().trim()) && messagingClassTmp.getMessagetype().trim() .equals(messagingclass.getMessagetype().trim()) && messagingClassTmp.getMessagingclass().trim() .equals(messagingclass.getMessagingclass().trim())) { queueclassList.remove(messagingClassTmp); } //System.out.println(count); //System.out.println("MessageElemName="+messagingClassTmp); } } } } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) { ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap .get("RoundRobinQueue"); //System.out.println("RoundRobinQueueMap"+roundrobinqueuemap); if (roundrobinqueuemap != null) { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { for (int count = 0; count < queueclassList.size(); count++) { MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count); if (messagingClassTmp.getMessageelemname() .equals(messagingclass.getMessageelemname()) && messagingClassTmp.getMessagetype() .equals(messagingclass.getMessagetype()) && messagingClassTmp.getMessagingclass() .equals(messagingclass.getMessagingclass())) { queueclassList.remove(messagingClassTmp); } } } } //System.out.println("End RoundRobinQueueMap"+roundrobinqueuemap); } else if (messagingclass.getMessagetype().equals("Topic")) { ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic"); //System.out.println("TopicMap"+topicmap); if (topicmap != null) { CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap .get(messagingclass.getMessageelemname().trim()); if (topicclassList != null) { for (int count = 0; count < topicclassList.size(); count++) { MessagingClass messagingClassTmp = (MessagingClass) topicclassList.get(count); if (messagingClassTmp.getMessageelemname() .equals(messagingclass.getMessageelemname()) && messagingClassTmp.getMessagetype() .equals(messagingclass.getMessagetype()) && messagingClassTmp.getMessagingclass() .equals(messagingclass.getMessagingclass())) { topicclassList.remove(messagingClassTmp); } } } } //System.out.println("End TopicMap"+topicmap); } } } catch (Exception ex) { log.error("Error occurred in constructing messaging classes", ex); //ex.printStackTrace(); } //System.out.println(messagingClassMap); }
From source file:com.web.messaging.MessagingClassConstruct.java
/** * This method parses the messagingclass.xml which is obtained after deploying the War file and metadata is constructed and kept in HashMap * @param messagedigester/*from w ww.j a v a2 s .c om*/ * @param configFile * @param customClassLoader * @param messagingClassMap * @throws ClassNotFoundException * @throws FileNotFoundException * @throws IOException * @throws SAXException */ public void getMessagingClass(Digester messagedigester, File configFile, WebClassLoader customClassLoader, Hashtable messagingClassMap) throws ClassNotFoundException, FileNotFoundException, IOException, SAXException { MessagingClasses messagingClasses = (MessagingClasses) messagedigester .parse(new InputSource(new FileInputStream(configFile))); for (MessagingClass messagingclass : messagingClasses.messagingClasses) { Class messagingClass = customClassLoader.loadClass(messagingclass.getMessagingclass()); messagingclass.setMessageClass(messagingClass); if (messagingclass.getMessagetype().equals("RandomQueue")) { ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue"); //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()); if (randomqueuemap == null) { System.out.print("No RandomQueue Available"); } else { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { queueclassList.add(messagingclass); } else { System.out.print("No RandomQueue Available"); } } } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) { ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap.get("RoundRobinQueue"); if (roundrobinqueuemap == null) { System.out.print("No RoundRobinQueue Available"); } else { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { queueclassList.add(messagingclass); } else { System.out.print("No RoundRobinQueue Available"); } } } else if (messagingclass.getMessagetype().equals("Topic")) { ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic"); if (topicmap == null) { System.out.print("No Topic Available"); } else { CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap .get(messagingclass.getMessageelemname().trim()); if (topicclassList != null) { topicclassList.add(messagingclass); } else { System.out.print("No Topic Available"); } } } } //System.out.println(messagingClassMap); }
From source file:com.app.messaging.MessagingClassConstruct.java
public void getMessagingClass(Digester messagedigester, File configFile, WebClassLoader customClassLoader, Hashtable messagingClassMap) throws ClassNotFoundException, FileNotFoundException, IOException, SAXException { MessagingClasses messagingClasses = (MessagingClasses) messagedigester .parse(new InputSource(new FileInputStream(configFile))); for (MessagingClass messagingclass : messagingClasses.messagingClasses) { Class messagingClass = customClassLoader.loadClass(messagingclass.getMessagingclass()); messagingclass.setMessageClass(messagingClass); if (messagingclass.getMessagetype().equals("RandomQueue")) { ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue"); //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()); if (randomqueuemap == null) { System.out.print("No RandomQueue Available"); } else { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { queueclassList.add(messagingclass); } else { System.out.print("No RandomQueue Available"); }/* w w w. j av a 2 s.co m*/ } } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) { ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap.get("RoundRobinQueue"); if (roundrobinqueuemap == null) { System.out.print("No RoundRobinQueue Available"); } else { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { queueclassList.add(messagingclass); } else { System.out.print("No RoundRobinQueue Available"); } } } else if (messagingclass.getMessagetype().equals("Topic")) { ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic"); if (topicmap == null) { System.out.print("No Topic Available"); } else { CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap .get(messagingclass.getMessageelemname().trim()); if (topicclassList != null) { topicclassList.add(messagingclass); } else { System.out.print("No Topic Available"); } } } } //System.out.println(messagingClassMap); }
From source file:com.alibaba.wasp.meta.TableSchemaCacheReader.java
private void mapping(Index index, String tableName) { ConcurrentHashMap<String, List<Index>> indexs = compositeIndex.get(tableName); if (indexs == null) { indexs = new ConcurrentHashMap<String, List<Index>>(); compositeIndex.put(tableName, indexs); }//from ww w. j a va2 s. co m StringBuilder start = new StringBuilder(); for (Field field : index.getIndexKeys().values()) { start.append(field.getName()); List<Index> indexList = indexs.get(start.toString()); if (indexList == null) { indexList = new ArrayList<Index>(); indexs.put(start.toString(), indexList); } indexList.add(index); } }
From source file:com.taobao.tddl.common.util.TDDLMBeanServer.java
private String getId(String name, String idPrefix) { ConcurrentHashMap<String, AtomicLong> subMap = idMap.get(name); if (null == subMap) { lock.lock();/* w ww. ja va 2s . c om*/ try { subMap = idMap.get(name); if (null == subMap) { subMap = new ConcurrentHashMap<String, AtomicLong>(); idMap.put(name, subMap); } } finally { lock.unlock(); } } AtomicLong indexValue = subMap.get(idPrefix); if (null == indexValue) { lock.lock(); try { indexValue = subMap.get(idPrefix); if (null == indexValue) { indexValue = new AtomicLong(0); subMap.put(idPrefix, indexValue); } } finally { lock.unlock(); } } long value = indexValue.incrementAndGet(); String result = idPrefix + "-" + value; return result; }