@Override public Object get(String componentName, String key) { if (!data.containsKey(componentName)) { return null; } return data.get(componentName).get(key); }
private Resolver<?, ?, ?> getResolver(Class<?> cls, Class<? extends Resolver> resolverClass, Annotation anno) { if (!providerCache.containsKey(resolverClass)) { try { providerCache.putIfAbsent(resolverClass, resolverClass.newInstance()); } catch (Exception ex) { throw new RuntimeException(ex); } } return providerCache.get(resolverClass); }
public void addParametricType(ParametricType parametricType) { String name = parametricType.getName().toLowerCase(Locale.ENGLISH); checkArgument(!parametricTypes.containsKey(name), "Parametric type already registered: %s", name); parametricTypes.putIfAbsent(name, parametricType); }
ConsumerLog getOrCreateConsumerLog(final String subject) { Preconditions.checkArgument(!Strings.isNullOrEmpty(subject), "message subject cannot be null or empty"); if (!logs.containsKey(subject)) { synchronized (logs) { if (!logs.containsKey(subject)) { logs.put(subject, new ConsumerLog(config, subject)); } } } return logs.get(subject); }
static Semaphore getLock(ConcurrentMap<String, Semaphore> locks2, String key) { Semaphore lock = locks2.get(key); if (lock == null) { Semaphore newLock = new Semaphore(1, true); locks2.get(null); locks2.put(null, null); locks2.remove(null); locks2.containsKey(null); locks2.containsValue(null); locks2.putIfAbsent(null, null); locks2.remove(null, null); locks2.replace(null, null); locks2.replace(null, null, null); lock = locks2.putIfAbsent(key, lock); // value, being null, will *always* throw NullPointerException if (lock == null) lock = newLock; } return lock; } // static Semaphore getLock(ConcurrentMap<String, Semaphore> locks2,
synchronized void registerMetric(KafkaMetric metric) { MetricName metricName = metric.metricName(); if (this.metrics.containsKey(metricName)) throw new IllegalArgumentException("A metric named '" + metricName + "' already exists, can't register another one."); this.metrics.put(metricName, metric); for (MetricsReporter reporter : reporters) { try { reporter.metricChange(metric); } catch (Exception e) { log.error("Error when registering metric on " + reporter.getClass().getName(), e); } } log.trace("Registered metric named {}", metricName); }
private Resolver<?, ?, ?> getResolver(Class<?> cls, Class<? extends Resolver> resolverClass, Annotation anno) { if (!providerCache.containsKey(resolverClass)) { try { providerCache.putIfAbsent(resolverClass, resolverClass.newInstance()); } catch (Exception ex) { throw new RuntimeException(ex); } } return providerCache.get(resolverClass); }
@Override public EntityGraph getOrCreateEmptyEntityGraph(final Class<?> entityClass, final boolean forWriter) { final ConcurrentMap<Class<?>, EntityGraph> classToGraph = forWriter ? writerClassToGraph : readerClassToGraph; if (!classToGraph.containsKey(entityClass) || !(classToGraph.get(entityClass) instanceof EmptyEntityGraphImpl)) { classToGraph.put(entityClass, new EmptyEntityGraphImpl(entityClass)); } return classToGraph.get(entityClass); }
return; Set<LogSegmentNamesListener> listenerSet = listeners.get(logSegmentsPath); if (null == listenerSet) { Set<LogSegmentNamesListener> newListenerSet = new HashSet<LogSegmentNamesListener>(); Set<LogSegmentNamesListener> oldListenerSet = listeners.putIfAbsent(logSegmentsPath, newListenerSet); if (null != oldListenerSet) { listenerSet = oldListenerSet; if (!listeners.containsKey(logSegmentsPath)) { listeners.put(logSegmentsPath, listenerSet);
@Override public void remove(String componentName, String key) { if (!data.containsKey(componentName)) { return; } data.get(componentName).remove(key); }
@Override public void registerProcessingTimeTimer(long time, final TimeWindow window) { if (!processingTimeTimerFutures.containsKey(window)) { processingTimeTimerFutures.put(window, registerFuture(time, window, WindowedBoltExecutor.this)); } }
public void subscriptionAutomatically(final String topic) { if (!this.rebalanceImpl.getSubscriptionInner().containsKey(topic)) { try { SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), topic, SubscriptionData.SUB_ALL); this.rebalanceImpl.subscriptionInner.putIfAbsent(topic, subscriptionData); } catch (Exception ignore) { } } }
public <T> void registerImplementer(Class<T> configInterface, Class<? extends T> ...implementation) { List<Class> set; if (registry.containsKey(configInterface)) { set = registry.get(configInterface); } else {//TODO: concurrency issue -jj (someone sets set before putIfAbsent) List<Class> newSet = Collections.synchronizedList(new ArrayList<>()); set = registry.putIfAbsent(configInterface, newSet); if (set == null) { set = newSet; } } set.addAll(Arrays.asList(implementation)); }
NamespaceTableAndRegionInfo addNamespace(String namespace) { if (!nsStateCache.containsKey(namespace)) { NamespaceTableAndRegionInfo a1 = new NamespaceTableAndRegionInfo(namespace); nsStateCache.put(namespace, a1); } return nsStateCache.get(namespace); }
private void createColumnFamily(final String name) throws RocksDBException { COLUMN_FAMILY_LOCKS.putIfAbsent(name, new ReentrantLock()); final Lock l = COLUMN_FAMILY_LOCKS.get(name); l.lock(); try { if(!COLUMN_FAMILIES.containsKey(name)) { final ColumnFamilyOptions cfOptions = new ColumnFamilyOptions().optimizeLevelStyleCompaction(); final ColumnFamilyHandle cfHandle = rocksDb.createColumnFamily( new ColumnFamilyDescriptor(name.getBytes(UTF_8), cfOptions) ); COLUMN_FAMILIES.put(name, new ColumnFamily(cfHandle, cfOptions)); } } finally { l.unlock(); } }
@Override public void remove(String componentName, String key) { if (!data.containsKey(componentName)) { return; } data.get(componentName).remove(key); }
@Override public void registerEventTimeTimer(long time, final TimeWindow window) { if (!eventTimeTimerFutures.containsKey(window)) { eventTimeTimerFutures.put(window, registerFuture(time, window, WindowedBoltExecutor.this)); } }
/** * putIfAbsent works when the given key is not present */ public void testPutIfAbsent() { ConcurrentMap map = map5(); map.putIfAbsent(six, "Z"); assertTrue(map.containsKey(six)); }
private static Field getField(Class<?> cls, String fieldName) { Field result = null; if (CLASS_FIELD_CACHE.containsKey(cls) && CLASS_FIELD_CACHE.get(cls).containsKey(fieldName)) { return CLASS_FIELD_CACHE.get(cls).get(fieldName); } try { result = cls.getDeclaredField(fieldName); result.setAccessible(true); } catch (NoSuchFieldException e) { for (Field field : cls.getFields()) { if (fieldName.equals(field.getName()) && ReflectUtils.isPublicInstanceField(field)) { result = field; break; } } } if (result != null) { ConcurrentMap<String, Field> fields = CLASS_FIELD_CACHE.get(cls); if (fields == null) { fields = new ConcurrentHashMap<String, Field>(); CLASS_FIELD_CACHE.putIfAbsent(cls, fields); } fields = CLASS_FIELD_CACHE.get(cls); fields.putIfAbsent(fieldName, result); } return result; }
private static void updateChannelsResource(String resourceId, String clientIp, String applicationId) { ConcurrentMap<Integer, RpcContext> sourcePortMap = RM_CHANNELS.get(resourceId).get(applicationId).get(clientIp); for (ConcurrentMap.Entry<String, ConcurrentMap<String, ConcurrentMap<String, ConcurrentMap<Integer, RpcContext>>>> rmChannelEntry : RM_CHANNELS.entrySet()) { if (rmChannelEntry.getKey().equals(resourceId)) { continue; } ConcurrentMap<String, ConcurrentMap<String, ConcurrentMap<Integer, RpcContext>>> applicationIdMap = rmChannelEntry.getValue(); if (!applicationIdMap.containsKey(applicationId)) { continue; } ConcurrentMap<String, ConcurrentMap<Integer, RpcContext>> clientIpMap = applicationIdMap.get(applicationId); if (!clientIpMap.containsKey(clientIp)) { continue; } ConcurrentMap<Integer, RpcContext> portMap = clientIpMap.get(clientIp); for (ConcurrentMap.Entry<Integer, RpcContext> portMapEntry : portMap.entrySet()) { Integer port = portMapEntry.getKey(); if (!sourcePortMap.containsKey(port)) { RpcContext rpcContext = portMapEntry.getValue(); sourcePortMap.put(port, rpcContext); rpcContext.holdInResourceManagerChannels(resourceId, port); } } } }