Java Code Examples for java.util.concurrent.ConcurrentHashMap#size()
The following examples show how to use
java.util.concurrent.ConcurrentHashMap#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlowQueryReport.java From Tomcat8-Source-Read with MIT License | 6 votes |
protected QueryStats getQueryStats(String sql) { if (sql==null) sql = ""; ConcurrentHashMap<String,QueryStats> queries = SlowQueryReport.this.queries; if (queries==null) { if (log.isWarnEnabled()) log.warn("Connection has already been closed or abandoned"); return null; } QueryStats qs = queries.get(sql); if (qs == null) { qs = new QueryStats(sql); if (queries.putIfAbsent(sql,qs)!=null) { qs = queries.get(sql); } else { //we added a new element, see if we need to remove the oldest if (queries.size() > maxQueries) { removeOldest(queries); } } } return qs; }
Example 2
Source File: SlowQueryReport.java From tomcatsrc with Apache License 2.0 | 6 votes |
protected QueryStats getQueryStats(String sql) { if (sql==null) sql = ""; ConcurrentHashMap<String,QueryStats> queries = SlowQueryReport.this.queries; if (queries==null) { if (log.isWarnEnabled()) log.warn("Connection has already been closed or abandoned"); return null; } QueryStats qs = queries.get(sql); if (qs == null) { qs = new QueryStats(sql); if (queries.putIfAbsent(sql,qs)!=null) { qs = queries.get(sql); } else { //we added a new element, see if we need to remove the oldest if (queries.size() > maxQueries) { removeOldest(queries); } } } return qs; }
Example 3
Source File: StatsdAggregationThread.java From StatsAgg with Apache License 2.0 | 6 votes |
private List<StatsdMetric> getCurrentStatsdMetricsAndRemoveMetricsFromGlobal(ConcurrentHashMap<Long,StatsdMetric> statsdMetrics) { if (statsdMetrics == null) { return new ArrayList(); } List<StatsdMetric> statsdMetricsToReturn = new ArrayList(statsdMetrics.size()); for (StatsdMetric statsdMetric : statsdMetrics.values()) { if (statsdMetric.getMetricReceivedTimestampInMilliseconds() <= threadStartTimestampInMilliseconds_) { statsdMetricsToReturn.add(statsdMetric); statsdMetrics.remove(statsdMetric.getHashKey()); } } return statsdMetricsToReturn; }
Example 4
Source File: DriverPoolTest.java From carina with Apache License 2.0 | 6 votes |
/** * Register driver in the DriverPool with device * * @param driver * WebDriver * @param name * String driver name * @param device * Device * */ private void registerDriver(WebDriver driver, String name, Device device) { Long threadId = Thread.currentThread().getId(); ConcurrentHashMap<String, CarinaDriver> currentDrivers = getDrivers(); int maxDriverCount = Configuration.getInt(Parameter.MAX_DRIVER_COUNT); if (currentDrivers.size() == maxDriverCount) { Assert.fail("Unable to register driver as you reached max number of drivers per thread: " + maxDriverCount); } if (currentDrivers.containsKey(name)) { Assert.fail("Driver '" + name + "' is already registered for thread: " + threadId); } // new 6.0 approach to manipulate drivers via regular Set CarinaDriver carinaDriver = new CarinaDriver(name, driver, device, TestPhase.getActivePhase(), threadId); driversPool.add(carinaDriver); }
Example 5
Source File: AbstractHollowProducer.java From hollow with Apache License 2.0 | 6 votes |
HollowProducer.Populator incrementalPopulate( ProducerListeners listeners, HollowProducer.Incremental.IncrementalPopulator incrementalPopulator, long toVersion) throws Exception { ConcurrentHashMap<RecordPrimaryKey, Object> events = new ConcurrentHashMap<>(); Status.IncrementalPopulateBuilder incrementalPopulateStatus = listeners.fireIncrementalPopulateStart(toVersion); try (CloseableIncrementalWriteState iws = new CloseableIncrementalWriteState(events, getObjectMapper())) { incrementalPopulator.populate(iws); incrementalPopulateStatus.success(); long removed = events.values().stream() .filter(o -> o == HollowIncrementalCyclePopulator.DELETE_RECORD).count(); long addedOrModified = events.size() - removed; incrementalPopulateStatus.changes(removed, addedOrModified); } catch (Throwable th) { incrementalPopulateStatus.fail(th); throw th; } finally { listeners.fireIncrementalPopulateComplete(incrementalPopulateStatus); } return new HollowIncrementalCyclePopulator(events, 1.0); }
Example 6
Source File: NYBusDriver.java From NYBus with Apache License 2.0 | 5 votes |
/** * Remove the event. * * @param mTargetMap the target map. * @param mEventsToTargetsMapEntry the event to target map entry. */ private void removeEventIfRequired(ConcurrentHashMap<Object, ConcurrentHashMap<String, SubscriberHolder>> mTargetMap, Map.Entry<Class<?>, ConcurrentHashMap<Object, ConcurrentHashMap<String, SubscriberHolder>>> mEventsToTargetsMapEntry) { if (mTargetMap.size() == 0) { mEventsToTargetsMap.remove(mEventsToTargetsMapEntry.getKey()); } }
Example 7
Source File: DoubleKeyValueMap.java From android-open-project-demo with Apache License 2.0 | 5 votes |
public int size() { if (k1_k2V_map.size() == 0) return 0; int result = 0; for (ConcurrentHashMap<K2, V> k2V_map : k1_k2V_map.values()) { result += k2V_map.size(); } return result; }
Example 8
Source File: LoggingRegistry.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Helper Method that determines a LogChannelFileWriterBuffer invoked by getLogChannelFileWriterBuffer and returns 1. * @param possibleWriters Map to search from. * @return LogChannelFileWriterBuffer, null if could not be determined. */ private LogChannelFileWriterBuffer determineLogChannelFileWriterBuffer( ConcurrentHashMap<LogChannelFileWriterBuffer, List<String>> possibleWriters ) { // Just one writer so just return it if ( possibleWriters.size() == 1 ) { return possibleWriters.keys().nextElement(); } else { // Several possibilities, so, lets get the writer among them that is the "lowest in the chain", // meaning, the one that is not a parent of the others Enumeration<LogChannelFileWriterBuffer> possibleWritersIds = possibleWriters.keys(); while ( possibleWritersIds.hasMoreElements() ) { LogChannelFileWriterBuffer writer = possibleWritersIds.nextElement(); for ( Map.Entry<LogChannelFileWriterBuffer, List<String>> entry : possibleWriters.entrySet() ) { if ( entry.getKey().equals( writer ) ) { continue; } if ( !entry.getValue().contains( writer.getLogChannelId() ) ) { return entry.getKey(); } } } } return null; }
Example 9
Source File: HelloImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap) throws RemoteException { int hashMapSize = 0; hashMapSize = receivedHashMap.size(); String response = "Hello with hashMapSize == " + hashMapSize; return response; }
Example 10
Source File: HelloImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap) throws RemoteException { int hashMapSize = 0; hashMapSize = receivedHashMap.size(); String response = "Hello with hashMapSize == " + hashMapSize; return response; }
Example 11
Source File: HelloImpl.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap) throws RemoteException { int hashMapSize = 0; hashMapSize = receivedHashMap.size(); String response = "Hello with hashMapSize == " + hashMapSize; return response; }
Example 12
Source File: ProcedureResultCollector.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/*** * * @param resultSetNumber * @return */ public IncomingResultSet[] getIncomingResultSets(int resultSetNumber) { IncomingResultSet[] retValue = null; Integer key = Integer.valueOf(resultSetNumber); if (this.incomingResultSets.containsKey(key)) { ConcurrentHashMap<String, IncomingResultSetImpl> sameNumberResultSets = this.incomingResultSets.get(key); retValue = new IncomingResultSet[sameNumberResultSets.size()]; retValue = sameNumberResultSets.values().toArray(retValue); } return retValue; }
Example 13
Source File: HelloImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap) throws RemoteException { int hashMapSize = 0; hashMapSize = receivedHashMap.size(); String response = "Hello with hashMapSize == " + hashMapSize; return response; }
Example 14
Source File: ProcedureResultCollector.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/*** * * @param resultSetNumber * @return */ public IncomingResultSet[] getIncomingResultSets(int resultSetNumber) { IncomingResultSet[] retValue = null; Integer key = Integer.valueOf(resultSetNumber); if (this.incomingResultSets.containsKey(key)) { ConcurrentHashMap<String, IncomingResultSetImpl> sameNumberResultSets = this.incomingResultSets.get(key); retValue = new IncomingResultSet[sameNumberResultSets.size()]; retValue = sameNumberResultSets.values().toArray(retValue); } return retValue; }
Example 15
Source File: HelloImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public String sayHelloWithHashMap(ConcurrentHashMap<String, String> receivedHashMap) throws RemoteException { int hashMapSize = 0; hashMapSize = receivedHashMap.size(); String response = "Hello with hashMapSize == " + hashMapSize; return response; }
Example 16
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Example using a Cleaner to remove WeakKey references from a Map. */ @Test void testWeakKey() { ConcurrentHashMap<WeakKey<String>, String> map = new ConcurrentHashMap<>(); Cleaner cleaner = Cleaner.create(); String key = new String("foo"); // ensure it is not interned String data = "bar"; map.put(new WeakKey<>(key, cleaner, map), data); WeakKey<String> k2 = new WeakKey<>(key, cleaner, map); Assert.assertEquals(map.get(k2), data, "value should be found in the map"); key = null; System.gc(); Assert.assertNotEquals(map.get(k2), data, "value should not be found in the map"); final long CYCLE_MAX = Utils.adjustTimeout(30L); for (int i = 1; map.size() > 0 && i < CYCLE_MAX; i++) { map.forEach( (k, v) -> System.out.printf(" k: %s, v: %s%n", k, v)); try { Thread.sleep(10L); } catch (InterruptedException ie) {} } Assert.assertEquals(map.size(), 0, "Expected map to be empty;"); cleaner = null; }
Example 17
Source File: SlowQueryReport.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Sort QueryStats by last invocation time * @param queries The queries map */ protected void removeOldest(ConcurrentHashMap<String,QueryStats> queries) { ArrayList<QueryStats> list = new ArrayList<>(queries.values()); Collections.sort(list, queryStatsComparator); int removeIndex = 0; while (queries.size() > maxQueries) { String sql = list.get(removeIndex).getQuery(); queries.remove(sql); if (log.isDebugEnabled()) log.debug("Removing slow query, capacity reached:"+sql); removeIndex++; } }
Example 18
Source File: ManagedConcurrentValueMapStressTest.java From groovy with Apache License 2.0 | 4 votes |
private static int size(ManagedConcurrentValueMap<String, Object> map) { MetaClass metaClass = InvokerHelper.getMetaClass(map); ConcurrentHashMap<String, Object> internalMap = (ConcurrentHashMap<String, Object>)metaClass.getProperty(map, "internalMap"); return internalMap.size(); }
Example 19
Source File: KSAbstract.java From OSPREY3 with GNU General Public License v2.0 | 4 votes |
protected ConcurrentHashMap<Integer, PFAbstract> createPFs4Seqs(ArrayList<ArrayList<String>> seqs, ArrayList<Boolean> contSCFlexVals, ArrayList<String> pfImplVals) { ConcurrentHashMap<Integer, PFAbstract> ans = new ConcurrentHashMap<>(); ArrayList<Integer> strands = new ArrayList<Integer>(Arrays.asList(2, 0, 1)); ArrayList<Integer> indexes = new ArrayList<>(); for(int i = 0; i < strands.size(); i++) indexes.add(i); //indexes.parallelStream().forEach((index) -> { for(int index = 0; index < strands.size(); ++index) { int strand = strands.get(index); boolean contSCFlex = contSCFlexVals.get(strand); String pfImpl = pfImplVals.get(strand); ArrayList<String> seq = seqs.get(strand); PFAbstract pf = createPF4Seq(contSCFlex, strand, seq, pfImpl); // put partition function in global map name2PF.put(pf.getReducedSearchProblemName(), pf); // put in local map ans.put(strand, pf); // only continue if we have not already started computed the PF if( pf.getRunState() == RunState.NOTSTARTED ) { // get energy matrix if(pf.getReducedSearchProblem().getEnergyMatrix() == null) { pf.getReducedSearchProblem().loadEnergyMatrix(); } // re-prune, since we have fewer witnesses now that we have trimmed the emat? // type dependent pruning doesn't take care of this? if(pf.getReducedSearchProblem().numConfs(pf.getReducedPruningMatrix()).compareTo(BigInteger.ZERO) == 0) { // no conformations in search space, so this cannot give a valid // partition function System.out.println("\nRe-pruning to steric threshold..."); double maxPruningInterval = cfp.params.getDouble("StericThresh"); pf.rePruneReducedSP(maxPruningInterval); if(pf.getReducedSearchProblem().numConfs(pf.getReducedPruningMatrix()).compareTo(BigInteger.ZERO) == 0) { System.out.println("\nWARNING: there are no valid conformations for sequence " + KSAbstract.list1D2String(pf.getSequence(), " ") + " " + pf.getFlexibility() + "\n"); pf.setEpsilonStatus(EApproxReached.NOT_POSSIBLE); } } // initialize conf counts for K* pf.setNumUnPruned(); pf.setNumPruned(); } } //}); if(ans.size() != 3) throw new RuntimeException("ERROR: returned map must contain three different partition functions"); return ans; }
Example 20
Source File: StatementCache.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public int getCacheSizePerConnection() { ConcurrentHashMap<CacheKey,CachedStatement> cache = getCache(); if (cache == null) return 0; return cache.size(); }