Refine search
/** * Returns a reference to the configured {@link EvictionPolicyConfigurer} used to configure the Eviction policy * of a {@link Region}. * * @return a reference to the configured {@link EvictionPolicyConfigurer}. * @see org.springframework.data.gemfire.config.annotation.EvictionConfiguration.EvictionPolicyConfigurer */ protected EvictionPolicyConfigurer getEvictionPolicyConfigurer() { return Optional.ofNullable(this.evictionPolicyConfigurer).orElseThrow(() -> newIllegalStateException("EvictionPolicyConfigurer was not properly configured and initialized")); }
/** * @inheritDoc */ @Override public <T> Page<T> query(String query, String defaultField, int resultLimit, int pageSize, Class<T> projectionType) { throw newUnsupportedOperationException(RuntimeExceptionFactory.NOT_IMPLEMENTED); }
/** * Constructs and initializes an {@link RuntimeException} with the given {@link Throwable cause}, * {@link String message} and {@link Object arguments} used to format the message. * * @param cause {@link Throwable} identifying the reason the {@link RuntimeException} was thrown. * @param message {@link String} describing the {@link RuntimeException exception}. * @param args {@link Object arguments} used to replace format placeholders in the {@link String message}. * @return a new {@link RuntimeException} with the given {@link Throwable cause} and {@link String message}. * @see java.lang.RuntimeException */ public static RuntimeException newRuntimeException(Throwable cause, String message, Object... args) { return new RuntimeException(format(message, args), cause); }
/** * Constructs a new instance of {@link SchemaObjectDefinition} initialized with the specified {@link String name}. * * @param name {@link String name} given to the GemFire/Geode schema object; must not be {@literal null}. * @throws IllegalArgumentException if name is not specified. */ public SchemaObjectDefinition(String name) { this.name = Optional.ofNullable(name).filter(StringUtils::hasText) .orElseThrow(() -> newIllegalArgumentException("Name [%s] is required", name)); }
QueryService resolveQueryService() { return Optional.ofNullable(this.queryService) .orElseGet(() -> Optional.ofNullable(lookupQueryService()) .orElseThrow(() -> newIllegalStateException("QueryService is required to create an Index"))); }
Optional.<GemFireCache>ofNullable(getCache()).ifPresent(cache -> { Optional.ofNullable(cache.getDistributedSystem()) .map(DistributedSystem::getDistributedMember) .ifPresent(member -> throw newRuntimeException(cause, "Error occurred when initializing peer cache");
/** * Loads the configured data {@link Resource snapshot} into the given {@link Region}. * * @param region {@link Region} to load. * @return the given {@link Region}. * @throws RuntimeException if the snapshot load fails. * @see org.apache.geode.cache.Region#loadSnapshot(InputStream) */ protected Region<K, V> loadSnapshot(Region<K, V> region) { Optional.ofNullable(this.snapshot).ifPresent(snapshot -> { try { region.loadSnapshot(snapshot.getInputStream()); } catch (Exception cause) { throw newRuntimeException(cause, "Failed to load snapshot [%s]", snapshot); } }); return region; }
protected String getIndexName() { return Optional.ofNullable(this.indexName).filter(StringUtils::hasText).orElseThrow(() -> newIllegalStateException("Index name is required")); }
/** * Sets a reference to the Pivotal GemFire Cache for which the snapshot will be taken. * * @param cache the Pivotal GemFire Cache used to create an instance of CacheSnapshotService. * @throws IllegalArgumentException if the Cache reference is null. * @see org.apache.geode.cache.Cache * @see #getCache() */ public void setCache(Cache cache) { this.cache = Optional.ofNullable(cache) .orElseThrow(() -> newIllegalArgumentException("Cache must not be null")); }
private static Object constructInstance(Class<?> type, Object... constructorArguments) { return org.springframework.data.util.ReflectionUtils.findConstructor(type, constructorArguments) .map(constructor -> BeanUtils.instantiateClass(constructor, constructorArguments)) .orElseThrow(() -> newIllegalArgumentException( "No suitable constructor was found for type [%s] having parameters [%s]", type.getName(), stream(nullSafeArray(constructorArguments, Object.class)) .map(ObjectUtils::nullSafeClassName) .collect(Collectors.toList()))); }
public static void close(boolean throwOnError, Consumer<String> logger) { get().ifPresent(connection -> { try { connection.close(); } catch (ResourceException cause) { String message = String.format("Failed to close GemFire Connection: %s", cause.getMessage()); if (throwOnError) { throw newRuntimeException(cause, message); } else { logger.accept(message); } } }); } }
public static Component valueOfName(String name) { return Arrays.stream(values()) .filter(component -> component.name().equalsIgnoreCase(String.valueOf(name).trim())) .findFirst() .orElseThrow(() -> newIllegalArgumentException("Name [%s] is not a valid component", name)); }
@Override public TypeFilter getFilter(String expression, ClassLoader classLoader) throws ClassNotFoundException { Class<?> filterClass = classLoader.loadClass(expression); if (!TypeFilter.class.isAssignableFrom(filterClass)) { throw newIllegalArgumentException("Class is not assignable to [%s]: %s", TypeFilter.class.getName(), expression); } return (TypeFilter) BeanUtils.instantiateClass(filterClass); } };
/** * Constructs and initializes an {@link RuntimeException} with the given {@link String message} * and {@link Object arguments} used to format the message. * * @param message {@link String} describing the {@link RuntimeException exception}. * @param args {@link Object arguments} used to replace format placeholders in the {@link String message}. * @return a new {@link RuntimeException} with the given {@link String message}. * @see #newRuntimeException(Throwable, String, Object...) * @see java.lang.RuntimeException */ public static RuntimeException newRuntimeException(String message, Object... args) { return newRuntimeException(null, message, args); }
public IndexDefinition having(String expression) { this.expression = Optional.ofNullable(expression).filter(StringUtils::hasText) .orElseThrow(() -> newIllegalArgumentException("Expression is required")); return this; }
RegionService resolveCache() { return Optional.ofNullable(this.cache) .orElseGet(() -> Optional.ofNullable(GemfireUtils.resolveGemFireCache()) .orElseThrow(() -> newIllegalStateException("Cache is required"))); }
Optional.<GemFireCache>ofNullable(getCache()).ifPresent(cache -> { Optional.ofNullable(cache.getDistributedSystem()) .map(DistributedSystem::getDistributedMember) .ifPresent(member -> throw newRuntimeException(cause, "Error occurred when initializing peer cache");
/** * Loads the configured data {@link Resource snapshot} into the given {@link Region}. * * @param region {@link Region} to load. * @return the given {@link Region}. * @throws RuntimeException if the snapshot load fails. * @see org.apache.geode.cache.Region#loadSnapshot(InputStream) */ protected Region<K, V> loadSnapshot(Region<K, V> region) { Optional.ofNullable(this.snapshot).ifPresent(snapshot -> { try { region.loadSnapshot(snapshot.getInputStream()); } catch (Exception cause) { throw newRuntimeException(cause, "Failed to load snapshot [%s]", snapshot); } }); return region; }
private static Object constructInstance(Class<?> type, Object... constructorArguments) { return org.springframework.data.util.ReflectionUtils.findConstructor(type, constructorArguments) .map(constructor -> BeanUtils.instantiateClass(constructor, constructorArguments)) .orElseThrow(() -> newIllegalArgumentException( "No suitable constructor was found for type [%s] having parameters [%s]", type.getName(), stream(nullSafeArray(constructorArguments, Object.class)) .map(ObjectUtils::nullSafeClassName) .collect(Collectors.toList()))); }
public static void close(boolean throwOnError, Consumer<String> logger) { get().ifPresent(connection -> { try { connection.close(); } catch (ResourceException cause) { String message = String.format("Failed to close Pivotal GemFire Connection: %s", cause.getMessage()); if (throwOnError) { throw newRuntimeException(cause, message); } else { logger.accept(message); } } }); } }