Java Code Examples for java.util.concurrent.ConcurrentNavigableMap#isEmpty()
The following examples show how to use
java.util.concurrent.ConcurrentNavigableMap#isEmpty() .
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: MemoryRawKVStore.java From sofa-jraft with Apache License 2.0 | 6 votes |
@Override public void deleteRange(final byte[] startKey, final byte[] endKey, final KVStoreClosure closure) { final Timer.Context timeCtx = getTimeContext("DELETE_RANGE"); try { final ConcurrentNavigableMap<byte[], byte[]> subMap = this.defaultDB.subMap(startKey, endKey); if (!subMap.isEmpty()) { subMap.clear(); } setSuccess(closure, Boolean.TRUE); } catch (final Exception e) { LOG.error("Fail to [DELETE_RANGE], ['[{}, {})'], {}.", BytesUtil.toHex(startKey), BytesUtil.toHex(endKey), StackTraceUtil.stackTrace(e)); setCriticalError(closure, "Fail to [DELETE_RANGE]", e); } finally { timeCtx.stop(); } }
Example 2
Source File: AdapterImplementations.java From sling-org-apache-sling-models-impl with Apache License 2.0 | 6 votes |
/** * Remove implementation mapping for the given adapter type. * @param adapterTypeName Adapter type name * @param implTypeName Implementation type name */ public void remove(String adapterTypeName, String implTypeName) { String key = adapterTypeName; if (StringUtils.equals(adapterTypeName, implTypeName)) { modelClasses.remove(key); } else { // although we already use a ConcurrentMap synchronize explicitly because we apply non-atomic operations on it synchronized (adapterImplementations) { ConcurrentNavigableMap<String,ModelClass<?>> implementations = adapterImplementations.get(key); if (implementations != null) { implementations.remove(implTypeName); if (implementations.isEmpty()) { adapterImplementations.remove(key); } } } } }
Example 3
Source File: AdapterImplementations.java From sling-org-apache-sling-models-impl with Apache License 2.0 | 6 votes |
/** * @param adapterType the type to check * @return {@code true} in case the given type is a model (may be with a different adapter class) */ @SuppressWarnings("unchecked") public <ModelType> boolean isModelClass(Class<ModelType> adapterType) { String key = adapterType.getName(); // lookup in cache for models without adapter classes ModelClass<ModelType> modelClass = (ModelClass<ModelType>)modelClasses.get(key); if (modelClass!=null) { return true; } // not found? look in cache with adapter classes ConcurrentNavigableMap<String,ModelClass<?>> implementations = adapterImplementations.get(key); if (implementations==null || implementations.isEmpty()) { return false; } return true; }
Example 4
Source File: ConsistentClusterRoutingService.java From iotplatform with Apache License 2.0 | 6 votes |
@Override public Optional<ServerAddress> resolveByUuid(UUID uuid) { Assert.notNull(uuid); if (circle.isEmpty()) { return Optional.empty(); } Long hash = hashFunction.newHasher().putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits()) .hash().asLong(); if (!circle.containsKey(hash)) { ConcurrentNavigableMap<Long, ServerInstance> tailMap = circle.tailMap(hash); hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey(); } ServerInstance result = circle.get(hash); if (!currentServer.equals(result)) { return Optional.of(result.getServerAddress()); } else { return Optional.empty(); } }
Example 5
Source File: DeepPagingCache.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
public DeepPageContainer lookup(DeepPageKey key, int skipTo) { LOG.debug("Looking up DeepPageContainer for skipTo [{0}] with key hashcode [{1}] and key [{2}]", skipTo, key.hashCode(), key); DeepPageKeyPlusPosition k = new DeepPageKeyPlusPosition(skipTo, key); DeepPageContainer deepPageContainer = _lruCache.get(k); if (deepPageContainer != null) { _hits.mark(); return deepPageContainer; } ConcurrentNavigableMap<DeepPageKeyPlusPosition, DeepPageContainer> headMap = _positionCache.headMap(k, true); if (headMap == null || headMap.isEmpty()) { _misses.mark(); return null; } Entry<DeepPageKeyPlusPosition, DeepPageContainer> firstEntry = headMap.lastEntry(); DeepPageKeyPlusPosition dpkpp = firstEntry.getKey(); if (dpkpp._deepPageKey.equals(key)) { _hits.mark(); return firstEntry.getValue(); } _misses.mark(); return null; }
Example 6
Source File: MemoryRawKVStore.java From sofa-jraft with Apache License 2.0 | 5 votes |
@Override public byte[] jumpOver(final byte[] startKey, final long distance) { final Timer.Context timeCtx = getTimeContext("JUMP_OVER"); try { final byte[] realStartKey = BytesUtil.nullToEmpty(startKey); final ConcurrentNavigableMap<byte[], byte[]> tailMap = this.defaultDB.tailMap(realStartKey); if (tailMap.isEmpty()) { return null; } long approximateKeys = 0; byte[] lastKey = null; for (final byte[] key : tailMap.keySet()) { lastKey = key; if (++approximateKeys >= distance) { break; } } if (lastKey == null) { return null; } final byte[] endKey = new byte[lastKey.length]; System.arraycopy(lastKey, 0, endKey, 0, lastKey.length); return endKey; } finally { timeCtx.stop(); } }
Example 7
Source File: AdapterImplementations.java From sling-org-apache-sling-models-impl with Apache License 2.0 | 5 votes |
/** * Lookup the best-matching implementation for the given adapter type by enquiring the {@link ImplementationPicker} services. * @param adapterType Adapter type * @param adaptable Adaptable for reference * @return Implementation type or null if none detected */ @SuppressWarnings("unchecked") public <ModelType> ModelClass<ModelType> lookup(Class<ModelType> adapterType, Object adaptable) { String key = adapterType.getName(); // lookup in cache for models without adapter classes ModelClass<ModelType> modelClass = (ModelClass<ModelType>)modelClasses.get(key); if (modelClass!=null) { return modelClass; } // not found? look in cache with adapter classes ConcurrentNavigableMap<String,ModelClass<?>> implementations = adapterImplementations.get(key); if (implementations==null || implementations.isEmpty()) { return null; } Collection<ModelClass<?>> implementationsCollection = implementations.values(); ModelClass<?>[] implementationWrappersArray = implementationsCollection.toArray(new ModelClass<?>[implementationsCollection.size()]); // prepare array for implementation picker Class<?>[] implementationsArray = new Class<?>[implementationsCollection.size()]; for (int i=0; i<implementationWrappersArray.length; i++) { implementationsArray[i] = implementationWrappersArray[i].getType(); } for (ImplementationPicker picker : this.sortedImplementationPickers) { Class<?> implementation = picker.pick(adapterType, implementationsArray, adaptable); if (implementation != null) { for (int i=0; i<implementationWrappersArray.length; i++) { if (implementation==implementationWrappersArray[i].getType()) { return (ModelClass<ModelType>)implementationWrappersArray[i]; } } } } return null; }
Example 8
Source File: MetaRegionLocationCache.java From hbase with Apache License 2.0 | 5 votes |
/** * @return Optional list of HRegionLocations for meta replica(s), null if the cache is empty. * */ public Optional<List<HRegionLocation>> getMetaRegionLocations() { ConcurrentNavigableMap<Integer, HRegionLocation> snapshot = cachedMetaLocations.tailMap(cachedMetaLocations.firstKey()); if (snapshot.isEmpty()) { // This could be possible if the master has not successfully initialized yet or meta region // is stuck in some weird state. return Optional.empty(); } List<HRegionLocation> result = new ArrayList<>(); // Explicitly iterate instead of new ArrayList<>(snapshot.values()) because the underlying // ArrayValueCollection does not implement toArray(). snapshot.values().forEach(location -> result.add(location)); return Optional.of(result); }