From 0bfd54cea412fef92e0ec36b2dc18136c4c3d4e0 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Fri, 1 Sep 2023 13:03:33 +0800 Subject: [PATCH] Cleanup and throw exception if bind failed (#12987) --- .../qos/protocol/QosProtocolWrapper.java | 7 +-- .../dubbo/qos/server/QosBindException.java | 26 ++++++++++ .../org/apache/dubbo/qos/server/Server.java | 19 ++++---- .../org/apache/dubbo/remoting/Constants.java | 4 ++ .../netty4/NettyPortUnificationServer.java | 47 +++++++++++-------- .../transport/netty4/NettyServer.java | 30 +++++++----- .../transport/netty4/ConnectionTest.java | 6 +-- .../netty4/PortUnificationServerTest.java | 5 +- ...ultiplexProtocolConnectionManagerTest.java | 7 ++- .../SingleProtocolConnectionManagerTest.java | 3 +- 10 files changed, 99 insertions(+), 55 deletions(-) create mode 100644 dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/QosBindException.java 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 d45ee69749..a8fa9ca754 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 @@ -96,7 +96,9 @@ public class QosProtocolWrapper implements Protocol, ScopeModelAware { return protocol.getServers(); } - private void startQosServer(URL url) { + private void startQosServer(URL url) throws RpcException { + boolean qosCheck = url.getParameter(QOS_CHECK, false); + try { if (!hasStarted.compareAndSet(false, true)) { return; @@ -132,9 +134,8 @@ public class QosProtocolWrapper implements Protocol, ScopeModelAware { } catch (Throwable throwable) { logger.warn(QOS_FAILED_START_SERVER, "", "", "Fail to start qos server: ", throwable); - boolean qosCheck = url.getParameter(QOS_CHECK, false); if (qosCheck) { - throw new IllegalStateException("Fail to start qos server: " + throwable.getMessage(), throwable); + throw new RpcException(throwable); } } } diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/QosBindException.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/QosBindException.java new file mode 100644 index 0000000000..57aecd228f --- /dev/null +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/QosBindException.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.dubbo.qos.server; + +/** + * Indicate that if Qos Start failed + */ +public class QosBindException extends RuntimeException { + public QosBindException(String message, Throwable cause) { + super(message, cause); + } +} 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 65e7e3b9fa..8bac2d8ab9 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 @@ -35,8 +35,6 @@ import io.netty.util.concurrent.DefaultThreadFactory; import java.util.concurrent.atomic.AtomicBoolean; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.QOS_FAILED_START_SERVER; - /** * A server serves for both telnet access and http access *