private ConcurrentLinkedQueue<OutstandingRequest> getQueue(String function) { if (function == null) { throw new IllegalArgumentException("The function for a request cannot be null"); } ConcurrentLinkedQueue<OutstandingRequest> queue = _queues.get(function); if (queue == null) { _queues.putIfAbsent(function, new ConcurrentLinkedQueue<>()); queue = _queues.get(function); } return queue; }
public V get(K key) { V v = store.get(key); if(v!=null) return v; // TODO: if we want to, we can avoid locking altogether by putting a sentinel value // that represents "the value is being computed". FingerprintMap does this. synchronized (this) { v = store.get(key); if(v!=null) return v; v = compute(key); store.put(key,v); return v; } }
public MemoryMapStateBacking(String id) { if (!_dbs.containsKey(id)) { _dbs.put(id, new HashMap()); } this.db = (Map<List<Object>, T>) _dbs.get(id); }
@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 Map<Integer, Set<E>> getPatternsForAllTokens(String sentId) { return (Map<Integer, Set<E>>)(patternsForEachToken.containsKey(sentId) ? patternsForEachToken.get(sentId) : Collections.emptyMap()); }
private void addCommandListener(URL url, CommandListener commandListener) { String group = url.getGroup(); ConcurrentHashMap<URL, CommandListener> map = commandListeners.get(group); if (map == null) { commandListeners.putIfAbsent(group, new ConcurrentHashMap<URL, CommandListener>()); map = commandListeners.get(group); } synchronized (map) { map.put(url, commandListener); } }
public void addError(long offset, int length, long baseOffset) { Long key = Long.valueOf(offset + baseOffset); Integer existingLength = cache.get(key); if (existingLength != null && existingLength >= length) return; Integer value = Integer.valueOf(length); while (true) { existingLength = cache.putIfAbsent(key, value); if (existingLength == null || existingLength >= length) return; cache.remove(key, existingLength); } }
/** * Helper method to have a single point of deletion in the queued flows */ public void dequeue(final int executionId) { if (this.queuedFlowMap.containsKey(executionId)) { this.queuedFlowList.remove(this.queuedFlowMap.get(executionId)); this.queuedFlowMap.remove(executionId); } }
@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); }
/** * Removes element from the queue. * @param elem element to remove * @return time at which the element was set to expire, or null if * it wasn't present */ public Long remove(E elem) { Long expiryTime = elemMap.remove(elem); if (expiryTime != null) { Set<E> set = expiryMap.get(expiryTime); if (set != null) { set.remove(elem); // We don't need to worry about removing empty sets, // they'll eventually be removed when they expire. } } return expiryTime; }
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; }
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; }
@Override public KeyColumnValueStore openDatabase(final String name, StoreMetaData.Container metaData) throws BackendException { if (!stores.containsKey(name)) { stores.putIfAbsent(name, new InMemoryKeyColumnValueStore(name)); } KeyColumnValueStore store = stores.get(name); Preconditions.checkNotNull(store); return store; }
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); }
private boolean isNodeShuttingDown(String nodeId) { Optional<NodeState> remoteNodeState = nodeStates.containsKey(nodeId) ? nodeStates.get(nodeId).getNodeState() : Optional.empty(); return remoteNodeState.isPresent() && remoteNodeState.get() == SHUTTING_DOWN; }
private void addServiceListener(URL url, ServiceListener serviceListener) { String service = ConsulUtils.getUrlClusterInfo(url); ConcurrentHashMap<URL, ServiceListener> map = serviceListeners.get(service); if (map == null) { serviceListeners.putIfAbsent(service, new ConcurrentHashMap<URL, ServiceListener>()); map = serviceListeners.get(service); } synchronized (map) { map.put(url, serviceListener); } }
/** * Remove the NonceKey if the procedure was not submitted to the executor. * @param nonceKey A unique identifier for this operation from the client or process. */ public void unregisterNonceIfProcedureWasNotSubmitted(final NonceKey nonceKey) { if (nonceKey == null) return; final Long procId = nonceKeysToProcIdsMap.get(nonceKey); if (procId == null) return; // if the procedure was not submitted, remove the nonce if (!(procedures.containsKey(procId) || completed.containsKey(procId))) { nonceKeysToProcIdsMap.remove(nonceKey); } }
private void addToCollection(ConcurrentHashMap<String, Collection<OAuth2AccessToken>> store, String key, OAuth2AccessToken token) { if (!store.containsKey(key)) { synchronized (store) { if (!store.containsKey(key)) { store.put(key, new HashSet<OAuth2AccessToken>()); } } } store.get(key).add(token); }