From 59c721691b43250578bf4a633fce748a0cebbcd6 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Fri, 1 Mar 2019 09:47:12 +0800 Subject: [PATCH] Improve demo for Sentinel cluster flow control Signed-off-by: Eric Zhao --- .../csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java | 2 ++ .../sentinel-demo-cluster-server-alone/pom.xml | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java index d1199290..bb675a4e 100644 --- a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java +++ b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java @@ -16,6 +16,7 @@ package com.alibaba.csp.sentinel.demo.cluster.init; import java.util.List; +import java.util.Objects; import java.util.Optional; import com.alibaba.csp.sentinel.cluster.ClusterStateManager; @@ -157,6 +158,7 @@ public class DemoClusterInitFunc implements InitFunc { // Otherwise it's unassigned, should be set to NOT_STARTED. boolean canBeClient = groupList.stream() .flatMap(e -> e.getClientSet().stream()) + .filter(Objects::nonNull) .anyMatch(e -> e.equals(getCurrentMachineId())); return canBeClient ? ClusterStateManager.CLUSTER_CLIENT : ClusterStateManager.CLUSTER_NOT_STARTED; } diff --git a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-server-alone/pom.xml b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-server-alone/pom.xml index fbc0ff31..80626c9d 100644 --- a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-server-alone/pom.xml +++ b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-server-alone/pom.xml @@ -35,5 +35,10 @@ com.alibaba.csp sentinel-datasource-nacos + + ch.qos.logback + logback-classic + 1.2.3 + \ No newline at end of file