/** * Groups entries by the entry key. The entries will be grouped * until at least one group has up to {@code maxBatch} * entries or until the {@code entries} have been exhausted. * * @param entries the entries to be grouped by key * @param maxBatch the maximum size of a group * @return the grouped entries by entry key */ private static Map<Integer, List<Data>> nextBatch(Iterator<Entry<Integer, Data>> entries, int maxBatch) { Map<Integer, List<Data>> batch = createHashMap(maxBatch); while (entries.hasNext()) { Entry<Integer, Data> e = entries.next(); List<Data> partitionKeys = CollectionUtil.addToValueList(batch, e.getKey(), e.getValue()); if (partitionKeys.size() >= maxBatch) { break; } } return batch; }
private static Class<?> getCollectionType(Collection collection) throws Exception { if (collection == null || collection.isEmpty()) { return null; } Object targetObject = CollectionUtil.getItemAtPositionOrNull(collection, 0); if (targetObject == null) { for (Object object : collection) { if (object != null) { return object.getClass(); } } return null; } return targetObject.getClass(); }
/** * Returns {@code true} if the given collection is not {@code null} and not empty, otherwise returns {@code false}. * * @param collection the given collection * @return {@code true} if collection is not empty */ public static boolean isNotEmpty(Collection collection) { return !isEmpty(collection); }
@Override public void removeAll(Set<? extends K> keys) { long startNanos = nowInNanosOrDefault(); ensureOpen(); checkNotNull(keys, NULL_KEY_IS_NOT_ALLOWED); if (keys.isEmpty()) { return; } List<Data> dataKeys = new ArrayList<Data>(keys.size()); objectToDataCollection(keys, dataKeys, getSerializationService(), NULL_KEY_IS_NOT_ALLOWED); removeAllKeysInternal(keys, dataKeys, startNanos); }
protected void setLastTableIndex(List<Data> segment, int lastTableIndex) { if (isNotEmpty(segment)) { this.lastTableIndex = lastTableIndex; } }
private void invokeOnAllPartitions() { for (Map.Entry<Address, List<Integer>> mp : memberPartitions.entrySet()) { Address address = mp.getKey(); List<Integer> partitions = mp.getValue(); PartitionIteratingOperation op = new PartitionIteratingOperation(operationFactory, toIntArray(partitions)); Future future = operationService.createInvocationBuilder(serviceName, op, address) .setTryCount(TRY_COUNT) .setTryPauseMillis(TRY_PAUSE_MILLIS) .invoke(); futures.put(address, future); } }
@Override public Map<Integer, Object> invokeOnPartitions(String serviceName, OperationFactory operationFactory, int[] partitions) throws Exception { return invokeOnPartitions(serviceName, operationFactory, toIntegerList(partitions)); }
private DiscoveryStrategy buildDiscoveryStrategy(DiscoveryStrategyConfig config, List<DiscoveryStrategyFactory> candidateFactories) { for (DiscoveryStrategyFactory factory : candidateFactories) { Class<? extends DiscoveryStrategy> discoveryStrategyType = factory.getDiscoveryStrategyType(); String className = discoveryStrategyType.getName(); String factoryClassName = getFactoryClassName(config); if (className.equals(factoryClassName)) { Map<String, Comparable> properties = DiscoveryServicePropertiesUtil .prepareProperties(config.getProperties(), nullToEmpty(factory.getConfigurationProperties())); return factory.newDiscoveryStrategy(discoveryNode, logger, properties); } } throw new ValidationException( "There is no discovery strategy factory to create '" + config + "' Is it a typo in a strategy classname? " + "Perhaps you forgot to include implementation on a classpath?"); }
@Override public void removeAll(Set<? extends K> keys) { long startNanos = nowInNanosOrDefault(); ensureOpen(); checkNotNull(keys, NULL_KEY_IS_NOT_ALLOWED); if (keys.isEmpty()) { return; } List<Data> dataKeys = new ArrayList<Data>(keys.size()); objectToDataCollection(keys, dataKeys, getSerializationService(), NULL_KEY_IS_NOT_ALLOWED); removeAllKeysInternal(keys, dataKeys, startNanos); }
protected void setLastTableIndex(List<Data> segment, int lastTableIndex) { if (isNotEmpty(segment)) { this.lastTableIndex = lastTableIndex; } }
private void invokeOnAllPartitions() { if (memberPartitions.isEmpty()) { future.setResult(Collections.EMPTY_MAP); return; } for (final Map.Entry<Address, List<Integer>> mp : memberPartitions.entrySet()) { final Address address = mp.getKey(); List<Integer> partitions = mp.getValue(); PartitionIteratingOperation op = new PartitionIteratingOperation(operationFactory, toIntArray(partitions)); operationService.createInvocationBuilder(serviceName, op, address) .setTryCount(TRY_COUNT) .setTryPauseMillis(TRY_PAUSE_MILLIS) .invoke() .andThen(new FirstAttemptExecutionCallback(partitions)); } }
@Override public Map<Integer, Object> invokeOnPartitions(String serviceName, OperationFactory operationFactory, int[] partitions) throws Exception { return invokeOnPartitions(serviceName, operationFactory, toIntegerList(partitions)); }
private DiscoveryStrategy buildDiscoveryStrategy(DiscoveryStrategyConfig config, List<DiscoveryStrategyFactory> candidateFactories) { for (DiscoveryStrategyFactory factory : candidateFactories) { Class<? extends DiscoveryStrategy> discoveryStrategyType = factory.getDiscoveryStrategyType(); String className = discoveryStrategyType.getName(); String factoryClassName = getFactoryClassName(config); if (className.equals(factoryClassName)) { Map<String, Comparable> properties = DiscoveryServicePropertiesUtil .prepareProperties(config.getProperties(), nullToEmpty(factory.getConfigurationProperties())); return factory.newDiscoveryStrategy(discoveryNode, logger, properties); } } throw new ValidationException( "There is no discovery strategy factory to create '" + config + "' Is it a typo in a strategy classname? " + "Perhaps you forgot to include implementation on a classpath?"); }
/** * Returns {@code true} if the given collection is not {@code null} and not empty, otherwise returns {@code false}. * * @param collection the given collection * @return {@code true} if collection is not empty */ public static boolean isNotEmpty(Collection collection) { return !isEmpty(collection); }
@Override protected void loadAllInternal(boolean replaceExistingValues, Collection<?> keysParameter) { Collection<?> keys = serializeKeys ? objectToDataCollection(keysParameter, getSerializationService()) : keysParameter; try { super.loadAllInternal(replaceExistingValues, keys); } finally { for (Object key : keys) { invalidateNearCache(key); } } }
protected boolean advance() { if (lastTableIndex < 0) { lastTableIndex = Integer.MAX_VALUE; return false; } segment = fetch(); if (isNotEmpty(segment)) { index = 0; return true; } return false; }
private static Class<?> getCollectionType(Collection collection) throws Exception { if (collection == null || collection.isEmpty()) { return null; } Object targetObject = CollectionUtil.getItemAtPositionOrNull(collection, 0); if (targetObject == null) { for (Object object : collection) { if (object != null) { return object.getClass(); } } return null; } return targetObject.getClass(); }
private void invokeOnAllPartitions() { if (memberPartitions.isEmpty()) { future.setResult(Collections.EMPTY_MAP); if (callback != null) { callback.onResponse(Collections.EMPTY_MAP); } return; } for (final Map.Entry<Address, List<Integer>> mp : memberPartitions.entrySet()) { final Address address = mp.getKey(); List<Integer> partitions = mp.getValue(); PartitionIteratingOperation op = new PartitionIteratingOperation(operationFactory, toIntArray(partitions)); operationService.createInvocationBuilder(serviceName, op, address) .setTryCount(TRY_COUNT) .setTryPauseMillis(TRY_PAUSE_MILLIS) .invoke() .andThen(new FirstAttemptExecutionCallback(mp.getValue())); } }
/** * Groups entries by the entry key. The entries will be grouped * until at least one group has up to {@code maxBatch} * entries or until the {@code entries} have been exhausted. * * @param entries the entries to be grouped by key * @param maxBatch the maximum size of a group * @return the grouped entries by entry key */ private static Map<Integer, List<Data>> nextBatch(Iterator<Entry<Integer, Data>> entries, int maxBatch) { Map<Integer, List<Data>> batch = createHashMap(maxBatch); while (entries.hasNext()) { Entry<Integer, Data> e = entries.next(); List<Data> partitionKeys = CollectionUtil.addToValueList(batch, e.getKey(), e.getValue()); if (partitionKeys.size() >= maxBatch) { break; } } return batch; }
/** * @return {@code true} if this class contains any registered * listener for the cache represented with the supplied {@code cacheId} else returns {@code false} */ public boolean hasListener(String cacheId) { Collection<ListenerInfo> listenerInfos = registrations.get(cacheId); return !isEmpty(listenerInfos); }