You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/08/08 02:45:31 UTC

[GitHub] [dubbo] CrazyHZM commented on a diff in pull request #10395: add qos protocol to pu server

CrazyHZM commented on code in PR #10395:
URL: https://github.com/apache/dubbo/pull/10395#discussion_r939776695


##########
dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java:
##########
@@ -102,6 +104,14 @@ private void startQosServer(URL url) {
                     "dubbo.properties or XML/spring-boot configuration.");
                 return;
             }
+            // frameModel of mock url is null
+            FrameworkModel frameworkModel1= url.getOrDefaultFrameworkModel();
+            if (frameworkModel1 != null) {
+                WireProtocol protocol1 = frameworkModel1.getExtensionLoader(WireProtocol.class).getExtension("qos");
+                if(protocol1 != null) {
+                    ((QosWireProtocol) protocol1).SetQosEnable(true);

Review Comment:
   This will cause it to be turned on forever.
   



##########
dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.pu;
+
+import org.apache.dubbo.qos.command.BaseCommand;
+import org.apache.dubbo.qos.command.CommandContext;
+import org.apache.dubbo.qos.command.decoder.TelnetCommandDecoder;
+import org.apache.dubbo.remoting.api.ProtocolDetector;
+import org.apache.dubbo.remoting.buffer.ChannelBuffer;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
+import io.netty.util.CharsetUtil;
+
+
+public class TelnetDetector implements ProtocolDetector {
+
+    private FrameworkModel frameworkModel;
+    private final int MaxSize = 2048;
+
+    public void setFrameworkModel(FrameworkModel frameworkModel) {
+        this.frameworkModel = frameworkModel;
+    }
+
+    @Override
+    public Result detect(ChannelBuffer in) {
+        if (in.readableBytes() >= MaxSize) {
+            return Result.UNRECOGNIZED;
+        }
+        // if no \n is found and in.len() is ok, NEED_MORE_DATA
+        ChannelBuffer back = in.copy();
+        byte[] backBytes = new byte[back.readableBytes()];
+        back.getBytes(back.readerIndex(), backBytes);
+
+        String s = new String(backBytes, CharsetUtil.UTF_8);
+        s = s.trim(); // trim /r/n to let parser work for the input

Review Comment:
   Comment code style should be unified.
   



##########
dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java:
##########
@@ -102,6 +104,14 @@ private void startQosServer(URL url) {
                     "dubbo.properties or XML/spring-boot configuration.");
                 return;
             }
+            // frameModel of mock url is null
+            FrameworkModel frameworkModel1= url.getOrDefaultFrameworkModel();

Review Comment:
   `frameworkModel` already exists
   



##########
dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/QosDetector.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.pu;
+
+import org.apache.dubbo.remoting.api.ProtocolDetector;
+import org.apache.dubbo.remoting.buffer.ChannelBuffer;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
+public class QosDetector implements ProtocolDetector {
+
+    private final QosHTTP1Detector qosHTTP1Detector = new QosHTTP1Detector();
+    private final TelnetDetector telnetDetector = new TelnetDetector();
+    private boolean QosEnableFlag = false;
+
+    public void setQosEnableFlag(boolean qosEnableFlag) {
+        QosEnableFlag = qosEnableFlag;
+    }
+
+    @Override
+    public Result detect(ChannelBuffer in) {
+        if(!QosEnableFlag) {
+            return Result.UNRECOGNIZED;
+        }
+        Result h1Res = qosHTTP1Detector.detect(in);
+        if(h1Res.equals(Result.RECOGNIZED)) {
+            return h1Res;
+        }
+        Result telRes = telnetDetector.detect(in);
+        if(telRes.equals(Result.RECOGNIZED)) {
+            return telRes;
+        }
+        if(h1Res.equals(Result.NEED_MORE_DATA) || telRes.equals(Result.NEED_MORE_DATA)) {
+            return Result.NEED_MORE_DATA;
+        }
+        return Result.UNRECOGNIZED;
+    }
+
+    public void setFrameWorkModel(FrameworkModel frameworkModel) {
+        this.telnetDetector.setFrameworkModel(frameworkModel);
+    }

Review Comment:
   implements `ScopeModelAware`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org