@Override public Histogram histogram(String name) { return (Histogram) CollectionUtils.computeIfAbsent(metrics, name, this::createHistogram); }
@Override public Meter meter(String name) { return (Meter) CollectionUtils.computeIfAbsent(metrics, name, this::createMeter); }
@Override public Counter counter(String name) { return (Counter) CollectionUtils.computeIfAbsent(metrics, name, this::createCounter); }
@Override public Metric register(String name, Metric metric) { return CollectionUtils.computeIfAbsent(metrics, name, () -> metric); }
@Override public Timer timer(String name) { return (Timer) CollectionUtils.computeIfAbsent(metrics, name, this::createTimer); }
private TableCache getTableCache(TableName tableName) { return computeIfAbsent(cache, tableName, TableCache::new); }
@Override public void incTaskCounters(Collection<byte[]> regions, ServerName sn) { tasksInProgress.incrementAndGet(); computeIfAbsent(taskCounterPerServer, sn, AtomicInteger::new).incrementAndGet(); regions.forEach((regBytes) -> computeIfAbsent(taskCounterPerRegion, regBytes, AtomicInteger::new).incrementAndGet() ); }
/** * Reports that there was an error on the server to do whatever bean-counting necessary. * @param server The server in question. */ void reportServerError(ServerName server) { computeIfAbsent(errorsByServer, server, ServerErrors::new).addError(); }
/** * Get a metric for {@code key} from {@code map}, or create it with {@code factory}. */ private <T> T getMetric(String key, ConcurrentMap<String, T> map, NewMetric<T> factory) { return computeIfAbsent(map, key, () -> factory.newMetric(getClass(), key, scope)); }
/** * @param tableName * @return Map of cached locations for passed <code>tableName</code> */ private ConcurrentNavigableMap<byte[], RegionLocations> getTableLocations( final TableName tableName) { // find the map of cached locations for this table return computeIfAbsent(cachedRegionLocations, tableName, () -> new CopyOnWriteArrayMap<>(Bytes.BYTES_COMPARATOR)); }
@Override public void updateRegionStats(ServerName server, byte[] region, RegionLoadStats currentStats) { computeIfAbsent(stats, server, ServerStatistics::new).update(region, currentStats); }
@Override public void updateRegionStats(ServerName serverName, byte[] regionName, RegionLoadStats stats) { String name = serverName.getServerName() + "," + Bytes.toStringBinary(regionName); ConcurrentMap<byte[], RegionStats> rsStats = computeIfAbsent(serverStats, serverName, () -> new ConcurrentSkipListMap<>(Bytes.BYTES_COMPARATOR)); RegionStats regionStats = computeIfAbsent(rsStats, regionName, () -> new RegionStats(this.registry, name)); regionStats.update(stats); }
public void addAction(HRegionLocation loc, Action action) { computeIfAbsent(actionsByRegion, loc.getRegionInfo().getRegionName(), () -> new RegionRequest(loc)).actions.add(action); } }
/** * Handles failures encountered when communicating with a server. * * Updates the FailureInfo in repeatedFailuresMap to reflect the failure. * Throws RepeatedConnectException if the client is in Fast fail mode. * * @param serverName * @param t * - the throwable to be handled. * @throws PreemptiveFastFailException */ @VisibleForTesting protected void handleFailureToServer(ServerName serverName, Throwable t) { if (serverName == null || t == null) { return; } long currentTime = EnvironmentEdgeManager.currentTime(); FailureInfo fInfo = computeIfAbsent(repeatedFailuresMap, serverName, () -> new FailureInfo(currentTime)); fInfo.timeOfLatestAttemptMilliSec = currentTime; fInfo.numConsecutiveFailures.incrementAndGet(); }
locateFailed.add(action); } else { computeIfAbsent(actionsByServer, loc.getServerName(), ServerRequest::new) .addAction(loc, action);
@Override public Timer timer(String name) { return (Timer) CollectionUtils.computeIfAbsent(metrics, name, this::createTimer); }
/** * In HBASE-16648 we found that ConcurrentHashMap.get is much faster than computeIfAbsent if the * value already exists. Notice that the implementation does not guarantee that the supplier will * only be executed once. */ public static <K, V> V computeIfAbsent(ConcurrentMap<K, V> map, K key, Supplier<V> supplier) { return computeIfAbsent(map, key, supplier, () -> { }); }
@Override public void incTaskCounters(Collection<byte[]> regions, ServerName sn) { tasksInProgress.incrementAndGet(); computeIfAbsent(taskCounterPerServer, sn, AtomicInteger::new).incrementAndGet(); regions.forEach((regBytes) -> computeIfAbsent(taskCounterPerRegion, regBytes, AtomicInteger::new).incrementAndGet() ); }
/** * Reports that there was an error on the server to do whatever bean-counting necessary. * @param server The server in question. */ void reportServerError(ServerName server) { computeIfAbsent(errorsByServer, server, ServerErrors::new).addError(); }
/** * @param tableName * @return Map of cached locations for passed <code>tableName</code> */ private ConcurrentNavigableMap<byte[], RegionLocations> getTableLocations( final TableName tableName) { // find the map of cached locations for this table return computeIfAbsent(cachedRegionLocations, tableName, () -> new CopyOnWriteArrayMap<>(Bytes.BYTES_COMPARATOR)); }