Add the priority to AbilityControlManager.
This commit is contained in:
parent
182b821938
commit
ac2523ab7d
@ -64,4 +64,10 @@ public class ClientAbilityControlManager extends DefaultAbilityControlManager {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
// if server ability manager exist, you should choose the server one
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
#
|
||||
# Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
|
||||
com.alibaba.nacos.client.ability.ClientAbilityControlManager
|
@ -84,7 +84,6 @@
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>nacos-version.txt</include>
|
||||
<include>META-INF/services/com.alibaba.nacos.common.ability.DefaultAbilityControlManager</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
@ -209,6 +209,14 @@ public abstract class AbstractAbilityControlManager implements AbilityControlMan
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* A Nacos application can only have one {@link AbilityControlManager}.
|
||||
* When multiple control centers exist, it is used to determine which one is preferred
|
||||
*
|
||||
* @return priority
|
||||
*/
|
||||
public abstract int getPriority();
|
||||
|
||||
/**
|
||||
* Return ability table of current node
|
||||
*
|
||||
|
@ -24,7 +24,10 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* This class is used to discover {@link AbstractAbilityControlManager} implements. All the
|
||||
@ -55,14 +58,15 @@ public class NacosAbilityManagerHolder {
|
||||
// if server
|
||||
load = NacosServiceLoader.load(DefaultAbilityControlManager.class);
|
||||
} catch (ServiceConfigurationError e) {
|
||||
// if client or not ability control manager
|
||||
load = NacosServiceLoader.load(DefaultAbilityControlManager.class);
|
||||
throw new RuntimeException("[AbilityControlManager] Cannot find AbilityControlManger");
|
||||
}
|
||||
// the priority of the server is higher
|
||||
List<DefaultAbilityControlManager> collect = load.stream()
|
||||
.sorted(Comparator.comparingInt(AbstractAbilityControlManager::getPriority))
|
||||
.collect(Collectors.toList());
|
||||
// get the highest priority one
|
||||
if (load.size() > 0) {
|
||||
load.forEach(clazz -> {
|
||||
abstractAbilityControlManager = clazz;
|
||||
});
|
||||
abstractAbilityControlManager = collect.get(collect.size() - 1);
|
||||
LOGGER.info("[AbilityControlManager] Successfully initialize AbilityControlManager");
|
||||
}
|
||||
}
|
||||
|
@ -181,6 +181,11 @@ public class ServerAbilityControlManager extends DefaultAbilityControlManager im
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**.
|
||||
* notify when current node ability changing
|
||||
*/
|
||||
|
@ -15,5 +15,4 @@
|
||||
#
|
||||
#
|
||||
|
||||
com.alibaba.nacos.client.ability.ClientAbilityControlManager
|
||||
com.alibaba.nacos.core.ability.control.ServerAbilityControlManager
|
Loading…
Reference in New Issue
Block a user