Remove unnecessary use of java.util.Optional.
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.actuate.autoconfigure.config;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -96,9 +95,12 @@ public class PeerCacheHealthIndicatorConfiguration {
|
||||
|
||||
CacheServerFactoryBean cacheServerFactoryBean = (CacheServerFactoryBean) bean;
|
||||
|
||||
Optional.ofNullable(ObjectUtils.<ServerLoadProbe>get(bean,"serverLoadProbe"))
|
||||
.ifPresent(serverLoadProbe ->
|
||||
cacheServerFactoryBean.setServerLoadProbe(wrap(serverLoadProbe)));
|
||||
ServerLoadProbe serverLoadProbe =
|
||||
ObjectUtils.<ServerLoadProbe>get(bean, "serverLoadProbe");
|
||||
|
||||
if (serverLoadProbe != null) {
|
||||
cacheServerFactoryBean.setServerLoadProbe(wrap(serverLoadProbe));
|
||||
}
|
||||
}
|
||||
|
||||
return bean;
|
||||
|
||||
@@ -21,7 +21,6 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.server.CacheServer;
|
||||
@@ -89,8 +88,10 @@ public class GeodeCacheServerHealthIndicatorAutoConfigurationIntegrationTests ex
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableGemFireMockObjects
|
||||
@PeerCacheApplication(name = "GeodeCacheServerHealthIndicatorAutoConfigurationIntegrationTests",
|
||||
logLevel = GEODE_LOG_LEVEL)
|
||||
@PeerCacheApplication(
|
||||
name = "GeodeCacheServerHealthIndicatorAutoConfigurationIntegrationTests",
|
||||
logLevel = GEODE_LOG_LEVEL
|
||||
)
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean("MockCacheServer")
|
||||
@@ -126,7 +127,11 @@ public class GeodeCacheServerHealthIndicatorAutoConfigurationIntegrationTests ex
|
||||
|
||||
when(mockServerLoadProbe.getLoad(eq(mockServerMetrics))).thenReturn(mockServerLoad);
|
||||
|
||||
Optional.ofNullable(mockCacheServer.getLoadProbe()).ifPresent(it -> it.getLoad(mockServerMetrics));
|
||||
ServerLoadProbe serverLoadProbe = mockCacheServer.getLoadProbe();
|
||||
|
||||
if (serverLoadProbe != null) {
|
||||
serverLoadProbe.getLoad(mockServerMetrics);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,9 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.actuate;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.geode.CancelCriterion;
|
||||
@@ -29,6 +26,7 @@ import org.apache.geode.distributed.DistributedSystem;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Status;
|
||||
import org.springframework.data.gemfire.util.CollectionUtils;
|
||||
import org.springframework.geode.boot.actuate.health.AbstractGeodeHealthIndicator;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -137,23 +135,11 @@ public class GeodeCacheHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
return healthBuilder -> getGemFireCache()
|
||||
.map(GemFireCache::getDistributedSystem)
|
||||
.map(distributedSystem -> healthBuilder
|
||||
.withDetail("geode.distributed-system.member-count", Optional.of(distributedSystem)
|
||||
.map(DistributedSystem::getAllOtherMembers)
|
||||
.map(Collection::size)
|
||||
.map(size -> size + 1)
|
||||
.orElse(1))
|
||||
.withDetail("geode.distributed-system.member-count", toMemberCount(distributedSystem))
|
||||
.withDetail("geode.distributed-system.connection", toConnectedNoConnectedString(distributedSystem.isConnected()))
|
||||
.withDetail("geode.distributed-system.reconnecting", toYesNoString(distributedSystem.isReconnecting()))
|
||||
.withDetail("geode.distributed-system.properties-location",
|
||||
Optional.ofNullable(DistributedSystem.getPropertiesFileURL())
|
||||
.map(URL::toExternalForm)
|
||||
.filter(StringUtils::hasText)
|
||||
.orElse(""))
|
||||
.withDetail("geode.distributed-system.security-properties-location",
|
||||
Optional.ofNullable(DistributedSystem.getSecurityPropertiesFileURL())
|
||||
.map(URL::toExternalForm)
|
||||
.filter(StringUtils::hasText)
|
||||
.orElse(""))
|
||||
.withDetail("geode.distributed-system.properties-location", toString(DistributedSystem.getPropertiesFileURL()))
|
||||
.withDetail("geode.distributed-system.security-properties-location", toString(DistributedSystem.getSecurityPropertiesFileURL()))
|
||||
)
|
||||
.orElse(healthBuilder);
|
||||
}
|
||||
@@ -171,7 +157,22 @@ public class GeodeCacheHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
.orElse(healthBuilder);
|
||||
}
|
||||
|
||||
private String emptyIfUnset(String value) {
|
||||
return StringUtils.hasText(value) ? value : "";
|
||||
}
|
||||
|
||||
private String toConnectedNoConnectedString(Boolean connected) {
|
||||
return Boolean.TRUE.equals(connected) ? "Connected" : "Not Connected";
|
||||
}
|
||||
|
||||
private int toMemberCount(DistributedSystem distributedSystem) {
|
||||
return CollectionUtils.nullSafeSize(distributedSystem.getAllOtherMembers()) + 1;
|
||||
}
|
||||
|
||||
private String toString(URL url) {
|
||||
|
||||
String urlString = url != null ? url.toExternalForm() : null;
|
||||
|
||||
return emptyIfUnset(urlString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.actuate;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -25,6 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.server.CacheServer;
|
||||
import org.apache.geode.cache.server.ServerLoad;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.data.gemfire.util.CacheUtils;
|
||||
@@ -112,14 +112,15 @@ public class GeodeCacheServersHealthIndicator extends AbstractGeodeHealthIndicat
|
||||
.withDetail(cacheServerMetricsKey(cacheServerIndex, "open-connection-count"), serverMetrics.getConnectionCount())
|
||||
.withDetail(cacheServerMetricsKey(cacheServerIndex, "subscription-connection-count"), serverMetrics.getSubscriptionConnectionCount());
|
||||
|
||||
Optional.ofNullable(cacheServer.getLoadProbe().getLoad(serverMetrics))
|
||||
.ifPresent(serverLoad -> {
|
||||
ServerLoad serverLoad = cacheServer.getLoadProbe().getLoad(serverMetrics);
|
||||
|
||||
builder.withDetail(cacheServerLoadKey(cacheServerIndex, "connection-load"), serverLoad.getConnectionLoad())
|
||||
.withDetail(cacheServerLoadKey(cacheServerIndex, "load-per-connection"), serverLoad.getLoadPerConnection())
|
||||
.withDetail(cacheServerLoadKey(cacheServerIndex, "subscription-connection-load"), serverLoad.getSubscriptionConnectionLoad())
|
||||
.withDetail(cacheServerLoadKey(cacheServerIndex, "load-per-subscription-connection"), serverLoad.getLoadPerSubscriptionConnection());
|
||||
});
|
||||
if (serverLoad != null) {
|
||||
|
||||
builder.withDetail(cacheServerLoadKey(cacheServerIndex, "connection-load"), serverLoad.getConnectionLoad())
|
||||
.withDetail(cacheServerLoadKey(cacheServerIndex, "load-per-connection"), serverLoad.getLoadPerConnection())
|
||||
.withDetail(cacheServerLoadKey(cacheServerIndex, "subscription-connection-load"), serverLoad.getSubscriptionConnectionLoad())
|
||||
.withDetail(cacheServerLoadKey(cacheServerIndex, "load-per-subscription-connection"), serverLoad.getLoadPerSubscriptionConnection());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.actuate;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -24,8 +23,10 @@ import java.util.Optional;
|
||||
|
||||
import org.apache.geode.cache.query.CqQuery;
|
||||
import org.apache.geode.cache.query.CqState;
|
||||
import org.apache.geode.cache.query.CqStatistics;
|
||||
import org.apache.geode.cache.query.Query;
|
||||
import org.apache.geode.cache.query.QueryService;
|
||||
import org.apache.geode.cache.query.QueryStatistics;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer;
|
||||
@@ -85,7 +86,7 @@ public class GeodeContinuousQueriesHealthIndicator extends AbstractGeodeHealthIn
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
protected void doHealthCheck(Health.Builder builder) {
|
||||
|
||||
if (getContinuousQueryListenerContainer().isPresent()) {
|
||||
|
||||
@@ -118,28 +119,34 @@ public class GeodeContinuousQueriesHealthIndicator extends AbstractGeodeHealthIn
|
||||
|
||||
builder.withDetail(continuousQueryKey(continuousQueryName,"oql-query-string"), continuousQuery.getQueryString())
|
||||
.withDetail(continuousQueryKey(continuousQueryName, "closed"), toYesNoString(continuousQuery.isClosed()))
|
||||
.withDetail(continuousQueryKey(continuousQueryName, "closing"), Optional.ofNullable(continuousQuery.getState())
|
||||
.map(CqState::isClosing)
|
||||
.map(this::toYesNoString)
|
||||
.orElse(UNKNOWN))
|
||||
.withDetail(continuousQueryKey(continuousQueryName, "closing"), toYesNoString(continuousQuery.getState()))
|
||||
.withDetail(continuousQueryKey(continuousQueryName, "durable"), toYesNoString(continuousQuery.isDurable()))
|
||||
.withDetail(continuousQueryKey(continuousQueryName, "running"), toYesNoString(continuousQuery.isRunning()))
|
||||
.withDetail(continuousQueryKey(continuousQueryName, "stopped"), toYesNoString(continuousQuery.isStopped()));
|
||||
|
||||
Optional.ofNullable(continuousQuery.getQuery())
|
||||
.map(Query::getStatistics)
|
||||
.ifPresent(queryStatistics ->
|
||||
Query query = continuousQuery.getQuery();
|
||||
|
||||
if (query != null) {
|
||||
|
||||
QueryStatistics queryStatistics = query.getStatistics();
|
||||
|
||||
if (queryStatistics != null) {
|
||||
builder.withDetail(continuousQueryQueryKey(continuousQueryName, "number-of-executions"), queryStatistics.getNumExecutions())
|
||||
.withDetail(continuousQueryQueryKey(continuousQueryName, "total-execution-time"), queryStatistics.getTotalExecutionTime()));
|
||||
.withDetail(continuousQueryQueryKey(continuousQueryName, "total-execution-time"), queryStatistics.getTotalExecutionTime());
|
||||
}
|
||||
}
|
||||
|
||||
Optional.ofNullable(continuousQuery.getStatistics())
|
||||
.ifPresent(continuousQueryStatistics ->
|
||||
builder.withDetail(continuousQueryStatisticsKey(continuousQueryName, "number-of-deletes"), continuousQueryStatistics.numDeletes())
|
||||
.withDetail(continuousQueryStatisticsKey(continuousQueryName, "number-of-events"), continuousQueryStatistics.numEvents())
|
||||
.withDetail(continuousQueryStatisticsKey(continuousQueryName, "number-of-inserts"), continuousQueryStatistics.numInserts())
|
||||
.withDetail(continuousQueryStatisticsKey(continuousQueryName, "number-of-updates"), continuousQueryStatistics.numUpdates()));
|
||||
CqStatistics continuousQueryStatistics = continuousQuery.getStatistics();
|
||||
|
||||
if (continuousQueryStatistics != null) {
|
||||
|
||||
builder.withDetail(continuousQueryStatisticsKey(continuousQueryName, "number-of-deletes"), continuousQueryStatistics.numDeletes())
|
||||
.withDetail(continuousQueryStatisticsKey(continuousQueryName, "number-of-events"), continuousQueryStatistics.numEvents())
|
||||
.withDetail(continuousQueryStatisticsKey(continuousQueryName, "number-of-inserts"), continuousQueryStatistics.numInserts())
|
||||
.withDetail(continuousQueryStatisticsKey(continuousQueryName, "number-of-updates"), continuousQueryStatistics.numUpdates());
|
||||
}
|
||||
});
|
||||
|
||||
builder.up();
|
||||
|
||||
return;
|
||||
@@ -159,4 +166,8 @@ public class GeodeContinuousQueriesHealthIndicator extends AbstractGeodeHealthIn
|
||||
private String continuousQueryStatisticsKey(String continuousQueryName, String suffix) {
|
||||
return String.format("geode.continuous-query.%1$s.statistics.%2$s", continuousQueryName, suffix);
|
||||
}
|
||||
|
||||
private String toYesNoString(CqState continuousQueryState) {
|
||||
return continuousQueryState != null ? toYesNoString(continuousQueryState.isClosing()) : UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,10 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.actuate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
@@ -88,9 +86,7 @@ public class GeodeGatewaySendersHealthIndicator extends AbstractGeodeHealthIndic
|
||||
.withDetail(gatewaySendersKey(gatewaySenderId, "batch-conflation-enabled"), toYesNoString(gatewaySender.isBatchConflationEnabled()))
|
||||
.withDetail(gatewaySendersKey(gatewaySenderId, "batch-size"), gatewaySender.getBatchSize())
|
||||
.withDetail(gatewaySendersKey(gatewaySenderId, "batch-time-interval"), gatewaySender.getBatchTimeInterval())
|
||||
.withDetail(gatewaySendersKey(gatewaySenderId, "disk-store-name"), Optional.ofNullable(gatewaySender.getDiskStoreName())
|
||||
.filter(StringUtils::hasText)
|
||||
.orElse(""))
|
||||
.withDetail(gatewaySendersKey(gatewaySenderId, "disk-store-name"), emptyIfUnset(gatewaySender.getDiskStoreName()))
|
||||
.withDetail(gatewaySendersKey(gatewaySenderId, "disk-synchronous"), toYesNoString(gatewaySender.isDiskSynchronous()))
|
||||
.withDetail(gatewaySendersKey(gatewaySenderId, "dispatcher-threads"), gatewaySender.getDispatcherThreads())
|
||||
.withDetail(gatewaySendersKey(gatewaySenderId, "max-queue-memory"), gatewaySender.getMaximumQueueMemory())
|
||||
@@ -113,6 +109,10 @@ public class GeodeGatewaySendersHealthIndicator extends AbstractGeodeHealthIndic
|
||||
builder.unknown();
|
||||
}
|
||||
|
||||
private String emptyIfUnset(String value) {
|
||||
return StringUtils.hasText(value) ? value : "";
|
||||
}
|
||||
|
||||
private String gatewaySendersKey(String id, String suffix) {
|
||||
return String.format("geode.gateway-sender.%1$s.%2$s", id, suffix);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.actuate;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -23,11 +22,13 @@ import java.util.Optional;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.query.Index;
|
||||
import org.apache.geode.cache.query.IndexStatistics;
|
||||
import org.apache.shiro.util.Assert;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.geode.boot.actuate.health.AbstractGeodeHealthIndicator;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The {@link GeodeIndexesHealthIndicator} class is a Spring Boot {@link HealthIndicator} providing details about
|
||||
@@ -104,23 +105,22 @@ public class GeodeIndexesHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
builder.withDetail(indexKey(indexName, "from-clause"), index.getFromClause())
|
||||
.withDetail(indexKey(indexName, "indexed-expression"), index.getIndexedExpression())
|
||||
.withDetail(indexKey(indexName, "projection-attributes"), index.getProjectionAttributes())
|
||||
.withDetail(indexKey(indexName, "region"), Optional.ofNullable(index.getRegion())
|
||||
.map(Region::getFullPath)
|
||||
.orElse(""))
|
||||
.withDetail(indexKey(indexName, "region"), toRegionPath(index.getRegion()))
|
||||
.withDetail(indexKey(indexName, "type"), String.valueOf(index.getType()));
|
||||
|
||||
Optional.ofNullable(index.getStatistics())
|
||||
.ifPresent(indexStatistics -> {
|
||||
IndexStatistics indexStatistics = index.getStatistics();
|
||||
|
||||
builder.withDetail(indexStatisticsKey(indexName, "number-of-bucket-indexes"), indexStatistics.getNumberOfBucketIndexes())
|
||||
.withDetail(indexStatisticsKey(indexName, "number-of-keys"), indexStatistics.getNumberOfKeys())
|
||||
.withDetail(indexStatisticsKey(indexName, "number-of-map-index-keys"), indexStatistics.getNumberOfMapIndexKeys())
|
||||
.withDetail(indexStatisticsKey(indexName, "number-of-values"), indexStatistics.getNumberOfValues())
|
||||
.withDetail(indexStatisticsKey(indexName, "number-of-updates"), indexStatistics.getNumUpdates())
|
||||
.withDetail(indexStatisticsKey(indexName, "read-lock-count"), indexStatistics.getReadLockCount())
|
||||
.withDetail(indexStatisticsKey(indexName, "total-update-time"), indexStatistics.getTotalUpdateTime())
|
||||
.withDetail(indexStatisticsKey(indexName, "total-uses"), indexStatistics.getTotalUses());
|
||||
});
|
||||
if (indexStatistics != null) {
|
||||
|
||||
builder.withDetail(indexStatisticsKey(indexName, "number-of-bucket-indexes"), indexStatistics.getNumberOfBucketIndexes())
|
||||
.withDetail(indexStatisticsKey(indexName, "number-of-keys"), indexStatistics.getNumberOfKeys())
|
||||
.withDetail(indexStatisticsKey(indexName, "number-of-map-index-keys"), indexStatistics.getNumberOfMapIndexKeys())
|
||||
.withDetail(indexStatisticsKey(indexName, "number-of-values"), indexStatistics.getNumberOfValues())
|
||||
.withDetail(indexStatisticsKey(indexName, "number-of-updates"), indexStatistics.getNumUpdates())
|
||||
.withDetail(indexStatisticsKey(indexName, "read-lock-count"), indexStatistics.getReadLockCount())
|
||||
.withDetail(indexStatisticsKey(indexName, "total-update-time"), indexStatistics.getTotalUpdateTime())
|
||||
.withDetail(indexStatisticsKey(indexName, "total-uses"), indexStatistics.getTotalUses());
|
||||
}
|
||||
});
|
||||
|
||||
builder.up();
|
||||
@@ -131,6 +131,10 @@ public class GeodeIndexesHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
builder.unknown();
|
||||
}
|
||||
|
||||
private String emptyIfUnset(String value) {
|
||||
return StringUtils.hasText(value) ? value : "";
|
||||
}
|
||||
|
||||
private String indexKey(String indexName, String suffix) {
|
||||
return String.format("geode.index.%1$s.%2$s", indexName, suffix);
|
||||
}
|
||||
@@ -138,4 +142,11 @@ public class GeodeIndexesHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
private String indexStatisticsKey(String indexName, String suffix) {
|
||||
return String.format("geode.index.%1$s.statistics.%2$s", indexName, suffix);
|
||||
}
|
||||
|
||||
private String toRegionPath(Region region) {
|
||||
|
||||
String regionPath = region != null ? region.getFullPath() : null;
|
||||
|
||||
return emptyIfUnset(regionPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.actuate;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -23,7 +22,11 @@ import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.geode.cache.EvictionAlgorithm;
|
||||
import org.apache.geode.cache.EvictionAttributes;
|
||||
import org.apache.geode.cache.ExpirationAttributes;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.PartitionAttributes;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.RegionAttributes;
|
||||
import org.apache.geode.internal.cache.LocalDataSet;
|
||||
@@ -89,7 +92,7 @@ public class GeodeRegionsHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
protected void doHealthCheck(Health.Builder builder) {
|
||||
|
||||
if (getGemFireCache().isPresent()) {
|
||||
|
||||
@@ -125,42 +128,42 @@ public class GeodeRegionsHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
|
||||
builder.withDetail(cacheRegionKey(regionName, "full-path"), region.getFullPath());
|
||||
|
||||
Optional.ofNullable(region.getAttributes())
|
||||
.ifPresent(regionAttributes -> builder
|
||||
.withDetail(cacheRegionKey(regionName, "cloning-enabled"), toYesNoString(regionAttributes.getCloningEnabled()))
|
||||
if (isRegionAttributesPresent(region)) {
|
||||
|
||||
RegionAttributes<?, ?> regionAttributes = region.getAttributes();
|
||||
|
||||
builder.withDetail(cacheRegionKey(regionName, "cloning-enabled"), toYesNoString(regionAttributes.getCloningEnabled()))
|
||||
.withDetail(cacheRegionKey(regionName, "data-policy"), String.valueOf(regionAttributes.getDataPolicy()))
|
||||
.withDetail(cacheRegionKey(regionName, "initial-capacity"), regionAttributes.getInitialCapacity())
|
||||
.withDetail(cacheRegionKey(regionName, "load-factor"), regionAttributes.getLoadFactor())
|
||||
.withDetail(cacheRegionKey(regionName, "key-constraint"), nullSafeClassName(regionAttributes.getKeyConstraint()))
|
||||
.withDetail(cacheRegionKey(regionName, "off-heap"), toYesNoString(regionAttributes.getOffHeap()))
|
||||
.withDetail(cacheRegionKey(regionName, "pool-name"), Optional.ofNullable(regionAttributes.getPoolName())
|
||||
.filter(StringUtils::hasText)
|
||||
.orElse(""))
|
||||
.withDetail(cacheRegionKey(regionName, "pool-name"), emptyIfUnset(regionAttributes.getPoolName()))
|
||||
.withDetail(cacheRegionKey(regionName, "scope"), String.valueOf(regionAttributes.getScope()))
|
||||
.withDetail(cacheRegionKey(regionName, "statistics-enabled"), toYesNoString(regionAttributes.getStatisticsEnabled()))
|
||||
.withDetail(cacheRegionKey(regionName, "value-constraint"), nullSafeClassName(regionAttributes.getValueConstraint())));
|
||||
.withDetail(cacheRegionKey(regionName, "value-constraint"), nullSafeClassName(regionAttributes.getValueConstraint())); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private BiConsumer<Region<?, ?>, Health.Builder> withPartitionRegionDetails() {
|
||||
|
||||
return (region, builder) -> {
|
||||
|
||||
String regionName = region.getName();
|
||||
if (isRegionAttributesPresent(region)) {
|
||||
|
||||
Optional.of(region)
|
||||
.filter(this::isRegionAttributesPresent)
|
||||
.map(Region::getAttributes)
|
||||
.map(RegionAttributes::getPartitionAttributes)
|
||||
.ifPresent(partitionAttributes -> builder
|
||||
.withDetail(cachePartitionRegionKey(regionName, "collocated-with"), Optional.ofNullable(partitionAttributes.getColocatedWith())
|
||||
.filter(StringUtils::hasText)
|
||||
.orElse(""))
|
||||
.withDetail(cachePartitionRegionKey(regionName, "local-max-memory"), partitionAttributes.getLocalMaxMemory())
|
||||
.withDetail(cachePartitionRegionKey(regionName, "redundant-copies"), partitionAttributes.getRedundantCopies())
|
||||
.withDetail(cachePartitionRegionKey(regionName, "total-max-memory"), partitionAttributes.getTotalMaxMemory())
|
||||
.withDetail(cachePartitionRegionKey(regionName, "total-number-of-buckets"), partitionAttributes.getTotalNumBuckets()));
|
||||
PartitionAttributes<?, ?> partitionAttributes = region.getAttributes().getPartitionAttributes();
|
||||
|
||||
if (partitionAttributes != null) {
|
||||
|
||||
String regionName = region.getName();
|
||||
|
||||
builder.withDetail(cachePartitionRegionKey(regionName, "collocated-with"), emptyIfUnset(partitionAttributes.getColocatedWith()))
|
||||
.withDetail(cachePartitionRegionKey(regionName, "local-max-memory"), partitionAttributes.getLocalMaxMemory())
|
||||
.withDetail(cachePartitionRegionKey(regionName, "redundant-copies"), partitionAttributes.getRedundantCopies())
|
||||
.withDetail(cachePartitionRegionKey(regionName, "total-max-memory"), partitionAttributes.getTotalMaxMemory())
|
||||
.withDetail(cachePartitionRegionKey(regionName, "total-number-of-buckets"), partitionAttributes.getTotalNumBuckets());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -168,23 +171,26 @@ public class GeodeRegionsHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
|
||||
return (region, builder) -> {
|
||||
|
||||
String regionName = region.getName();
|
||||
if (isRegionAttributesPresent(region)) {
|
||||
|
||||
Optional.of(region)
|
||||
.filter(this::isRegionAttributesPresent)
|
||||
.map(Region::getAttributes)
|
||||
.map(RegionAttributes::getEvictionAttributes)
|
||||
.ifPresent(evictionAttributes -> {
|
||||
EvictionAttributes evictionAttributes = region.getAttributes().getEvictionAttributes();
|
||||
|
||||
if (evictionAttributes != null) {
|
||||
|
||||
String regionName = region.getName();
|
||||
|
||||
builder.withDetail(cacheRegionEvictionKey(regionName, "action"), String.valueOf(evictionAttributes.getAction()))
|
||||
.withDetail(cacheRegionEvictionKey(regionName, "algorithm"), String.valueOf(evictionAttributes.getAlgorithm()));
|
||||
|
||||
// NOTE: Careful! Eviction Maximum does not apply when Eviction Algorithm is Heap LRU.
|
||||
Optional.ofNullable(evictionAttributes.getAlgorithm())
|
||||
.filter(it -> !it.isLRUHeap())
|
||||
.ifPresent(it -> builder
|
||||
.withDetail(cacheRegionEvictionKey(regionName,"maximum"), evictionAttributes.getMaximum()));
|
||||
});
|
||||
EvictionAlgorithm evictionAlgorithm = evictionAttributes.getAlgorithm();
|
||||
|
||||
// NOTE: Eviction Maximum does not apply when Eviction Algorithm is Heap LRU.
|
||||
if (evictionAlgorithm != null && !evictionAlgorithm.isLRUHeap()) {
|
||||
builder.withDetail(cacheRegionEvictionKey(regionName,"maximum"),
|
||||
evictionAttributes.getMaximum());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -192,23 +198,26 @@ public class GeodeRegionsHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
|
||||
return (region, builder) -> {
|
||||
|
||||
String regionName = region.getName();
|
||||
if (isRegionAttributesPresent(region)) {
|
||||
|
||||
Optional.of(region)
|
||||
.filter(this::isRegionAttributesPresent)
|
||||
.map(Region::getAttributes)
|
||||
.map(RegionAttributes::getEntryTimeToLive)
|
||||
.ifPresent(expirationAttributes -> builder
|
||||
.withDetail(cacheRegionExpirationKey(regionName, "entry.ttl.action"), String.valueOf(expirationAttributes.getAction()))
|
||||
.withDetail(cacheRegionExpirationKey(regionName, "entry.ttl.timeout"), expirationAttributes.getTimeout()));
|
||||
String regionName = region.getName();
|
||||
|
||||
Optional.of(region)
|
||||
.filter(this::isRegionAttributesPresent)
|
||||
.map(Region::getAttributes)
|
||||
.map(RegionAttributes::getEntryIdleTimeout)
|
||||
.ifPresent(expirationAttributes -> builder
|
||||
.withDetail(cacheRegionExpirationKey(regionName, "entry.tti.action"), String.valueOf(expirationAttributes.getAction()))
|
||||
.withDetail(cacheRegionExpirationKey(regionName, "entry.tti.timeout"), expirationAttributes.getTimeout()));
|
||||
RegionAttributes<?, ?> regionAttributes = region.getAttributes();
|
||||
|
||||
ExpirationAttributes entryTimeToLive = regionAttributes.getEntryTimeToLive();
|
||||
|
||||
if (entryTimeToLive != null) {
|
||||
builder.withDetail(cacheRegionExpirationKey(regionName, "entry.ttl.action"), String.valueOf(entryTimeToLive.getAction()))
|
||||
.withDetail(cacheRegionExpirationKey(regionName, "entry.ttl.timeout"), entryTimeToLive.getTimeout());
|
||||
}
|
||||
|
||||
ExpirationAttributes entryIdleTimeout = regionAttributes.getEntryIdleTimeout();
|
||||
|
||||
if (entryIdleTimeout != null) {
|
||||
builder.withDetail(cacheRegionExpirationKey(regionName, "entry.tti.action"), String.valueOf(entryIdleTimeout.getAction()))
|
||||
.withDetail(cacheRegionExpirationKey(regionName, "entry.tti.timeout"), entryIdleTimeout.getTimeout());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -241,18 +250,11 @@ public class GeodeRegionsHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
}
|
||||
|
||||
private boolean isRegionAttributesPresent(Region<?, ?> region) {
|
||||
|
||||
return Optional.ofNullable(region)
|
||||
.map(Region::getAttributes)
|
||||
.isPresent();
|
||||
return region != null && region.getAttributes() != null;
|
||||
}
|
||||
|
||||
private boolean isStatisticsEnabled(Region<?, ?> region) {
|
||||
|
||||
return Optional.ofNullable(region)
|
||||
.map(Region::getAttributes)
|
||||
.filter(RegionAttributes::getStatisticsEnabled)
|
||||
.isPresent();
|
||||
return isRegionAttributesPresent(region) && region.getAttributes().getStatisticsEnabled();
|
||||
}
|
||||
|
||||
private String cachePartitionRegionKey(String regionName, String suffix) {
|
||||
@@ -274,4 +276,8 @@ public class GeodeRegionsHealthIndicator extends AbstractGeodeHealthIndicator {
|
||||
private String cacheRegionStatisticsKey(String regionName, String suffix) {
|
||||
return cacheRegionKey(regionName, String.format("statistics.%s", suffix));
|
||||
}
|
||||
|
||||
private String emptyIfUnset(String value) {
|
||||
return StringUtils.hasText(value) ? value : "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.actuate.health.support;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -49,11 +48,11 @@ public class RegionStatisticsResolver {
|
||||
|
||||
public static CacheStatistics resolve(Region<?, ?> region) {
|
||||
|
||||
return Optional.ofNullable(region)
|
||||
.map(it -> PartitionRegionHelper.isPartitionedRegion(it)
|
||||
return region != null
|
||||
? PartitionRegionHelper.isPartitionedRegion(region)
|
||||
? new PartitionRegionCacheStatistics(region)
|
||||
: it.getStatistics())
|
||||
.orElse(null);
|
||||
: region.getStatistics()
|
||||
: null;
|
||||
}
|
||||
|
||||
protected static class PartitionRegionCacheStatistics implements CacheStatistics {
|
||||
|
||||
@@ -90,9 +90,11 @@ public class CacheNameAutoConfiguration {
|
||||
|
||||
private void configureCacheName(Environment environment, CacheFactoryBean cacheFactoryBean) {
|
||||
|
||||
Optional.of(environment)
|
||||
.map(this::resolveSpringApplicationName)
|
||||
.ifPresent(springApplicationName -> setGemFireName(cacheFactoryBean, springApplicationName));
|
||||
String springApplicationName = resolveSpringApplicationName(environment);
|
||||
|
||||
if (StringUtils.hasText(springApplicationName)) {
|
||||
setGemFireName(cacheFactoryBean, springApplicationName);
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveSpringApplicationName(Environment environment) {
|
||||
|
||||
@@ -13,11 +13,9 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.autoconfigure;
|
||||
|
||||
import static org.springframework.data.gemfire.util.CollectionUtils.asSet;
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -41,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.springframework.data.gemfire.cache.GemfireCacheManager;
|
||||
import org.springframework.data.gemfire.cache.config.EnableGemfireCaching;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -90,8 +89,10 @@ public class CachingProviderAutoConfiguration {
|
||||
}
|
||||
|
||||
GemfireCacheManager getCacheManager() {
|
||||
return Optional.ofNullable(this.cacheManager)
|
||||
.orElseThrow(() -> newIllegalStateException("GemfireCacheManager was not properly configured"));
|
||||
|
||||
Assert.state(this.cacheManager != null, "GemfireCacheManager was not properly configured");
|
||||
|
||||
return this.cacheManager;
|
||||
}
|
||||
|
||||
Optional<CacheManagerCustomizers> getCacheManagerCustomizers() {
|
||||
@@ -115,10 +116,7 @@ public class CachingProviderAutoConfiguration {
|
||||
|
||||
String springCacheType = context.getEnvironment().getProperty(SPRING_CACHE_TYPE_PROPERTY);
|
||||
|
||||
return Optional.ofNullable(springCacheType)
|
||||
.filter(StringUtils::hasText)
|
||||
.map(it -> SPRING_CACHE_TYPES.contains(it.trim().toLowerCase()))
|
||||
.orElse(true);
|
||||
return !StringUtils.hasText(springCacheType) || SPRING_CACHE_TYPES.contains(springCacheType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.autoconfigure;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -116,10 +115,7 @@ public class ClientSecurityAutoConfiguration {
|
||||
}
|
||||
|
||||
private boolean isCloudFoundryEnvironment(Environment environment) {
|
||||
|
||||
return Optional.ofNullable(environment)
|
||||
.filter(CloudPlatform.CLOUD_FOUNDRY::isActive)
|
||||
.isPresent();
|
||||
return environment != null && CloudPlatform.CLOUD_FOUNDRY.isActive(environment);
|
||||
}
|
||||
|
||||
private boolean isEnabled(Environment environment) {
|
||||
|
||||
@@ -13,12 +13,10 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.autoconfigure;
|
||||
|
||||
import static org.springframework.data.gemfire.util.CollectionUtils.asSet;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -128,10 +126,8 @@ public class SpringSessionAutoConfiguration {
|
||||
String springSessionStoreTypeValue =
|
||||
context.getEnvironment().getProperty(SPRING_SESSION_STORE_TYPE_PROPERTY);
|
||||
|
||||
return Optional.ofNullable(springSessionStoreTypeValue)
|
||||
.filter(StringUtils::hasText)
|
||||
.map(it -> SPRING_SESSION_STORE_TYPES.contains(it.trim().toLowerCase()))
|
||||
.orElse(true);
|
||||
return !StringUtils.hasText(springSessionStoreTypeValue)
|
||||
|| SPRING_SESSION_STORE_TYPES.contains(springSessionStoreTypeValue.trim().toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +129,9 @@ public class SslAutoConfiguration {
|
||||
|
||||
private static String resolveTrustedKeystoreName(Environment environment) {
|
||||
|
||||
return Optional.ofNullable(environment)
|
||||
.filter(it -> environment.containsProperty(TRUSTED_KEYSTORE_FILENAME_PROPERTY))
|
||||
.map(it -> environment.getProperty(TRUSTED_KEYSTORE_FILENAME_PROPERTY))
|
||||
.orElse(TRUSTED_KEYSTORE_FILENAME);
|
||||
return environment != null && environment.containsProperty(TRUSTED_KEYSTORE_FILENAME_PROPERTY)
|
||||
? environment.getProperty(TRUSTED_KEYSTORE_FILENAME_PROPERTY)
|
||||
: TRUSTED_KEYSTORE_FILENAME;
|
||||
}
|
||||
|
||||
private static Optional<String> resolveKeyStoreFromClassPathAsPathname(Environment environment) {
|
||||
|
||||
@@ -13,16 +13,13 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package example.app.service;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import example.app.model.Author;
|
||||
import example.app.model.Book;
|
||||
@@ -52,8 +49,9 @@ public class BookService {
|
||||
|
||||
protected BookRepository getBookRepository() {
|
||||
|
||||
return Optional.ofNullable(this.bookRepository)
|
||||
.orElseThrow(() -> newIllegalStateException("BookRepository was not properly configured"));
|
||||
Assert.state(this.bookRepository != null, "BookRepository was not properly configured");
|
||||
|
||||
return this.bookRepository;
|
||||
}
|
||||
|
||||
public List<Book> findByAuthor(Author author) {
|
||||
|
||||
@@ -67,8 +67,8 @@ public class SpringBootApacheGeodeClientCacheApplicationIntegrationTests extends
|
||||
public void clientCacheAndClientRegionAreAvailable() {
|
||||
|
||||
Optional.ofNullable(this.clientCache)
|
||||
.filter(it -> it instanceof GemFireCacheImpl)
|
||||
.map(it -> (GemFireCacheImpl) it)
|
||||
.filter(GemFireCacheImpl.class::isInstance)
|
||||
.map(GemFireCacheImpl.class::cast)
|
||||
.map(it -> assertThat(it.isClient()).isTrue())
|
||||
.orElseThrow(() -> newIllegalStateException("ClientCache was null"));
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ public class SpringBootApacheGeodePeerCacheApplicationIntegrationTests extends I
|
||||
public void peerCacheWithPeerLocalRegionAreAvailable() {
|
||||
|
||||
Optional.ofNullable(this.peerCache)
|
||||
.filter(it -> it instanceof GemFireCacheImpl)
|
||||
.map(it -> (GemFireCacheImpl) it)
|
||||
.filter(GemFireCacheImpl.class::isInstance)
|
||||
.map(GemFireCacheImpl.class::cast)
|
||||
.map(it -> assertThat(it.isClient()).isFalse())
|
||||
.orElseThrow(() -> newIllegalStateException("Peer cache was null"));
|
||||
|
||||
|
||||
@@ -108,8 +108,9 @@ public class AutoConfiguredFunctionExecutionsIntegrationTests extends Integratio
|
||||
private Object extractResult(Object result) {
|
||||
|
||||
return Optional.ofNullable(result)
|
||||
.filter(it -> it instanceof Iterable)
|
||||
.map(it -> ((Iterable) it).iterator())
|
||||
.filter(Iterable.class::isInstance)
|
||||
.map(Iterable.class::cast)
|
||||
.map(Iterable::iterator)
|
||||
.filter(Iterator::hasNext)
|
||||
.map(Iterator::next)
|
||||
.map(this::extractResult)
|
||||
|
||||
@@ -13,18 +13,15 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.boot.autoconfigure.repository.service;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.springframework.geode.boot.autoconfigure.repository.model.Customer;
|
||||
import org.springframework.geode.boot.autoconfigure.repository.repo.CustomerRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* The {@link CustomerService} class is an application service for managing {@link Customer Customers}.
|
||||
@@ -48,8 +45,10 @@ public class CustomerService {
|
||||
|
||||
public CustomerRepository getCustomerRepository() {
|
||||
|
||||
return Optional.ofNullable(this.customerRepository)
|
||||
.orElseThrow(() -> newIllegalStateException("CustomerRepository was not properly configured"));
|
||||
Assert.state(this.customerRepository != null,
|
||||
"CustomerRepository was not properly configured");
|
||||
|
||||
return this.customerRepository;
|
||||
}
|
||||
|
||||
public Optional<Customer> findBy(String name) {
|
||||
@@ -62,15 +61,12 @@ public class CustomerService {
|
||||
|
||||
public Customer save(Customer customer) {
|
||||
|
||||
return Optional.ofNullable(customer)
|
||||
.map(it -> {
|
||||
Assert.state(customer != null, "Customer is required");
|
||||
|
||||
if (customer.isNew()) {
|
||||
customer.identifiedBy(nextId());
|
||||
}
|
||||
if (customer.isNew()) {
|
||||
customer = customer.identifiedBy(nextId());
|
||||
}
|
||||
|
||||
return getCustomerRepository().save(customer);
|
||||
})
|
||||
.orElseThrow(() -> newIllegalArgumentException("Customer is required"));
|
||||
return getCustomerRepository().save(customer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,20 +108,23 @@ public class DurableClientConfiguration extends AbstractAnnotationConfigSupport
|
||||
|
||||
protected Integer getDurableClientTimeout() {
|
||||
|
||||
return Optional.ofNullable(this.durableClientTimeout)
|
||||
.orElse(DEFAULT_DURABLE_CLIENT_TIMEOUT);
|
||||
return this.durableClientTimeout != null
|
||||
? this.durableClientTimeout
|
||||
: DEFAULT_DURABLE_CLIENT_TIMEOUT;
|
||||
}
|
||||
|
||||
protected Boolean getKeepAlive() {
|
||||
|
||||
return Optional.ofNullable(this.keepAlive)
|
||||
.orElse(DEFAULT_KEEP_ALIVE);
|
||||
return this.keepAlive != null
|
||||
? this.keepAlive
|
||||
: DEFAULT_KEEP_ALIVE;
|
||||
}
|
||||
|
||||
protected Boolean getReadyForEvents() {
|
||||
|
||||
return Optional.ofNullable(this.readyForEvents)
|
||||
.orElse(DEFAULT_READY_FOR_EVENTS);
|
||||
return this.readyForEvents != null
|
||||
? this.readyForEvents
|
||||
: DEFAULT_READY_FOR_EVENTS;
|
||||
}
|
||||
|
||||
protected Logger getLogger() {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.core.env.support;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||
@@ -256,8 +255,8 @@ public class CloudCacheService extends Service {
|
||||
int index = String.valueOf(value).trim().indexOf("[");
|
||||
|
||||
return index > 0 ? value.trim().substring(0, index).trim()
|
||||
: (index != 0 && StringUtils.hasText(value) ? value.trim()
|
||||
: DEFAULT_LOCATOR_HOST);
|
||||
: index != 0 && StringUtils.hasText(value) ? value.trim()
|
||||
: DEFAULT_LOCATOR_HOST;
|
||||
}
|
||||
|
||||
private static int parsePort(String value) {
|
||||
@@ -281,6 +280,7 @@ public class CloudCacheService extends Service {
|
||||
* @param port {@link Integer} specifying the port number on which this {@link Locator} is listening.
|
||||
*/
|
||||
private Locator(String host, Integer port) {
|
||||
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
@@ -293,10 +293,7 @@ public class CloudCacheService extends Service {
|
||||
* @return the {@link String name} of the host on which this {@link Locator} is running.
|
||||
*/
|
||||
public String getHost() {
|
||||
|
||||
return Optional.ofNullable(this.host)
|
||||
.filter(StringUtils::hasText)
|
||||
.orElse(DEFAULT_LOCATOR_HOST);
|
||||
return StringUtils.hasText(this.host) ? this.host : DEFAULT_LOCATOR_HOST;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,9 +304,7 @@ public class CloudCacheService extends Service {
|
||||
* @return the {@link Integer port} on which this {@link Locator} is listening.
|
||||
*/
|
||||
public int getPort() {
|
||||
|
||||
return Optional.ofNullable(this.port)
|
||||
.orElse(DEFAULT_LOCATOR_PORT);
|
||||
return this.port != null ? this.port : DEFAULT_LOCATOR_PORT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -190,11 +190,17 @@ public abstract class ObjectUtils extends org.springframework.util.ObjectUtils {
|
||||
Assert.notNull(obj, "Object is required");
|
||||
Assert.hasText(fieldName, String.format("Field name [%s] is required", fieldName));
|
||||
|
||||
return Optional.ofNullable(ReflectionUtils.findField(obj.getClass(), fieldName))
|
||||
.map(ObjectUtils::makeAccessible)
|
||||
.map(field -> ObjectUtils.<T>get(obj, field))
|
||||
.orElseThrow(() -> newIllegalArgumentException("No field with name [%s] exists on object of type [%s]",
|
||||
fieldName, ObjectUtils.nullSafeClassName(obj)));
|
||||
Field field = ReflectionUtils.findField(obj.getClass(), fieldName);
|
||||
|
||||
if (field != null) {
|
||||
|
||||
field = makeAccessible(field);
|
||||
|
||||
return get(obj, field);
|
||||
}
|
||||
|
||||
throw newIllegalArgumentException("No field with name [%s] exists on object of type [%s]",
|
||||
fieldName, ObjectUtils.nullSafeClassName(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,17 +246,23 @@ public abstract class ObjectUtils extends org.springframework.util.ObjectUtils {
|
||||
}
|
||||
|
||||
public static Constructor makeAccessible(Constructor<?> constructor) {
|
||||
|
||||
ReflectionUtils.makeAccessible(constructor);
|
||||
|
||||
return constructor;
|
||||
}
|
||||
|
||||
public static Field makeAccessible(Field field) {
|
||||
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
public static Method makeAccessible(Method method) {
|
||||
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.data.gemfire.function.config.AbstractFunctionExecutionConfigurationSource;
|
||||
import org.springframework.data.gemfire.function.config.AnnotationFunctionExecutionConfigurationSource;
|
||||
import org.springframework.data.gemfire.function.config.FunctionExecutionBeanDefinitionRegistrar;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* The {@link AbstractFunctionExecutionAutoConfigurationExtension} class extends SDG's {@link FunctionExecutionBeanDefinitionRegistrar}
|
||||
@@ -60,8 +61,9 @@ public abstract class AbstractFunctionExecutionAutoConfigurationExtension
|
||||
@SuppressWarnings("all")
|
||||
protected BeanFactory getBeanFactory() {
|
||||
|
||||
return Optional.ofNullable(this.beanFactory)
|
||||
.orElseThrow(() -> newIllegalStateException("BeanFactory was not properly configured"));
|
||||
Assert.state(this.beanFactory != null, "BeanFactory was not properly configured");
|
||||
|
||||
return this.beanFactory;
|
||||
}
|
||||
|
||||
protected abstract Class<?> getConfiguration();
|
||||
|
||||
@@ -13,12 +13,8 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.security.support;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -84,8 +80,11 @@ public class SecurityManagerProxy extends LazyWiringDeclarableSupport
|
||||
*/
|
||||
public static SecurityManagerProxy getInstance() {
|
||||
|
||||
return Optional.ofNullable(INSTANCE.get())
|
||||
.orElseThrow(() -> newIllegalStateException("SecurityManagerProxy was not configured"));
|
||||
SecurityManagerProxy securityManagerProxy = INSTANCE.get();
|
||||
|
||||
Assert.state(securityManagerProxy != null, "SecurityManagerProxy was not configured");
|
||||
|
||||
return securityManagerProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user