You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/09/16 12:50:35 UTC
[dubbo] branch 3.0 updated: Refactor dubbo-qos module to support
Multi-Instances (#8823)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new ebdb2f6 Refactor dubbo-qos module to support Multi-Instances (#8823)
ebdb2f6 is described below
commit ebdb2f6edfbfa335df437692557368ef6a786183
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Thu Sep 16 20:50:25 2021 +0800
Refactor dubbo-qos module to support Multi-Instances (#8823)
* Refactor dubbo-qos module to support Multi-Instaces
* Fix
* Add rat
* Fix
* Fix import
---
.../bootstrap/DefaultApplicationDeployer.java | 5 ++-
...nlineApp.java => QosScopeModelInitializer.java} | 35 ++++++++-------
.../org/apache/dubbo/qos/command/BaseCommand.java | 3 +-
.../dubbo/qos/command/DefaultCommandExecutor.java | 10 ++++-
.../apache/dubbo/qos/command/impl/BaseOffline.java | 10 +++--
.../apache/dubbo/qos/command/impl/BaseOnline.java | 10 +++--
.../dubbo/qos/command/impl/ChangeTelnet.java | 9 +++-
.../apache/dubbo/qos/command/impl/CountTelnet.java | 9 +++-
.../org/apache/dubbo/qos/command/impl/Help.java | 14 ++++--
.../dubbo/qos/command/impl/InvokeTelnet.java | 9 +++-
.../org/apache/dubbo/qos/command/impl/Live.java | 40 ++++++++++++-----
.../java/org/apache/dubbo/qos/command/impl/Ls.java | 12 +++--
.../org/apache/dubbo/qos/command/impl/Offline.java | 6 +++
.../apache/dubbo/qos/command/impl/OfflineApp.java | 5 +++
.../dubbo/qos/command/impl/OfflineInterface.java | 6 +++
.../org/apache/dubbo/qos/command/impl/Online.java | 5 +++
.../apache/dubbo/qos/command/impl/OnlineApp.java | 7 +--
.../dubbo/qos/command/impl/OnlineInterface.java | 5 +++
.../apache/dubbo/qos/command/impl/PortTelnet.java | 11 ++++-
.../dubbo/qos/command/impl/PublishMetadata.java | 51 ++++++++++++++--------
.../org/apache/dubbo/qos/command/impl/Ready.java | 24 ++++++++--
.../dubbo/qos/command/impl/SelectTelnet.java | 7 ++-
.../dubbo/qos/command/impl/ShutdownTelnet.java | 18 ++++++++
.../org/apache/dubbo/qos/command/impl/Startup.java | 25 +++++++++--
.../dubbo/qos/command/util/CommandHelper.java | 21 +++++----
.../org/apache/dubbo/qos/probe/LivenessProbe.java | 3 +-
.../org/apache/dubbo/qos/probe/ReadinessProbe.java | 3 +-
.../org/apache/dubbo/qos/probe/StartupProbe.java | 3 +-
.../dubbo/qos/protocol/QosProtocolWrapper.java | 20 ++++++---
.../java/org/apache/dubbo/qos/server/Server.java | 13 +++---
.../qos/server/handler/HttpProcessHandler.java | 6 ++-
.../qos/server/handler/QosProcessHandler.java | 10 +++--
.../qos/server/handler/TelnetProcessHandler.java | 7 ++-
...rg.apache.dubbo.rpc.model.ScopeModelInitializer | 1 +
.../qos/command/DefaultCommandExecutorTest.java | 6 ++-
.../dubbo/qos/command/impl/ChangeTelnetTest.java | 3 +-
.../dubbo/qos/command/impl/CountTelnetTest.java | 3 +-
.../apache/dubbo/qos/command/impl/HelpTest.java | 8 ++--
.../dubbo/qos/command/impl/InvokeTelnetTest.java | 19 +++++---
.../dubbo/qos/command/impl/PortTelnetTest.java | 3 +-
.../dubbo/qos/command/impl/SelectTelnetTest.java | 8 ++--
.../dubbo/qos/command/impl/ShutdownTelnetTest.java | 6 ++-
.../dubbo/qos/command/util/CommandHelperTest.java | 13 +++---
.../dubbo/qos/protocol/QosProtocolWrapperTest.java | 9 +++-
.../qos/server/handler/HttpProcessHandlerTest.java | 10 +++--
.../qos/server/handler/QosProcessHandlerTest.java | 6 ++-
.../server/handler/TelnetProcessHandlerTest.java | 12 ++---
.../client/AbstractServiceDiscoveryFactory.java | 4 +-
.../dispatcher/WrappedChannelHandler.java | 3 +-
49 files changed, 386 insertions(+), 150 deletions(-)
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DefaultApplicationDeployer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DefaultApplicationDeployer.java
index bddcea3..248932a 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DefaultApplicationDeployer.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DefaultApplicationDeployer.java
@@ -129,7 +129,6 @@ public class DefaultApplicationDeployer implements ApplicationDeployer {
protected ScheduledFuture<?> asyncMetadataFuture;
private String identifier;
-
public DefaultApplicationDeployer(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
configManager = applicationModel.getApplicationConfigManager();
@@ -812,6 +811,10 @@ public class DefaultApplicationDeployer implements ApplicationDeployer {
return this.serviceInstance;
}
+ public ServiceInstance getServiceInstance() {
+ return serviceInstance;
+ }
+
@Override
public void destroy() {
if (destroyLock.tryLock()
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineApp.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/QosScopeModelInitializer.java
similarity index 50%
copy from dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineApp.java
copy to dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/QosScopeModelInitializer.java
index 1e2bee8..2f61507 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineApp.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/QosScopeModelInitializer.java
@@ -14,26 +14,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.qos.command.impl;
+package org.apache.dubbo.qos;
+import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
+import org.apache.dubbo.qos.server.Server;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.rpc.model.ModuleModel;
+import org.apache.dubbo.rpc.model.ScopeModelInitializer;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.utils.UrlUtils;
-import org.apache.dubbo.qos.command.annotation.Cmd;
-import org.apache.dubbo.rpc.model.ProviderModel;
+public class QosScopeModelInitializer implements ScopeModelInitializer {
+ @Override
+ public void initializeFrameworkModel(FrameworkModel frameworkModel) {
+ ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory();
+ beanFactory.registerBean(Server.class);
+ }
+
+ @Override
+ public void initializeApplicationModel(ApplicationModel applicationModel) {
-@Cmd(name = "onlineApp", summary = "online app addresses", example = {
- "onlineApp",
- "onlineApp xx.xx.xxx.service"
-})
-public class OnlineApp extends BaseOnline {
- private static final Logger logger = LoggerFactory.getLogger(OnlineApp.class);
+ }
@Override
- protected void doExport(ProviderModel.RegisterStatedURL statedURL) {
- if (UrlUtils.isServiceDiscoveryURL(statedURL.getRegistryUrl())) {
- super.doExport(statedURL);
- }
+ public void initializeModuleModel(ModuleModel moduleModel) {
+
}
}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/BaseCommand.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/BaseCommand.java
index ac9a3fe..c2a8419 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/BaseCommand.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/BaseCommand.java
@@ -16,9 +16,10 @@
*/
package org.apache.dubbo.qos.command;
+import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
-@SPI
+@SPI(scope = ExtensionScope.FRAMEWORK)
public interface BaseCommand {
String execute(CommandContext commandContext,String[] args);
}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/DefaultCommandExecutor.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/DefaultCommandExecutor.java
index 342f256..12cd5f9 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/DefaultCommandExecutor.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/DefaultCommandExecutor.java
@@ -16,14 +16,20 @@
*/
package org.apache.dubbo.qos.command;
-import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.rpc.model.FrameworkModel;
public class DefaultCommandExecutor implements CommandExecutor {
+ private FrameworkModel frameworkModel;
+
+ public DefaultCommandExecutor(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
+ }
+
@Override
public String execute(CommandContext commandContext) throws NoSuchCommandException {
BaseCommand command = null;
try {
- command = ExtensionLoader.getExtensionLoader(BaseCommand.class).getExtension(commandContext.getCommandName());
+ command = frameworkModel.getExtensionLoader(BaseCommand.class).getExtension(commandContext.getCommandName());
} catch (Throwable throwable) {
//can't find command
}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/BaseOffline.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/BaseOffline.java
index e15836b..4a98e23 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/BaseOffline.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/BaseOffline.java
@@ -16,7 +16,6 @@
*/
package org.apache.dubbo.qos.command.impl;
-import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.qos.command.BaseCommand;
@@ -33,8 +32,11 @@ import java.util.List;
public class BaseOffline implements BaseCommand {
private Logger logger = LoggerFactory.getLogger(OfflineInterface.class);
- public static RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
- public static FrameworkServiceRepository serviceRepository = FrameworkModel.defaultModel().getServiceRepository();
+ public FrameworkServiceRepository serviceRepository;
+
+ public BaseOffline(FrameworkModel frameworkModel) {
+ this.serviceRepository = FrameworkModel.defaultModel().getServiceRepository();
+ }
@Override
public String execute(CommandContext commandContext, String[] args) {
@@ -78,6 +80,8 @@ public class BaseOffline implements BaseCommand {
}
protected void doUnexport(ProviderModel.RegisterStatedURL statedURL) {
+ RegistryFactory registryFactory =
+ statedURL.getRegistryUrl().getOrDefaultApplicationModel().getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
Registry registry = registryFactory.getRegistry(statedURL.getRegistryUrl());
registry.unregister(statedURL.getProviderUrl());
statedURL.setRegistered(false);
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/BaseOnline.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/BaseOnline.java
index 543c081..9ee67e5 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/BaseOnline.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/BaseOnline.java
@@ -16,7 +16,6 @@
*/
package org.apache.dubbo.qos.command.impl;
-import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ArrayUtils;
@@ -34,8 +33,11 @@ import java.util.List;
public class BaseOnline implements BaseCommand {
private static final Logger logger = LoggerFactory.getLogger(Online.class);
- public static RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
- public static FrameworkServiceRepository serviceRepository = FrameworkModel.defaultModel().getServiceRepository();
+ public FrameworkServiceRepository serviceRepository;
+
+ public BaseOnline(FrameworkModel frameworkModel) {
+ this.serviceRepository = frameworkModel.getServiceRepository();
+ }
@Override
public String execute(CommandContext commandContext, String[] args) {
@@ -78,6 +80,8 @@ public class BaseOnline implements BaseCommand {
}
protected void doExport(ProviderModel.RegisterStatedURL statedURL) {
+ RegistryFactory registryFactory =
+ statedURL.getRegistryUrl().getOrDefaultApplicationModel().getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
Registry registry = registryFactory.getRegistry(statedURL.getRegistryUrl());
registry.register(statedURL.getProviderUrl());
statedURL.setRegistered(true);
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/ChangeTelnet.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/ChangeTelnet.java
index d6424ec..d0864b9 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/ChangeTelnet.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/ChangeTelnet.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.rpc.Exporter;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
import io.netty.channel.Channel;
@@ -32,6 +33,12 @@ public class ChangeTelnet implements BaseCommand {
public static final AttributeKey<String> SERVICE_KEY = AttributeKey.valueOf("telnet.service");
+ private DubboProtocol dubboProtocol;
+
+ public ChangeTelnet(FrameworkModel frameworkModel) {
+ this.dubboProtocol = DubboProtocol.getDubboProtocol(frameworkModel);
+ }
+
@Override
public String execute(CommandContext commandContext, String[] args) {
Channel channel = commandContext.getRemote();
@@ -46,7 +53,7 @@ public class ChangeTelnet implements BaseCommand {
buf.append("Cancelled default service ").append(service).append(".");
} else {
boolean found = false;
- for (Exporter<?> exporter : DubboProtocol.getDubboProtocol().getExporters()) {
+ for (Exporter<?> exporter : dubboProtocol.getExporters()) {
if (message.equals(exporter.getInvoker().getInterface().getSimpleName())
|| message.equals(exporter.getInvoker().getInterface().getName())
|| message.equals(exporter.getInvoker().getUrl().getPath())) {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/CountTelnet.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/CountTelnet.java
index 5bd8ecc..9bf0706 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/CountTelnet.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/CountTelnet.java
@@ -27,6 +27,7 @@ import org.apache.dubbo.remoting.utils.PayloadDropper;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcStatus;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
import io.netty.channel.Channel;
@@ -43,6 +44,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
"count [service] [method] [times]"
})
public class CountTelnet implements BaseCommand {
+ private DubboProtocol dubboProtocol;
+
+ public CountTelnet(FrameworkModel frameworkModel) {
+ this.dubboProtocol = DubboProtocol.getDubboProtocol(frameworkModel);
+ }
+
@Override
public String execute(CommandContext commandContext, String[] args) {
Channel channel = commandContext.getRemote();
@@ -74,7 +81,7 @@ public class CountTelnet implements BaseCommand {
}
final int t = Integer.parseInt(times);
Invoker<?> invoker = null;
- for (Exporter<?> exporter : DubboProtocol.getDubboProtocol().getExporters()) {
+ for (Exporter<?> exporter : dubboProtocol.getExporters()) {
if (service.equals(exporter.getInvoker().getInterface().getSimpleName())
|| service.equals(exporter.getInvoker().getInterface().getName())
|| service.equals(exporter.getInvoker().getUrl().getPath())) {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Help.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Help.java
index bb0a94d..534c3fa 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Help.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Help.java
@@ -21,6 +21,7 @@ import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.qos.command.util.CommandHelper;
import org.apache.dubbo.qos.textui.TTable;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import java.util.Collections;
import java.util.Comparator;
@@ -31,6 +32,13 @@ import java.util.List;
"help online"
})
public class Help implements BaseCommand {
+
+ private CommandHelper commandHelper;
+
+ public Help(FrameworkModel frameworkModel) {
+ this.commandHelper = new CommandHelper(frameworkModel);
+ }
+
@Override
public String execute(CommandContext commandContext, String[] args) {
if (args != null && args.length > 0) {
@@ -44,11 +52,11 @@ public class Help implements BaseCommand {
private String commandHelp(String commandName) {
- if (!CommandHelper.hasCommand(commandName)) {
+ if (!commandHelper.hasCommand(commandName)) {
return "no such command:" + commandName;
}
- Class<?> clazz = CommandHelper.getCommandClass(commandName);
+ Class<?> clazz = commandHelper.getCommandClass(commandName);
final Cmd cmd = clazz.getAnnotation(Cmd.class);
final TTable tTable = new TTable(new TTable.ColumnDefine[]{
@@ -83,7 +91,7 @@ public class Help implements BaseCommand {
new TTable.ColumnDefine(80, false, TTable.Align.LEFT)
});
- final List<Class<?>> classes = CommandHelper.getAllCommandClass();
+ final List<Class<?>> classes = commandHelper.getAllCommandClass();
Collections.sort(classes, new Comparator<Class<?>>() {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/InvokeTelnet.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/InvokeTelnet.java
index 64c5c15..f8f3a09 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/InvokeTelnet.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/InvokeTelnet.java
@@ -23,7 +23,7 @@ import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.rpc.AppResponse;
-import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.MethodDescriptor;
import org.apache.dubbo.rpc.model.ProviderModel;
@@ -48,6 +48,11 @@ public class InvokeTelnet implements BaseCommand {
public static final AttributeKey<List<Method>> INVOKE_METHOD_LIST_KEY = AttributeKey.valueOf("telnet.invoke.method.list");
public static final AttributeKey<ProviderModel> INVOKE_METHOD_PROVIDER_KEY = AttributeKey.valueOf("telnet.invoke.method.provider");
+ private FrameworkModel frameworkModel;
+
+ public InvokeTelnet(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
+ }
@Override
public String execute(CommandContext commandContext, String[] args) {
@@ -87,7 +92,7 @@ public class InvokeTelnet implements BaseCommand {
selectedProvider = channel.attr(INVOKE_METHOD_PROVIDER_KEY).get();
invokeMethod = channel.attr(SelectTelnet.SELECT_METHOD_KEY).get();
} else {
- for (ProviderModel provider : ApplicationModel.defaultModel().allProviderModels()) {
+ for (ProviderModel provider : frameworkModel.getServiceRepository().allProviderModels()) {
if (!isServiceMatch(service, provider)) {
continue;
}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Live.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Live.java
index 696c3a1..c9e00c6 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Live.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Live.java
@@ -18,30 +18,48 @@ package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
-import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.qos.probe.LivenessProbe;
-import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
@Cmd(name = "live", summary = "Judge if service is alive? ")
public class Live implements BaseCommand {
+ private FrameworkModel frameworkModel;
+
+ public Live(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
+ }
@Override
public String execute(CommandContext commandContext, String[] args) {
- URL url = URL.valueOf("application://")
- .addParameter(CommonConstants.QOS_LIVE_PROBE_EXTENSION, ApplicationModel.defaultModel().getCurrentConfig().getLivenessProbe());
- List<LivenessProbe> livenessProbes = ExtensionLoader.getExtensionLoader(LivenessProbe.class)
+ String config = frameworkModel.getApplicationModels()
+ .stream()
+ .map(applicationModel -> applicationModel.getApplicationConfigManager().getApplication())
+ .map(o -> o.orElse(null))
+ .filter(Objects::nonNull)
+ .map(ApplicationConfig::getLivenessProbe)
+ .filter(Objects::nonNull)
+ .collect(Collectors.joining(","));
+ if(StringUtils.isNotEmpty(config)) {
+ URL url = URL.valueOf("application://")
+ .addParameter(CommonConstants.QOS_LIVE_PROBE_EXTENSION, config);
+ List<LivenessProbe> livenessProbes = frameworkModel.getExtensionLoader(LivenessProbe.class)
.getActivateExtension(url, CommonConstants.QOS_LIVE_PROBE_EXTENSION);
- if (!livenessProbes.isEmpty()) {
- for (LivenessProbe livenessProbe : livenessProbes) {
- if (!livenessProbe.check()) {
- // 503 Service Unavailable
- commandContext.setHttpCode(503);
- return "false";
+ if (!livenessProbes.isEmpty()) {
+ for (LivenessProbe livenessProbe : livenessProbes) {
+ if (!livenessProbe.check()) {
+ // 503 Service Unavailable
+ commandContext.setHttpCode(503);
+ return "false";
+ }
}
}
}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java
index 314a000..3722196 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java
@@ -21,8 +21,8 @@ import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.qos.command.util.ServiceCheckUtils;
import org.apache.dubbo.qos.textui.TTable;
-import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ConsumerModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ProviderModel;
import java.util.Collection;
@@ -31,6 +31,12 @@ import java.util.Collection;
"ls"
})
public class Ls implements BaseCommand {
+ private FrameworkModel frameworkModel;
+
+ public Ls(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
+ }
+
@Override
public String execute(CommandContext commandContext, String[] args) {
StringBuilder result = new StringBuilder();
@@ -43,7 +49,7 @@ public class Ls implements BaseCommand {
public String listProvider() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("As Provider side:" + System.lineSeparator());
- Collection<ProviderModel> providerModelList = ApplicationModel.defaultModel().allProviderModels();
+ Collection<ProviderModel> providerModelList = frameworkModel.getServiceRepository().allProviderModels();
TTable tTable = new TTable(new TTable.ColumnDefine[]{
new TTable.ColumnDefine(TTable.Align.MIDDLE),
@@ -65,7 +71,7 @@ public class Ls implements BaseCommand {
public String listConsumer() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("As Consumer side:" + System.lineSeparator());
- Collection<ConsumerModel> consumerModelList = ApplicationModel.defaultModel().allConsumerModels();
+ Collection<ConsumerModel> consumerModelList = frameworkModel.getServiceRepository().allConsumerModels();
TTable tTable = new TTable(new TTable.ColumnDefine[]{
new TTable.ColumnDefine(TTable.Align.MIDDLE),
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java
index 5d1031c..e7a5274 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java
@@ -17,6 +17,7 @@
package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ProviderModel;
@Cmd(name = "offline", summary = "offline dubbo", example = {
@@ -24,6 +25,11 @@ import org.apache.dubbo.rpc.model.ProviderModel;
"offline xx.xx.xxx.service"
})
public class Offline extends BaseOffline {
+
+ public Offline(FrameworkModel frameworkModel) {
+ super(frameworkModel);
+ }
+
@Override
protected void doUnexport(ProviderModel.RegisterStatedURL statedURL) {
super.doUnexport(statedURL);
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OfflineApp.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OfflineApp.java
index 5de1c8b..29aeb98 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OfflineApp.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OfflineApp.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ProviderModel;
@Cmd(name = "offlineApp", summary = "offline app addresses", example = {
@@ -29,6 +30,10 @@ import org.apache.dubbo.rpc.model.ProviderModel;
public class OfflineApp extends BaseOffline {
private static final Logger logger = LoggerFactory.getLogger(OfflineApp.class);
+ public OfflineApp(FrameworkModel frameworkModel) {
+ super(frameworkModel);
+ }
+
@Override
protected void doUnexport(ProviderModel.RegisterStatedURL statedURL) {
if (UrlUtils.isServiceDiscoveryURL(statedURL.getRegistryUrl())) {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OfflineInterface.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OfflineInterface.java
index f02b0e8..b7bb3ba 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OfflineInterface.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OfflineInterface.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ProviderModel;
@Cmd(name = "offlineInterface", summary = "offline dubbo", example = {
@@ -25,6 +26,11 @@ import org.apache.dubbo.rpc.model.ProviderModel;
"offlineInterface xx.xx.xxx.service"
})
public class OfflineInterface extends BaseOffline {
+ public OfflineInterface(FrameworkModel frameworkModel) {
+ super(frameworkModel);
+ }
+
+ @Override
protected void doUnexport(ProviderModel.RegisterStatedURL statedURL) {
if (!UrlUtils.isServiceDiscoveryURL(statedURL.getRegistryUrl())) {
super.doUnexport(statedURL);
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java
index d2f3d03..9370a3b 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java
@@ -17,6 +17,7 @@
package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ProviderModel;
@Cmd(name = "onlineAPp", summary = "offline app addresses", example = {
@@ -24,6 +25,10 @@ import org.apache.dubbo.rpc.model.ProviderModel;
"offlineApp xx.xx.xxx.service"
})
public class Online extends BaseOnline {
+ public Online(FrameworkModel frameworkModel) {
+ super(frameworkModel);
+ }
+
@Override
protected void doExport(ProviderModel.RegisterStatedURL statedURL) {
super.doExport(statedURL);
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineApp.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineApp.java
index 1e2bee8..d25ad21 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineApp.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineApp.java
@@ -17,10 +17,9 @@
package org.apache.dubbo.qos.command.impl;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ProviderModel;
@Cmd(name = "onlineApp", summary = "online app addresses", example = {
@@ -28,7 +27,9 @@ import org.apache.dubbo.rpc.model.ProviderModel;
"onlineApp xx.xx.xxx.service"
})
public class OnlineApp extends BaseOnline {
- private static final Logger logger = LoggerFactory.getLogger(OnlineApp.class);
+ public OnlineApp(FrameworkModel frameworkModel) {
+ super(frameworkModel);
+ }
@Override
protected void doExport(ProviderModel.RegisterStatedURL statedURL) {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineInterface.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineInterface.java
index e7b100d..e4a441b 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineInterface.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/OnlineInterface.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ProviderModel;
@Cmd(name = "onlineInterface", summary = "online dubbo", example = {
@@ -25,6 +26,10 @@ import org.apache.dubbo.rpc.model.ProviderModel;
"onlineInterface xx.xx.xxx.service"
})
public class OnlineInterface extends BaseOnline {
+ public OnlineInterface(FrameworkModel frameworkModel) {
+ super(frameworkModel);
+ }
+
@Override
protected void doExport(ProviderModel.RegisterStatedURL statedURL) {
if (!UrlUtils.isServiceDiscoveryURL(statedURL.getRegistryUrl())) {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/PortTelnet.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/PortTelnet.java
index d6ce35e..e41e47a 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/PortTelnet.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/PortTelnet.java
@@ -23,6 +23,7 @@ import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.remoting.exchange.ExchangeChannel;
import org.apache.dubbo.remoting.exchange.ExchangeServer;
import org.apache.dubbo.rpc.ProtocolServer;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
import java.util.Collection;
@@ -31,6 +32,12 @@ import java.util.Collection;
"ps -l [port]", "ps", "ps -l", "ps -l 20880"
})
public class PortTelnet implements BaseCommand {
+ private DubboProtocol dubboProtocol;
+
+ public PortTelnet(FrameworkModel frameworkModel) {
+ this.dubboProtocol = DubboProtocol.getDubboProtocol(frameworkModel);
+ }
+
@Override
public String execute(CommandContext commandContext, String[] args) {
StringBuilder buf = new StringBuilder();
@@ -49,7 +56,7 @@ public class PortTelnet implements BaseCommand {
}
}
if (port == null || port.length() == 0) {
- for (ProtocolServer server : DubboProtocol.getDubboProtocol().getServers()) {
+ for (ProtocolServer server : dubboProtocol.getServers()) {
if (buf.length() > 0) {
buf.append("\r\n");
}
@@ -62,7 +69,7 @@ public class PortTelnet implements BaseCommand {
} else {
int p = Integer.parseInt(port);
ProtocolServer protocolServer = null;
- for (ProtocolServer s : DubboProtocol.getDubboProtocol().getServers()) {
+ for (ProtocolServer s : dubboProtocol.getServers()) {
if (p == s.getUrl().getPort()) {
protocolServer = s;
break;
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/PublishMetadata.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/PublishMetadata.java
index 34ef7d0..7deb58c 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/PublishMetadata.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/PublishMetadata.java
@@ -16,48 +16,63 @@
*/
package org.apache.dubbo.qos.command.impl;
-import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.threadpool.manager.ExecutorRepository;
import org.apache.dubbo.common.utils.ArrayUtils;
+import org.apache.dubbo.config.bootstrap.DefaultApplicationDeployer;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
-import java.util.concurrent.ScheduledFuture;
+import java.util.List;
import java.util.concurrent.TimeUnit;
@Cmd(name = "publishMetadata", summary = "update service metadata and service instance", example = {
"publishMetadata",
"publishMetadata 5"
})
-public class PublishMetadata implements BaseCommand {
+public class PublishMetadata implements BaseCommand {
private static final Logger logger = LoggerFactory.getLogger(PublishMetadata.class);
- private final ExecutorRepository executorRepository = ExtensionLoader.getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
- private ScheduledFuture future;
+ private final FrameworkModel frameworkModel;
+
+ public PublishMetadata(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
+ }
@Override
public String execute(CommandContext commandContext, String[] args) {
logger.info("received publishMetadata command.");
- if (ArrayUtils.isEmpty(args)) {
- ServiceInstanceMetadataUtils.refreshMetadataAndInstance(null);
- return "publish metadata succeeded.";
- }
+ StringBuilder stringBuilder = new StringBuilder();
+ List<ApplicationModel> applicationModels = frameworkModel.getApplicationModels();
- try {
- int delay = Integer.parseInt(args[0]);
- if (future == null || future.isDone() || future.isCancelled()) {
- future = executorRepository.nextScheduledExecutor()
- .scheduleWithFixedDelay(() -> ServiceInstanceMetadataUtils.refreshMetadataAndInstance(null), 0, delay, TimeUnit.MILLISECONDS);
+ for (ApplicationModel applicationModel : applicationModels) {
+ DefaultApplicationDeployer deployer = applicationModel.getBeanFactory().getBean(DefaultApplicationDeployer.class);
+ ServiceInstance serviceInstance = deployer.getServiceInstance();
+ if (serviceInstance != null) {
+ if (ArrayUtils.isEmpty(args)) {
+ ServiceInstanceMetadataUtils.refreshMetadataAndInstance(serviceInstance);
+ stringBuilder.append("publish metadata succeeded. App:").append(serviceInstance.getServiceName()).append("\n");
+ } else {
+ try {
+ int delay = Integer.parseInt(args[0]);
+ ExecutorRepository executorRepository = applicationModel.getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
+ executorRepository.nextScheduledExecutor()
+ .schedule(() -> ServiceInstanceMetadataUtils.refreshMetadataAndInstance(serviceInstance), delay, TimeUnit.SECONDS);
+ } catch (NumberFormatException e) {
+ logger.error("Wrong delay param", e);
+ return "publishMetadata failed! Wrong delay param!";
+ }
+ stringBuilder.append("publish task submitted, will publish in ").append(args[0]).append(" seconds. App:").append(serviceInstance.getServiceName()).append("\n");
+ }
}
- } catch (NumberFormatException e) {
- logger.error("Wrong delay param", e);
- return "publishMetadata failed! Wrong delay param!";
}
- return "publish task submitted, will publish in " + args[0] + " seconds.";
+ return stringBuilder.toString();
}
}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ready.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ready.java
index 44bc789..e7ce839 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ready.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ready.java
@@ -18,23 +18,39 @@ package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
-import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.qos.probe.ReadinessProbe;
-import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
@Cmd(name = "ready", summary = "Judge if service is ready to work? ")
public class Ready implements BaseCommand {
+ private FrameworkModel frameworkModel;
+
+ public Ready(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
+ }
@Override
public String execute(CommandContext commandContext, String[] args) {
+ String config = frameworkModel.getApplicationModels()
+ .stream()
+ .map(applicationModel -> applicationModel.getApplicationConfigManager().getApplication())
+ .map(o -> o.orElse(null))
+ .filter(Objects::nonNull)
+ .map(ApplicationConfig::getReadinessProbe)
+ .filter(Objects::nonNull)
+ .collect(Collectors.joining(","));
+
URL url = URL.valueOf("application://")
- .addParameter(CommonConstants.QOS_READY_PROBE_EXTENSION, ApplicationModel.defaultModel().getCurrentConfig().getReadinessProbe());
- List<ReadinessProbe> readinessProbes = ExtensionLoader.getExtensionLoader(ReadinessProbe.class)
+ .addParameter(CommonConstants.QOS_READY_PROBE_EXTENSION, config);
+ List<ReadinessProbe> readinessProbes = frameworkModel.getExtensionLoader(ReadinessProbe.class)
.getActivateExtension(url, CommonConstants.QOS_READY_PROBE_EXTENSION);
if (!readinessProbes.isEmpty()) {
for (ReadinessProbe readinessProbe : readinessProbes) {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/SelectTelnet.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/SelectTelnet.java
index b15cecc..a2a75c2 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/SelectTelnet.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/SelectTelnet.java
@@ -21,6 +21,7 @@ import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
@@ -35,7 +36,11 @@ public class SelectTelnet implements BaseCommand {
public static final AttributeKey<Boolean> SELECT_KEY = AttributeKey.valueOf("telnet.select");
public static final AttributeKey<Method> SELECT_METHOD_KEY = AttributeKey.valueOf("telnet.select.method");
- private final InvokeTelnet invokeTelnet = new InvokeTelnet();
+ private final InvokeTelnet invokeTelnet;
+
+ public SelectTelnet(FrameworkModel frameworkModel) {
+ this.invokeTelnet = new InvokeTelnet(frameworkModel);
+ }
@Override
public String execute(CommandContext commandContext, String[] args) {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/ShutdownTelnet.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/ShutdownTelnet.java
index 9b22a6c..384a739 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/ShutdownTelnet.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/ShutdownTelnet.java
@@ -17,14 +17,27 @@
package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.config.bootstrap.DefaultApplicationDeployer;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
+import java.util.ArrayList;
+import java.util.List;
@Cmd(name = "shutdown", summary = "Shutdown Dubbo Application.", example = {
"shutdown -t <milliseconds>"
})
public class ShutdownTelnet implements BaseCommand {
+
+ private FrameworkModel frameworkModel;
+
+ public ShutdownTelnet(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
+ }
+
@Override
public String execute(CommandContext commandContext, String[] args) {
@@ -45,6 +58,11 @@ public class ShutdownTelnet implements BaseCommand {
}
}
StringBuilder buf = new StringBuilder();
+ List<ApplicationModel> applicationModels = frameworkModel.getApplicationModels();
+ for (ApplicationModel applicationModel : new ArrayList<>(applicationModels)) {
+ DefaultApplicationDeployer deployer = applicationModel.getBeanFactory().getBean(DefaultApplicationDeployer.class);
+ deployer.destroy();
+ }
// TODO change to ApplicationDeployer.destroy() or ApplicationModel.destroy()
// DubboShutdownHook.getDubboShutdownHook().unregister();
// DubboShutdownHook.getDubboShutdownHook().doDestroy();
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Startup.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Startup.java
index 2c9fed2..e963f65 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Startup.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Startup.java
@@ -18,23 +18,40 @@ package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
-import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.qos.probe.StartupProbe;
-import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
@Cmd(name = "startup", summary = "Judge if service has started? ")
public class Startup implements BaseCommand {
+ private FrameworkModel frameworkModel;
+
+ public Startup(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
+ }
+
@Override
public String execute(CommandContext commandContext, String[] args) {
+ String config = frameworkModel.getApplicationModels()
+ .stream()
+ .map(applicationModel -> applicationModel.getApplicationConfigManager().getApplication())
+ .map(o -> o.orElse(null))
+ .filter(Objects::nonNull)
+ .map(ApplicationConfig::getStartupProbe)
+ .filter(Objects::nonNull)
+ .collect(Collectors.joining(","));
+
URL url = URL.valueOf("application://")
- .addParameter(CommonConstants.QOS_STARTUP_PROBE_EXTENSION, ApplicationModel.defaultModel().getCurrentConfig().getStartupProbe());
- List<StartupProbe> startupProbes = ExtensionLoader.getExtensionLoader(StartupProbe.class)
+ .addParameter(CommonConstants.QOS_STARTUP_PROBE_EXTENSION, config);
+ List<StartupProbe> startupProbes = frameworkModel.getExtensionLoader(StartupProbe.class)
.getActivateExtension(url, CommonConstants.QOS_STARTUP_PROBE_EXTENSION);
if (!startupProbes.isEmpty()) {
for (StartupProbe startupProbe : startupProbes) {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/util/CommandHelper.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/util/CommandHelper.java
index 6300c81..fa61ab9 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/util/CommandHelper.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/util/CommandHelper.java
@@ -16,8 +16,8 @@
*/
package org.apache.dubbo.qos.command.util;
-import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.qos.command.BaseCommand;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import java.util.ArrayList;
import java.util.List;
@@ -25,14 +25,17 @@ import java.util.Set;
public class CommandHelper {
- private CommandHelper() {
+ private FrameworkModel frameworkModel;
+
+ public CommandHelper(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
}
- public static boolean hasCommand(String commandName) {
+ public boolean hasCommand(String commandName) {
BaseCommand command = null;
try {
- command = ExtensionLoader.getExtensionLoader(BaseCommand.class).getExtension(commandName);
+ command = frameworkModel.getExtensionLoader(BaseCommand.class).getExtension(commandName);
} catch (Throwable throwable) {
return false;
}
@@ -41,12 +44,12 @@ public class CommandHelper {
}
- public static List<Class<?>> getAllCommandClass() {
- final Set<String> commandList = ExtensionLoader.getExtensionLoader(BaseCommand.class).getSupportedExtensions();
+ public List<Class<?>> getAllCommandClass() {
+ final Set<String> commandList = frameworkModel.getExtensionLoader(BaseCommand.class).getSupportedExtensions();
final List<Class<?>> classes = new ArrayList<Class<?>>();
for (String commandName : commandList) {
- BaseCommand command = ExtensionLoader.getExtensionLoader(BaseCommand.class).getExtension(commandName);
+ BaseCommand command = frameworkModel.getExtensionLoader(BaseCommand.class).getExtension(commandName);
classes.add(command.getClass());
}
@@ -54,9 +57,9 @@ public class CommandHelper {
}
- public static Class<?> getCommandClass(String commandName) {
+ public Class<?> getCommandClass(String commandName) {
if (hasCommand(commandName)) {
- return ExtensionLoader.getExtensionLoader(BaseCommand.class).getExtension(commandName).getClass();
+ return frameworkModel.getExtensionLoader(BaseCommand.class).getExtension(commandName).getClass();
} else {
return null;
}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/LivenessProbe.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/LivenessProbe.java
index 15484d3..0f81a9f 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/LivenessProbe.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/LivenessProbe.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.qos.probe;
+import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
/**
@@ -27,7 +28,7 @@ import org.apache.dubbo.common.extension.SPI;
*
* @since 3.0
*/
-@SPI
+@SPI(scope = ExtensionScope.FRAMEWORK)
public interface LivenessProbe {
/**
* Check if program is alive
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/ReadinessProbe.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/ReadinessProbe.java
index d988f38..98a51dd 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/ReadinessProbe.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/ReadinessProbe.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.qos.probe;
+import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
/**
@@ -27,7 +28,7 @@ import org.apache.dubbo.common.extension.SPI;
*
* @since 3.0
*/
-@SPI
+@SPI(scope = ExtensionScope.FRAMEWORK)
public interface ReadinessProbe {
/**
* Check if program is Ready
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/StartupProbe.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/StartupProbe.java
index 45bdd4b..018f8e8 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/StartupProbe.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/probe/StartupProbe.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.qos.probe;
+import org.apache.dubbo.common.extension.ExtensionScope;
import org.apache.dubbo.common.extension.SPI;
/**
@@ -27,7 +28,7 @@ import org.apache.dubbo.common.extension.SPI;
*
* @since 3.0
*/
-@SPI
+@SPI(scope = ExtensionScope.FRAMEWORK)
public interface StartupProbe {
/**
* Check if program has been startup
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
index 2e67d61..200ded4 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
@@ -17,6 +17,7 @@
package org.apache.dubbo.qos.protocol;
import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.UrlUtils;
@@ -27,6 +28,8 @@ import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProtocolServer;
import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -36,15 +39,17 @@ import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST;
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
-
-public class QosProtocolWrapper implements Protocol {
+@Activate(order = 200)
+public class QosProtocolWrapper implements Protocol, ScopeModelAware {
private final Logger logger = LoggerFactory.getLogger(QosProtocolWrapper.class);
- private static AtomicBoolean hasStarted = new AtomicBoolean(false);
+ private AtomicBoolean hasStarted = new AtomicBoolean(false);
private Protocol protocol;
+ private FrameworkModel frameworkModel;
+
public QosProtocolWrapper(Protocol protocol) {
if (protocol == null) {
throw new IllegalArgumentException("protocol == null");
@@ -53,6 +58,11 @@ public class QosProtocolWrapper implements Protocol {
}
@Override
+ public void setFrameworkModel(FrameworkModel frameworkModel) {
+ this.frameworkModel = frameworkModel;
+ }
+
+ @Override
public int getDefaultPort() {
return protocol.getDefaultPort();
}
@@ -103,7 +113,7 @@ public class QosProtocolWrapper implements Protocol {
String host = url.getParameter(QOS_HOST);
int port = url.getParameter(QOS_PORT, QosConstants.DEFAULT_PORT);
boolean acceptForeignIp = Boolean.parseBoolean(url.getParameter(ACCEPT_FOREIGN_IP, "false"));
- Server server = Server.getInstance();
+ Server server = frameworkModel.getBeanFactory().getBean(Server.class);
server.setHost(host);
server.setPort(port);
server.setAcceptForeignIp(acceptForeignIp);
@@ -116,7 +126,7 @@ public class QosProtocolWrapper implements Protocol {
/*package*/ void stopServer() {
if (hasStarted.compareAndSet(true, false)) {
- Server server = Server.getInstance();
+ Server server = frameworkModel.getBeanFactory().getBean(Server.class);
server.stop();
}
}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java
index 0f33ae3..2689ecd 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.qos.server.handler.QosProcessHandler;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
@@ -43,11 +44,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class Server {
private static final Logger logger = LoggerFactory.getLogger(Server.class);
- private static final Server INSTANCE = new Server();
-
- public static final Server getInstance() {
- return INSTANCE;
- }
private String host;
@@ -59,8 +55,11 @@ public class Server {
private EventLoopGroup worker;
- private Server() {
+ private FrameworkModel frameworkModel;
+
+ public Server(FrameworkModel frameworkModel) {
this.welcome = DubboLogo.DUBBO;
+ this.frameworkModel = frameworkModel;
}
private String welcome;
@@ -96,7 +95,7 @@ public class Server {
@Override
protected void initChannel(Channel ch) throws Exception {
- ch.pipeline().addLast(new QosProcessHandler(welcome, acceptForeignIp));
+ ch.pipeline().addLast(new QosProcessHandler(frameworkModel, welcome, acceptForeignIp));
}
});
try {
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/HttpProcessHandler.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/HttpProcessHandler.java
index 07af64d..48aad6a 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/HttpProcessHandler.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/HttpProcessHandler.java
@@ -23,6 +23,7 @@ import org.apache.dubbo.qos.command.CommandExecutor;
import org.apache.dubbo.qos.command.DefaultCommandExecutor;
import org.apache.dubbo.qos.command.NoSuchCommandException;
import org.apache.dubbo.qos.command.decoder.HttpCommandDecoder;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
@@ -50,8 +51,11 @@ import io.netty.handler.codec.http.HttpVersion;
public class HttpProcessHandler extends SimpleChannelInboundHandler<HttpRequest> {
private static final Logger log = LoggerFactory.getLogger(HttpProcessHandler.class);
- private static CommandExecutor commandExecutor = new DefaultCommandExecutor();
+ private CommandExecutor commandExecutor;
+ public HttpProcessHandler(FrameworkModel frameworkModel) {
+ this.commandExecutor = new DefaultCommandExecutor(frameworkModel);
+ }
private static FullHttpResponse http(int httpCode, String result) {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(httpCode)
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/QosProcessHandler.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/QosProcessHandler.java
index 836b3aa..f1dc1ee 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/QosProcessHandler.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/QosProcessHandler.java
@@ -17,6 +17,7 @@
package org.apache.dubbo.qos.server.handler;
import org.apache.dubbo.common.utils.ExecutorUtil;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -44,9 +45,12 @@ public class QosProcessHandler extends ByteToMessageDecoder {
// true means to accept foreign IP
private boolean acceptForeignIp;
+ private FrameworkModel frameworkModel;
+
public static final String PROMPT = "dubbo>";
- public QosProcessHandler(String welcome, boolean acceptForeignIp) {
+ public QosProcessHandler(FrameworkModel frameworkModel, String welcome, boolean acceptForeignIp) {
+ this.frameworkModel = frameworkModel;
this.welcome = welcome;
this.acceptForeignIp = acceptForeignIp;
}
@@ -84,7 +88,7 @@ public class QosProcessHandler extends ByteToMessageDecoder {
}
p.addLast(new HttpServerCodec());
p.addLast(new HttpObjectAggregator(1048576));
- p.addLast(new HttpProcessHandler());
+ p.addLast(new HttpProcessHandler(frameworkModel));
p.remove(this);
} else {
p.addLast(new LineBasedFrameDecoder(2048));
@@ -92,7 +96,7 @@ public class QosProcessHandler extends ByteToMessageDecoder {
p.addLast(new StringEncoder(CharsetUtil.UTF_8));
p.addLast(new IdleStateHandler(0, 0, 5 * 60));
p.addLast(new TelnetIdleEventHandler());
- p.addLast(new TelnetProcessHandler());
+ p.addLast(new TelnetProcessHandler(frameworkModel));
p.remove(this);
}
}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandler.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandler.java
index e302e1a..4631401 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandler.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandler.java
@@ -25,6 +25,7 @@ import org.apache.dubbo.qos.command.DefaultCommandExecutor;
import org.apache.dubbo.qos.command.NoSuchCommandException;
import org.apache.dubbo.qos.command.decoder.TelnetCommandDecoder;
import org.apache.dubbo.qos.common.QosConstants;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
@@ -36,7 +37,11 @@ import io.netty.channel.SimpleChannelInboundHandler;
public class TelnetProcessHandler extends SimpleChannelInboundHandler<String> {
private static final Logger log = LoggerFactory.getLogger(TelnetProcessHandler.class);
- private static CommandExecutor commandExecutor = new DefaultCommandExecutor();
+ private final CommandExecutor commandExecutor;
+
+ public TelnetProcessHandler(FrameworkModel frameworkModel) {
+ this.commandExecutor = new DefaultCommandExecutor(frameworkModel);
+ }
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
diff --git a/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer b/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer
new file mode 100644
index 0000000..f678488
--- /dev/null
+++ b/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer
@@ -0,0 +1 @@
+qos=org.apache.dubbo.qos.QosScopeModelInitializer
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/DefaultCommandExecutorTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/DefaultCommandExecutorTest.java
index 6533900..8db17bf 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/DefaultCommandExecutorTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/DefaultCommandExecutorTest.java
@@ -17,6 +17,8 @@
package org.apache.dubbo.qos.command;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -27,14 +29,14 @@ public class DefaultCommandExecutorTest {
@Test
public void testExecute1() throws Exception {
Assertions.assertThrows(NoSuchCommandException.class, () -> {
- DefaultCommandExecutor executor = new DefaultCommandExecutor();
+ DefaultCommandExecutor executor = new DefaultCommandExecutor(FrameworkModel.defaultModel());
executor.execute(CommandContextFactory.newInstance("not-exit"));
});
}
@Test
public void testExecute2() throws Exception {
- DefaultCommandExecutor executor = new DefaultCommandExecutor();
+ DefaultCommandExecutor executor = new DefaultCommandExecutor(FrameworkModel.defaultModel());
String result = executor.execute(CommandContextFactory.newInstance("greeting", new String[]{"dubbo"}, false));
assertThat(result, equalTo("greeting dubbo"));
}
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ChangeTelnetTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ChangeTelnetTest.java
index b349f9d..cd0f6be 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ChangeTelnetTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ChangeTelnetTest.java
@@ -24,6 +24,7 @@ import org.apache.dubbo.qos.legacy.ProtocolUtils;
import org.apache.dubbo.qos.legacy.service.DemoService;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
import io.netty.channel.Channel;
@@ -40,7 +41,7 @@ import static org.mockito.Mockito.reset;
public class ChangeTelnetTest {
private final DefaultAttributeMap defaultAttributeMap = new DefaultAttributeMap();
- private static final BaseCommand change = new ChangeTelnet();
+ private static final BaseCommand change = new ChangeTelnet(FrameworkModel.defaultModel());
private Channel mockChannel;
private CommandContext mockCommandContext;
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/CountTelnetTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/CountTelnetTest.java
index 113be4d..8f40b3f 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/CountTelnetTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/CountTelnetTest.java
@@ -27,6 +27,7 @@ import org.apache.dubbo.remoting.telnet.support.TelnetUtils;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.RpcStatus;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
import org.junit.jupiter.api.AfterEach;
@@ -44,7 +45,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
public class CountTelnetTest {
- private static final BaseCommand count = new CountTelnet();
+ private static final BaseCommand count = new CountTelnet(FrameworkModel.defaultModel());
private MockNettyChannel mockChannel;
private Invoker<DemoService> mockInvoker;
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/HelpTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/HelpTest.java
index 0b97313..642637d 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/HelpTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/HelpTest.java
@@ -17,16 +17,18 @@
package org.apache.dubbo.qos.command.impl;
import org.apache.dubbo.qos.command.CommandContext;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
public class HelpTest {
@Test
public void testMainHelp() throws Exception {
- Help help = new Help();
+ Help help = new Help(FrameworkModel.defaultModel());
String output = help.execute(Mockito.mock(CommandContext.class), null);
assertThat(output, containsString("greeting"));
assertThat(output, containsString("help"));
@@ -38,7 +40,7 @@ public class HelpTest {
@Test
public void testGreeting() throws Exception {
- Help help = new Help();
+ Help help = new Help(FrameworkModel.defaultModel());
String output = help.execute(Mockito.mock(CommandContext.class), new String[]{"greeting"});
assertThat(output, containsString("COMMAND NAME"));
assertThat(output, containsString("greeting"));
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/InvokeTelnetTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/InvokeTelnetTest.java
index 0e2ee82..e2e97ea 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/InvokeTelnetTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/InvokeTelnetTest.java
@@ -16,8 +16,6 @@
*/
package org.apache.dubbo.qos.command.impl;
-import io.netty.channel.Channel;
-import io.netty.util.DefaultAttributeMap;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
@@ -26,8 +24,12 @@ import org.apache.dubbo.qos.legacy.service.DemoService;
import org.apache.dubbo.qos.legacy.service.DemoServiceImpl;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleServiceRepository;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
+
+import io.netty.channel.Channel;
+import io.netty.util.DefaultAttributeMap;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -40,8 +42,9 @@ import static org.mockito.Mockito.reset;
public class InvokeTelnetTest {
- private static final BaseCommand invoke = new InvokeTelnet();
- private static final BaseCommand select = new SelectTelnet();
+ private FrameworkModel frameworkModel;
+ private BaseCommand invoke;
+ private BaseCommand select;
private Channel mockChannel;
private CommandContext mockCommandContext;
private final DefaultAttributeMap defaultAttributeMap = new DefaultAttributeMap();
@@ -50,16 +53,20 @@ public class InvokeTelnetTest {
@BeforeEach
public void setup() {
DubboBootstrap.reset();
+ frameworkModel = new FrameworkModel();
+ invoke = new InvokeTelnet(frameworkModel);
+ select = new SelectTelnet(frameworkModel);
mockChannel = mock(Channel.class);
mockCommandContext = mock(CommandContext.class);
given(mockCommandContext.getRemote()).willReturn(mockChannel);
- repository = ApplicationModel.defaultModel().getDefaultModule().getServiceRepository();
+ ApplicationModel applicationModel = new ApplicationModel(frameworkModel);
+ repository = applicationModel.getDefaultModule().getServiceRepository();
}
@AfterEach
public void after() {
ProtocolUtils.closeAll();
- DubboBootstrap.reset();
+ frameworkModel.destroy();
reset(mockChannel, mockCommandContext);
}
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/PortTelnetTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/PortTelnetTest.java
index dbbc476..ed98538 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/PortTelnetTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/PortTelnetTest.java
@@ -28,6 +28,7 @@ import org.apache.dubbo.remoting.exchange.ExchangeClient;
import org.apache.dubbo.remoting.exchange.Exchangers;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
import org.junit.jupiter.api.AfterEach;
@@ -41,7 +42,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
public class PortTelnetTest {
- private static final BaseCommand port = new PortTelnet();
+ private static final BaseCommand port = new PortTelnet(FrameworkModel.defaultModel());
private Invoker<DemoService> mockInvoker;
private CommandContext mockCommandContext;
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/SelectTelnetTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/SelectTelnetTest.java
index 9d1196b..1de057a 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/SelectTelnetTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/SelectTelnetTest.java
@@ -16,8 +16,6 @@
*/
package org.apache.dubbo.qos.command.impl;
-import io.netty.channel.Channel;
-import io.netty.util.DefaultAttributeMap;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
@@ -26,8 +24,12 @@ import org.apache.dubbo.qos.legacy.service.DemoService;
import org.apache.dubbo.qos.legacy.service.DemoServiceImpl;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleServiceRepository;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
+
+import io.netty.channel.Channel;
+import io.netty.util.DefaultAttributeMap;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -43,7 +45,7 @@ import static org.mockito.Mockito.reset;
public class SelectTelnetTest {
- private static BaseCommand select = new SelectTelnet();
+ private static BaseCommand select = new SelectTelnet(FrameworkModel.defaultModel());
private Channel mockChannel;
private CommandContext mockCommandContext;
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ShutdownTelnetTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ShutdownTelnetTest.java
index 76aae44..e9b208a 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ShutdownTelnetTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ShutdownTelnetTest.java
@@ -16,11 +16,13 @@
*/
package org.apache.dubbo.qos.command.impl;
-import io.netty.channel.Channel;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.legacy.ProtocolUtils;
import org.apache.dubbo.remoting.RemotingException;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
+import io.netty.channel.Channel;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -32,7 +34,7 @@ import static org.mockito.Mockito.reset;
public class ShutdownTelnetTest {
- private static final BaseCommand shutdown = new ShutdownTelnet();
+ private static final BaseCommand shutdown = new ShutdownTelnet(FrameworkModel.defaultModel());
private Channel mockChannel;
private CommandContext mockCommandContext;
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java
index f2719e9..328e8f9 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java
@@ -21,7 +21,6 @@ import org.apache.dubbo.qos.command.impl.ChangeTelnet;
import org.apache.dubbo.qos.command.impl.CountTelnet;
import org.apache.dubbo.qos.command.impl.Help;
import org.apache.dubbo.qos.command.impl.InvokeTelnet;
-import org.apache.dubbo.qos.command.impl.InvokeTelnetTest;
import org.apache.dubbo.qos.command.impl.Live;
import org.apache.dubbo.qos.command.impl.Ls;
import org.apache.dubbo.qos.command.impl.Offline;
@@ -39,6 +38,7 @@ import org.apache.dubbo.qos.command.impl.SelectTelnet;
import org.apache.dubbo.qos.command.impl.ShutdownTelnet;
import org.apache.dubbo.qos.command.impl.Startup;
import org.apache.dubbo.qos.command.impl.Version;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.junit.jupiter.api.Test;
@@ -53,15 +53,16 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CommandHelperTest {
+ private CommandHelper commandHelper = new CommandHelper(FrameworkModel.defaultModel());
@Test
public void testHasCommand() throws Exception {
- assertTrue(CommandHelper.hasCommand("greeting"));
- assertFalse(CommandHelper.hasCommand("not-exiting"));
+ assertTrue(commandHelper.hasCommand("greeting"));
+ assertFalse(commandHelper.hasCommand("not-exiting"));
}
@Test
public void testGetAllCommandClass() throws Exception {
- List<Class<?>> classes = CommandHelper.getAllCommandClass();
+ List<Class<?>> classes = commandHelper.getAllCommandClass();
// update this list when introduce a new command
List<Class<?>> expectedClasses = new LinkedList<>();
@@ -92,7 +93,7 @@ public class CommandHelperTest {
@Test
public void testGetCommandClass() throws Exception {
- assertThat(CommandHelper.getCommandClass("greeting"), equalTo(GreetingCommand.class));
- assertNull(CommandHelper.getCommandClass("not-exiting"));
+ assertThat(commandHelper.getCommandClass("greeting"), equalTo(GreetingCommand.class));
+ assertNull(commandHelper.getCommandClass("not-exiting"));
}
}
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java
index daac933..1a45665 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java
@@ -21,6 +21,7 @@ import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.server.Server;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
+import org.apache.dubbo.rpc.model.FrameworkModel;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -42,8 +43,8 @@ public class QosProtocolWrapperTest {
private URL url = Mockito.mock(URL.class);
private Invoker invoker = mock(Invoker.class);
private Protocol protocol = mock(Protocol.class);
- private QosProtocolWrapper wrapper = new QosProtocolWrapper(protocol);
- private Server server = Server.getInstance();
+ private QosProtocolWrapper wrapper;
+ private Server server;
@BeforeEach
public void setUp() throws Exception {
@@ -53,6 +54,9 @@ public class QosProtocolWrapperTest {
when(url.getParameter(ACCEPT_FOREIGN_IP, true)).thenReturn(false);
when(invoker.getUrl()).thenReturn(url);
when(url.getProtocol()).thenReturn(REGISTRY_PROTOCOL);
+ server = FrameworkModel.defaultModel().getBeanFactory().getBean(Server.class);
+ wrapper = new QosProtocolWrapper(protocol);
+ wrapper.setFrameworkModel(FrameworkModel.defaultModel());
}
@AfterEach
@@ -60,6 +64,7 @@ public class QosProtocolWrapperTest {
if (server.isStarted()) {
server.stop();
}
+ FrameworkModel.defaultModel().destroy();
}
@Test
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/HttpProcessHandlerTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/HttpProcessHandlerTest.java
index 12194ad..ba3f3cc 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/HttpProcessHandlerTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/HttpProcessHandlerTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.dubbo.qos.server.handler;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
@@ -26,8 +28,8 @@ import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
-import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -41,7 +43,7 @@ public class HttpProcessHandlerTest {
when(context.writeAndFlush(any(FullHttpResponse.class))).thenReturn(future);
HttpRequest message = Mockito.mock(HttpRequest.class);
when(message.getUri()).thenReturn("test");
- HttpProcessHandler handler = new HttpProcessHandler();
+ HttpProcessHandler handler = new HttpProcessHandler(FrameworkModel.defaultModel());
handler.channelRead0(context, message);
verify(future).addListener(ChannelFutureListener.CLOSE);
ArgumentCaptor<FullHttpResponse> captor = ArgumentCaptor.forClass(FullHttpResponse.class);
@@ -58,7 +60,7 @@ public class HttpProcessHandlerTest {
HttpRequest message = Mockito.mock(HttpRequest.class);
when(message.getUri()).thenReturn("localhost:80/greeting");
when(message.getMethod()).thenReturn(HttpMethod.GET);
- HttpProcessHandler handler = new HttpProcessHandler();
+ HttpProcessHandler handler = new HttpProcessHandler(FrameworkModel.defaultModel());
handler.channelRead0(context, message);
verify(future).addListener(ChannelFutureListener.CLOSE);
ArgumentCaptor<FullHttpResponse> captor = ArgumentCaptor.forClass(FullHttpResponse.class);
@@ -75,7 +77,7 @@ public class HttpProcessHandlerTest {
HttpRequest message = Mockito.mock(HttpRequest.class);
when(message.getUri()).thenReturn("localhost:80/test");
when(message.getMethod()).thenReturn(HttpMethod.GET);
- HttpProcessHandler handler = new HttpProcessHandler();
+ HttpProcessHandler handler = new HttpProcessHandler(FrameworkModel.defaultModel());
handler.channelRead0(context, message);
verify(future).addListener(ChannelFutureListener.CLOSE);
ArgumentCaptor<FullHttpResponse> captor = ArgumentCaptor.forClass(FullHttpResponse.class);
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/QosProcessHandlerTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/QosProcessHandlerTest.java
index a89aa10..271a277 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/QosProcessHandlerTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/QosProcessHandlerTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.dubbo.qos.server.handler;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
@@ -40,7 +42,7 @@ public class QosProcessHandlerTest {
ChannelHandlerContext context = Mockito.mock(ChannelHandlerContext.class);
ChannelPipeline pipeline = Mockito.mock(ChannelPipeline.class);
Mockito.when(context.pipeline()).thenReturn(pipeline);
- QosProcessHandler handler = new QosProcessHandler("welcome", false);
+ QosProcessHandler handler = new QosProcessHandler(FrameworkModel.defaultModel(), "welcome", false);
handler.decode(context, buf, Collections.emptyList());
verify(pipeline).addLast(any(HttpServerCodec.class));
verify(pipeline).addLast(any(HttpObjectAggregator.class));
@@ -54,7 +56,7 @@ public class QosProcessHandlerTest {
ChannelHandlerContext context = Mockito.mock(ChannelHandlerContext.class);
ChannelPipeline pipeline = Mockito.mock(ChannelPipeline.class);
Mockito.when(context.pipeline()).thenReturn(pipeline);
- QosProcessHandler handler = new QosProcessHandler("welcome", false);
+ QosProcessHandler handler = new QosProcessHandler(FrameworkModel.defaultModel(), "welcome", false);
handler.decode(context, buf, Collections.emptyList());
verify(pipeline).addLast(any(LineBasedFrameDecoder.class));
verify(pipeline).addLast(any(StringDecoder.class));
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandlerTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandlerTest.java
index fce6577..759d664 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandlerTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandlerTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.dubbo.qos.server.handler;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
@@ -23,9 +25,9 @@ import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -34,7 +36,7 @@ public class TelnetProcessHandlerTest {
@Test
public void testPrompt() throws Exception {
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
- TelnetProcessHandler handler = new TelnetProcessHandler();
+ TelnetProcessHandler handler = new TelnetProcessHandler(FrameworkModel.defaultModel());
handler.channelRead0(context, "");
verify(context).writeAndFlush(QosProcessHandler.PROMPT);
}
@@ -42,7 +44,7 @@ public class TelnetProcessHandlerTest {
@Test
public void testBye() throws Exception {
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
- TelnetProcessHandler handler = new TelnetProcessHandler();
+ TelnetProcessHandler handler = new TelnetProcessHandler(FrameworkModel.defaultModel());
ChannelFuture future = mock(ChannelFuture.class);
when(context.writeAndFlush("BYE!\n")).thenReturn(future);
handler.channelRead0(context, "quit");
@@ -52,7 +54,7 @@ public class TelnetProcessHandlerTest {
@Test
public void testUnknownCommand() throws Exception {
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
- TelnetProcessHandler handler = new TelnetProcessHandler();
+ TelnetProcessHandler handler = new TelnetProcessHandler(FrameworkModel.defaultModel());
handler.channelRead0(context, "unknown");
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(context, Mockito.atLeastOnce()).writeAndFlush(captor.capture());
@@ -62,7 +64,7 @@ public class TelnetProcessHandlerTest {
@Test
public void testGreeting() throws Exception {
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
- TelnetProcessHandler handler = new TelnetProcessHandler();
+ TelnetProcessHandler handler = new TelnetProcessHandler(FrameworkModel.defaultModel());
handler.channelRead0(context, "greeting");
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(context).writeAndFlush(captor.capture());
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscoveryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscoveryFactory.java
index 90d8127..07e1d60 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscoveryFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscoveryFactory.java
@@ -33,9 +33,9 @@ import java.util.concurrent.ConcurrentMap;
*/
public abstract class AbstractServiceDiscoveryFactory implements ServiceDiscoveryFactory {
- private static final ConcurrentMap<String, ServiceDiscovery> discoveries = new ConcurrentHashMap<>();
+ private final ConcurrentMap<String, ServiceDiscovery> discoveries = new ConcurrentHashMap<>();
- public static List<ServiceDiscovery> getAllServiceDiscoveries() {
+ public List<ServiceDiscovery> getAllServiceDiscoveries() {
return Collections.unmodifiableList(new LinkedList<>(discoveries.values()));
}
diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java
index 49d099d..dadada1 100644
--- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java
@@ -17,7 +17,6 @@
package org.apache.dubbo.remoting.transport.dispatcher;
import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.threadpool.manager.ExecutorRepository;
@@ -132,7 +131,7 @@ public class WrappedChannelHandler implements ChannelHandlerDelegate {
*/
public ExecutorService getSharedExecutorService() {
ExecutorRepository executorRepository =
- ExtensionLoader.getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
+ url.getOrDefaultApplicationModel().getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
ExecutorService executor = executorRepository.getExecutor(url);
if (executor == null) {
executor = executorRepository.createExecutorIfAbsent(url);