Add the priority to AbilityControlManager.
This commit is contained in:
parent
182b821938
commit
ac2523ab7d
@ -63,5 +63,11 @@ public class ClientAbilityControlManager extends DefaultAbilityControlManager {
|
|||||||
protected void remove(String connectionId) {
|
protected void remove(String connectionId) {
|
||||||
// nothing to do
|
// 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>
|
<filtering>true</filtering>
|
||||||
<includes>
|
<includes>
|
||||||
<include>nacos-version.txt</include>
|
<include>nacos-version.txt</include>
|
||||||
<include>META-INF/services/com.alibaba.nacos.common.ability.DefaultAbilityControlManager</include>
|
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -208,6 +208,14 @@ public abstract class AbstractAbilityControlManager implements AbilityControlMan
|
|||||||
// default destroy
|
// default destroy
|
||||||
// nothing to do
|
// 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
|
* Return ability table of current node
|
||||||
|
@ -24,7 +24,10 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.ServiceConfigurationError;
|
import java.util.ServiceConfigurationError;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to discover {@link AbstractAbilityControlManager} implements. All the
|
* This class is used to discover {@link AbstractAbilityControlManager} implements. All the
|
||||||
@ -55,14 +58,15 @@ public class NacosAbilityManagerHolder {
|
|||||||
// if server
|
// if server
|
||||||
load = NacosServiceLoader.load(DefaultAbilityControlManager.class);
|
load = NacosServiceLoader.load(DefaultAbilityControlManager.class);
|
||||||
} catch (ServiceConfigurationError e) {
|
} catch (ServiceConfigurationError e) {
|
||||||
// if client or not ability control manager
|
throw new RuntimeException("[AbilityControlManager] Cannot find AbilityControlManger");
|
||||||
load = NacosServiceLoader.load(DefaultAbilityControlManager.class);
|
|
||||||
}
|
}
|
||||||
// the priority of the server is higher
|
// 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) {
|
if (load.size() > 0) {
|
||||||
load.forEach(clazz -> {
|
abstractAbilityControlManager = collect.get(collect.size() - 1);
|
||||||
abstractAbilityControlManager = clazz;
|
|
||||||
});
|
|
||||||
LOGGER.info("[AbilityControlManager] Successfully initialize AbilityControlManager");
|
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
|
* notify when current node ability changing
|
||||||
*/
|
*/
|
||||||
|
@ -15,5 +15,4 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
com.alibaba.nacos.client.ability.ClientAbilityControlManager
|
|
||||||
com.alibaba.nacos.core.ability.control.ServerAbilityControlManager
|
com.alibaba.nacos.core.ability.control.ServerAbilityControlManager
|
Loading…
Reference in New Issue
Block a user