@Override protected Map<String, String> create(Entry<String, String>[] entries) { return populate(new ConcurrentHashMap<String, String>(), entries); } })
@Override public void addPatterns(String sentId, Map<Integer, Set<E>> patterns) { if (!patternsForEachToken.containsKey(sentId)) patternsForEachToken.put(sentId, new ConcurrentHashMap<>()); patternsForEachToken.get(sentId).putAll(patterns); }
private boolean isTaskInPendingCompletionGroups(String taskId) { for (List<TaskGroup> taskGroups : pendingCompletionTaskGroups.values()) { for (TaskGroup taskGroup : taskGroups) { if (taskGroup.tasks.containsKey(taskId)) { return true; } } } return false; }
public static <T> ProviderInvokerWrapper<T> registerProvider(Invoker<T> invoker, URL registryUrl, URL providerUrl) { ProviderInvokerWrapper<T> wrapperInvoker = new ProviderInvokerWrapper<>(invoker, registryUrl, providerUrl); String serviceUniqueName = providerUrl.getServiceKey(); ConcurrentMap<Invoker, ProviderInvokerWrapper> invokers = providerInvokers.get(serviceUniqueName); if (invokers == null) { providerInvokers.putIfAbsent(serviceUniqueName, new ConcurrentHashMap<>()); invokers = providerInvokers.get(serviceUniqueName); } invokers.put(invoker, wrapperInvoker); return wrapperInvoker; }
protected Deque<PooledConnection> getPoolForEventLoop(EventLoop eventLoop) { // We don't want to block under any circumstances, so can't use CHM.computeIfAbsent(). // Instead we accept the slight inefficiency of an unnecessary instantiation of a ConcurrentLinkedDeque. Deque<PooledConnection> pool = connectionsPerEventLoop.get(eventLoop); if (pool == null) { pool = new ConcurrentLinkedDeque<>(); connectionsPerEventLoop.putIfAbsent(eventLoop, pool); } return pool; }
void putFilter(String sName, ZuulFilter filter, long lastModified) { List<ZuulFilter> list = hashFiltersByType.get(filter.filterType()); if (list != null) { hashFiltersByType.remove(filter.filterType()); //rebuild this list } String nameAndType = filter.filterType() + ":" + filter.filterName(); filtersByNameAndType.put(nameAndType, filter); filterRegistry.put(sName, filter); filterClassLastModified.put(sName, lastModified); }
public static Set<ProviderInvokerWrapper> getProviderInvoker(String serviceUniqueName) { ConcurrentMap<Invoker, ProviderInvokerWrapper> invokers = providerInvokers.get(serviceUniqueName); if (invokers == null) { return Collections.emptySet(); } return new HashSet<>(invokers.values()); }
@Override public String getDataSource(final String name, final String masterDataSourceName, final List<String> slaveDataSourceNames) { AtomicInteger count = COUNT_MAP.containsKey(name) ? COUNT_MAP.get(name) : new AtomicInteger(0); COUNT_MAP.putIfAbsent(name, count); count.compareAndSet(slaveDataSourceNames.size(), 0); return slaveDataSourceNames.get(Math.abs(count.getAndIncrement()) % slaveDataSourceNames.size()); } }
@Override public Object put(String key, Object value) { if (value != null) { return super.put(key, value); } else { return remove(key); } }
/** * Increments the entry for this guess and gold by the given increment amount. */ public synchronized void add(U guess, U gold, int increment) { Pair<U, U> pair = new Pair<>(guess, gold); if (confTable.containsKey(pair)) { confTable.put(pair, confTable.get(pair) + increment); } else { confTable.put(pair, increment); } }
private static int count(int jobId) { // cache clear if (System.currentTimeMillis() > CACHE_VALID_TIME) { routeCountEachJob.clear(); CACHE_VALID_TIME = System.currentTimeMillis() + 1000*60*60*24; } // count++ Integer count = routeCountEachJob.get(jobId); count = (count==null || count>1000000)?(new Random().nextInt(100)):++count; // 初始化时主动Random一次,缓解首次压力 routeCountEachJob.put(jobId, count); return count; }
private InvocationHandler buildInvocationHandler(String referencedBeanName, ReferenceBean referenceBean) { ReferenceBeanInvocationHandler handler = localReferenceBeanInvocationHandlerCache.get(referencedBeanName); if (handler == null) { handler = new ReferenceBeanInvocationHandler(referenceBean); } if (applicationContext.containsBean(referencedBeanName)) { // Is local @Service Bean or not ? // ReferenceBeanInvocationHandler's initialization has to wait for current local @Service Bean has been exported. localReferenceBeanInvocationHandlerCache.put(referencedBeanName, handler); } else { // Remote Reference Bean should initialize immediately handler.init(); } return handler; }
private void killTaskGroupForPartitions(Set<PartitionIdType> partitions, String reasonFormat, Object... args) { for (PartitionIdType partition : partitions) { int taskGroupId = getTaskGroupIdForPartition(partition); killTasksInGroup(activelyReadingTaskGroups.get(taskGroupId), reasonFormat, args); partitionGroups.remove(taskGroupId); activelyReadingTaskGroups.remove(taskGroupId); } }
/** * If {@code (key, value)} is currently in the map, this method removes it and returns true; * otherwise, this method returns false. */ boolean remove(K key, long value) { return map.remove(key, value); }
private boolean isNodeShuttingDown(String nodeId) { Optional<NodeState> remoteNodeState = nodeStates.containsKey(nodeId) ? nodeStates.get(nodeId).getNodeState() : Optional.empty(); return remoteNodeState.isPresent() && remoteNodeState.get() == SHUTTING_DOWN; }
/** * Removes all of the mappings from this map. The map will be empty after this call returns. * * <p>This method is not atomic: the map may not be empty after returning if there were concurrent * writes. */ public void clear() { map.clear(); }
@Override public Mono<Void> doNotify(InstanceEvent event, Instance instance) { return delegate.notify(event).onErrorResume(error -> Mono.empty()).then(Mono.fromRunnable(() -> { if (shouldEndReminder(event)) { reminders.remove(event.getInstance()); } else if (shouldStartReminder(event)) { reminders.putIfAbsent(event.getInstance(), new Reminder(event)); } })); }
@VisibleForTesting public void moveTaskGroupToPendingCompletion(int taskGroupId) { final TaskGroup taskGroup = activelyReadingTaskGroups.remove(taskGroupId); if (taskGroup != null) { pendingCompletionTaskGroups.computeIfAbsent(taskGroupId, k -> new CopyOnWriteArrayList<>()).add(taskGroup); } }
/** Returns true if this map contains a mapping for the specified key. */ public boolean containsKey(Object key) { return map.containsKey(key); }