use of org.apache.dubbo.rpc.cluster.support.migration.MigrationStep in project dubbo by alibaba.
the class ZoneAwareClusterInvoker method list.
@Override
protected List<Invoker<T>> list(Invocation invocation) throws RpcException {
List<Invoker<T>> invokers = super.list(invocation);
if (null == invokers || invokers.size() < 2) {
return invokers;
}
List<Invoker<T>> interfaceInvokers = new ArrayList<>();
List<Invoker<T>> serviceInvokers = new ArrayList<>();
boolean addressChanged = false;
for (Invoker<T> invoker : invokers) {
MigrationClusterInvoker migrationClusterInvoker = (MigrationClusterInvoker) invoker;
if (migrationClusterInvoker.isServiceInvoker()) {
serviceInvokers.add(invoker);
} else {
interfaceInvokers.add(invoker);
}
if (migrationClusterInvoker.invokersChanged().compareAndSet(true, false)) {
addressChanged = true;
}
}
if (serviceInvokers.isEmpty() || interfaceInvokers.isEmpty()) {
return invokers;
}
MigrationRule rule = null;
for (Invoker<T> invoker : serviceInvokers) {
MigrationClusterInvoker migrationClusterInvoker = (MigrationClusterInvoker) invoker;
if (rule == null) {
rule = migrationClusterInvoker.getMigrationRule();
continue;
}
// inconsistency rule
if (!rule.equals(migrationClusterInvoker.getMigrationRule())) {
rule = MigrationRule.queryRule();
break;
}
}
MigrationStep step = rule.getStep();
switch(step) {
case FORCE_INTERFACE:
clusterRefresh(addressChanged, interfaceInvokers);
clusterDestroy(addressChanged, serviceInvokers, true);
if (logger.isDebugEnabled()) {
logger.debug("step is FORCE_INTERFACE");
}
return interfaceInvokers;
case APPLICATION_FIRST:
clusterRefresh(addressChanged, serviceInvokers);
clusterRefresh(addressChanged, interfaceInvokers);
boolean serviceAvailable = !serviceInvokers.isEmpty();
if (serviceAvailable) {
if (shouldMigrate(addressChanged, serviceInvokers, interfaceInvokers)) {
if (logger.isDebugEnabled()) {
logger.debug("step is APPLICATION_FIRST shouldMigrate true get serviceInvokers");
}
return serviceInvokers;
}
}
if (logger.isDebugEnabled()) {
logger.debug("step is APPLICATION_FIRST " + (serviceInvokers.isEmpty() ? "serviceInvokers is empty" : "shouldMigrate false") + " get interfaceInvokers");
}
return interfaceInvokers;
case FORCE_APPLICATION:
clusterRefresh(addressChanged, serviceInvokers);
clusterDestroy(addressChanged, interfaceInvokers, true);
if (logger.isDebugEnabled()) {
logger.debug("step is FORCE_APPLICATION");
}
return serviceInvokers;
}
throw new UnsupportedOperationException(rule.getStep().name());
}
Aggregations