From 5b1640bb0e4ba21add8b414415d3c5146ff075b8 Mon Sep 17 00:00:00 2001 From: nytta <1846770750@qq.com> Date: Sun, 25 Nov 2018 23:08:57 +0800 Subject: [PATCH] failover cluster make attribute name to be final --- .../src/main/java/lam/cobia/cluster/AbstractCluster.java | 9 +++++---- .../src/main/java/lam/cobia/cluster/FailoverCluster.java | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cobia-core/src/main/java/lam/cobia/cluster/AbstractCluster.java b/cobia-core/src/main/java/lam/cobia/cluster/AbstractCluster.java index 826ca24..710cbc8 100644 --- a/cobia-core/src/main/java/lam/cobia/cluster/AbstractCluster.java +++ b/cobia-core/src/main/java/lam/cobia/cluster/AbstractCluster.java @@ -39,19 +39,20 @@ public abstract class AbstractCluster implements Cluster, RegistrySubcribe private LoadBalance loadBalance; - protected String name; + protected final String name; /** * should call setInterfaceClass, setConsumers, setLoadBalance method after AbstractCluster instance is created. */ - public AbstractCluster() { - + public AbstractCluster(String name) { + this.name = name; } - public AbstractCluster(Class interfaceClass, List> consumers, LoadBalance loadBalance) { + public AbstractCluster(String name, Class interfaceClass, List> consumers, LoadBalance loadBalance) { if (consumers == null || consumers.isEmpty()) { throw new IllegalStateException("List consumers is null or empty."); } + this.name = name; this.interfaceClass = interfaceClass; this.consumers = consumers; this.loadBalance = loadBalance; diff --git a/cobia-core/src/main/java/lam/cobia/cluster/FailoverCluster.java b/cobia-core/src/main/java/lam/cobia/cluster/FailoverCluster.java index 703a87a..1d9077f 100644 --- a/cobia-core/src/main/java/lam/cobia/cluster/FailoverCluster.java +++ b/cobia-core/src/main/java/lam/cobia/cluster/FailoverCluster.java @@ -26,12 +26,11 @@ public class FailoverCluster extends AbstractCluster{ private int retryTime = 2; public FailoverCluster() { - super.name = "failover"; + super("failover"); } public FailoverCluster(Class interfaceClass, List> consumers, LoadBalance loadBalance) { - super(interfaceClass, consumers, loadBalance); - super.name = "failover"; + super("failover", interfaceClass, consumers, loadBalance); } @Override