From d41e7225d026b2e35ed78719e4ef4fa53b201fd8 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Mon, 25 Dec 2017 14:09:49 +0800 Subject: [PATCH] #1104 I18N effort for dubbo code base - dubbo-plugin --- dubbo-plugin/dubbo-qos/pom.xml | 16 ++ .../dubbo/qos/command/BaseCommand.java | 20 ++- .../dubbo/qos/command/CommandContext.java | 20 ++- .../qos/command/CommandContextFactory.java | 20 ++- .../dubbo/qos/command/CommandExecutor.java | 30 ++-- .../dubbo/qos/command/CommandImpl/Help.java | 22 ++- .../dubbo/qos/command/CommandImpl/Ls.java | 20 ++- .../qos/command/CommandImpl/Offline.java | 20 ++- .../dubbo/qos/command/CommandImpl/Online.java | 20 ++- .../dubbo/qos/command/CommandImpl/Quit.java | 20 ++- .../qos/command/DefaultCommandExecutor.java | 20 ++- .../qos/command/NoSuchCommandException.java | 20 ++- .../dubbo/qos/command/annotation/Cmd.java | 34 +++-- .../command/decoder/HttpCommandDecoder.java | 24 ++- .../command/decoder/TelnetCommandDecoder.java | 20 ++- .../dubbo/qos/command/util/CommandHelper.java | 20 ++- .../alibaba/dubbo/qos/common/Constants.java | 24 ++- .../alibaba/dubbo/qos/server/DubboLogo.java | 20 ++- .../com/alibaba/dubbo/qos/server/Server.java | 40 +++-- .../server/handler/HttpProcessHandler.java | 40 +++-- .../handler/LocalHostPermitHandler.java | 20 ++- .../qos/server/handler/QosProcessHandler.java | 27 +++- .../server/handler/TelnetProcessHandler.java | 23 ++- .../alibaba/dubbo/qos/textui/TComponent.java | 21 ++- .../com/alibaba/dubbo/qos/textui/TKv.java | 28 ++-- .../com/alibaba/dubbo/qos/textui/TLadder.java | 34 +++-- .../com/alibaba/dubbo/qos/textui/TTable.java | 142 ++++++++++-------- .../com/alibaba/dubbo/qos/textui/TTree.java | 59 +++++--- .../java/com/alibaba/StringSplitTest.java | 20 ++- .../com/alibaba/dubbo/qos/textui/TKvTest.java | 20 ++- dubbo-plugin/pom.xml | 16 ++ 31 files changed, 629 insertions(+), 251 deletions(-) diff --git a/dubbo-plugin/dubbo-qos/pom.xml b/dubbo-plugin/dubbo-qos/pom.xml index fb8fb8253c..beb17087fe 100644 --- a/dubbo-plugin/dubbo-qos/pom.xml +++ b/dubbo-plugin/dubbo-qos/pom.xml @@ -1,3 +1,19 @@ + diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/BaseCommand.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/BaseCommand.java index f928ec4701..731abb9e0a 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/BaseCommand.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/BaseCommand.java @@ -1,11 +1,23 @@ +/* + * 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 com.alibaba.dubbo.qos.command; import com.alibaba.dubbo.common.extension.SPI; -/** - * @author qinliujie - * @date 2017/11/21 - */ @SPI public interface BaseCommand { String execute(CommandContext commandContext,String[] args); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandContext.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandContext.java index 470455f174..995ed0223b 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandContext.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandContext.java @@ -1,11 +1,23 @@ +/* + * 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 com.alibaba.dubbo.qos.command; import io.netty.channel.Channel; -/** - * @author qinliujie - * @date 2017/11/17 - */ public class CommandContext { private String commandName; private String[] args; diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandContextFactory.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandContextFactory.java index e905845117..1f28ab3fd6 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandContextFactory.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandContextFactory.java @@ -1,9 +1,21 @@ +/* + * 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 com.alibaba.dubbo.qos.command; -/** - * @author qinliujie - * @date 2017/11/17 - */ public class CommandContextFactory { public static CommandContext newInstance(String commandName){ return new CommandContext(commandName); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandExecutor.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandExecutor.java index 1f0ea5a858..15663a348d 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandExecutor.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandExecutor.java @@ -1,18 +1,28 @@ +/* + * 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 com.alibaba.dubbo.qos.command; -/** - * @author qinliujie - * @date 2017/11/17 - */ public interface CommandExecutor { /** - *
-     * 执行一个命令,返回对应命令执行的结果
-     * 
+ * Execute one command and return the execution result * - * @param commandContext - * 命令 - * @return + * @param commandContext command context + * @return command execution result + * @throws NoSuchCommandException */ String execute(CommandContext commandContext) throws NoSuchCommandException; } diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Help.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Help.java index e027eefabc..0ae5ec7d1b 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Help.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Help.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.command.CommandImpl; import com.alibaba.dubbo.qos.command.BaseCommand; @@ -10,10 +26,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -/** - * @author qinliujie - * @date 2017/11/21 - */ @Cmd(name = "help", summary = "help command", example = { "help", "help online" @@ -62,7 +74,7 @@ public class Help implements BaseCommand { } /* - * 输出主帮助菜单 + * output main help */ private String mainHelp() { diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Ls.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Ls.java index a44456cb95..f8ac47e676 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Ls.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Ls.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.command.CommandImpl; import com.alibaba.dubbo.config.model.ApplicationModel; @@ -14,10 +30,6 @@ import com.alibaba.dubbo.registry.support.ProviderInvokerWrapper; import java.util.Collection; import java.util.Set; -/** - * @author qinliujie - * @date 2017/11/22 - */ @Cmd(name = "ls", summary = "ls service", example = { "ls" }) diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Offline.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Offline.java index 4ea6604f6f..2d20d05eaa 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Offline.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Offline.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.command.CommandImpl; import com.alibaba.dubbo.common.extension.ExtensionLoader; @@ -16,10 +32,6 @@ import com.alibaba.dubbo.registry.support.ProviderInvokerWrapper; import java.util.List; import java.util.Set; -/** - * @author qinliujie - * @date 2017/11/21 - */ @Cmd(name = "offline", summary = "offline dubbo", example = { "offline dubbo", "offline xx.xx.xxx.service" diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Online.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Online.java index 1870c4228c..1321bcf9a8 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Online.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Online.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.command.CommandImpl; import com.alibaba.dubbo.common.extension.ExtensionLoader; @@ -16,10 +32,6 @@ import com.alibaba.dubbo.registry.support.ProviderInvokerWrapper; import java.util.List; import java.util.Set; -/** - * @author qinliujie - * @date 2017/11/21 - */ @Cmd(name = "online", summary = "online dubbo", example = { "online dubbo", "online xx.xx.xxx.service" diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Quit.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Quit.java index 3385e0190e..4ca05b8e45 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Quit.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/CommandImpl/Quit.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.command.CommandImpl; import com.alibaba.dubbo.qos.command.BaseCommand; @@ -5,10 +21,6 @@ import com.alibaba.dubbo.qos.command.CommandContext; import com.alibaba.dubbo.qos.command.annotation.Cmd; import com.alibaba.dubbo.qos.common.Constants; -/** - * @author qinliujie - * @date 2017/11/21 - */ @Cmd(name = "quit",summary = "quit telnet console") public class Quit implements BaseCommand { @Override diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/DefaultCommandExecutor.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/DefaultCommandExecutor.java index 994f77409d..9603705cd4 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/DefaultCommandExecutor.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/DefaultCommandExecutor.java @@ -1,11 +1,23 @@ +/* + * 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 com.alibaba.dubbo.qos.command; import com.alibaba.dubbo.common.extension.ExtensionLoader; -/** - * @author qinliujie - * @date 2017/11/17 - */ public class DefaultCommandExecutor implements CommandExecutor { @Override public String execute(CommandContext commandContext) throws NoSuchCommandException { diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/NoSuchCommandException.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/NoSuchCommandException.java index f4a6224bd8..4b4437504a 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/NoSuchCommandException.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/NoSuchCommandException.java @@ -1,9 +1,21 @@ +/* + * 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 com.alibaba.dubbo.qos.command; -/** - * @author qinliujie - * @date 2017/11/17 - */ public class NoSuchCommandException extends Exception { public NoSuchCommandException(String msg) { super("NoSuchCommandException:" + msg); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/annotation/Cmd.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/annotation/Cmd.java index a523ce2e39..3fc63a7a53 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/annotation/Cmd.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/annotation/Cmd.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.command.annotation; import java.lang.annotation.ElementType; @@ -6,37 +22,37 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * 指令集 + * Command */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Cmd { /** - * 指定命令的名称
+ * Command name * - * @return 返回命令的名称 + * @return command name */ String name(); /** - * 指定命令的解释 + * Command description * - * @return 返回命令的解释 + * @return command description */ String summary(); /** - * 例子 + * Command example * - * @return 返回命令的例子 + * @return command example */ String[] example() default {}; /** - * 排序,在help命令中 + * Command order in help * - * @return 返回命令在目录中的排序 + * @return command order in help */ int sort() default 0; } diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/decoder/HttpCommandDecoder.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/decoder/HttpCommandDecoder.java index f6a4c49620..4e96df6cfe 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/decoder/HttpCommandDecoder.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/decoder/HttpCommandDecoder.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.command.decoder; import com.alibaba.dubbo.qos.command.CommandContext; @@ -14,10 +30,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -/** - * @author qinliujie - * @date 2017/11/17 - */ public class HttpCommandDecoder { public static CommandContext decode(HttpRequest request) { CommandContext commandContext = null; @@ -28,9 +40,7 @@ public class HttpCommandDecoder { if (array.length == 2) { String name = array[1]; - // Get请求和Post请求分开处理 - // Get看url的Path - // Post看请求正文 + // process GET request and POST request separately. Check url for GET, and check body for POST if (request.getMethod() == HttpMethod.GET) { if (queryStringDecoder.parameters().isEmpty()) { commandContext = CommandContextFactory.newInstance(name); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/decoder/TelnetCommandDecoder.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/decoder/TelnetCommandDecoder.java index 368c233977..6ffd680766 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/decoder/TelnetCommandDecoder.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/decoder/TelnetCommandDecoder.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.command.decoder; import com.alibaba.dubbo.qos.command.CommandContext; @@ -5,10 +21,6 @@ import com.alibaba.dubbo.qos.command.CommandContextFactory; import org.apache.commons.lang3.StringUtils; -/** - * @author qinliujie - * @date 2017/11/17 - */ public class TelnetCommandDecoder { public static final CommandContext decode(String str) { CommandContext commandContext = null; diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/util/CommandHelper.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/util/CommandHelper.java index c5c11cce50..860f7eab8e 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/util/CommandHelper.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/command/util/CommandHelper.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.command.util; import com.alibaba.dubbo.common.extension.ExtensionLoader; @@ -7,10 +23,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -/** - * @author qinliujie - * @date 2017/11/21 - */ public class CommandHelper { public static boolean hasCommand(String commandName) { diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/common/Constants.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/common/Constants.java index 9eabef1c00..e7908ddbea 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/common/Constants.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/common/Constants.java @@ -1,17 +1,29 @@ +/* + * 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 com.alibaba.dubbo.qos.common; -/** - * @author qinliujie - * @date 2017/11/17 - */ public interface Constants { int DEFAULT_PORT = 22222; - // 通过-D参数指定port + // system property for specifying qos port String QOS_PORT = "dubbo.qos.port"; String BR_STR = "\r\n"; String CLOSE = "close!"; - // 通过-D参数指定当前qos是否能够拒绝外部ip的联入 + // system property for whether to accept foreign IP to connect or not String ACCEPT_FOREIGN_IP = "dubbo.qos.accept.foreign.ip"; } diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/DubboLogo.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/DubboLogo.java index de67b8f50d..cf2e44ce2b 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/DubboLogo.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/DubboLogo.java @@ -1,9 +1,21 @@ +/* + * 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 com.alibaba.dubbo.qos.server; -/** - * @author qinliujie - * @date 2017/11/21 - */ public class DubboLogo { public static String dubbo = " ████████▄ ███ █▄ ▀█████████▄ ▀█████████▄ ▄██████▄ \n" + diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/Server.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/Server.java index a49c1724cb..a7489bfdf3 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/Server.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/Server.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.server; import com.alibaba.dubbo.common.logger.Logger; @@ -5,7 +21,6 @@ import com.alibaba.dubbo.common.logger.LoggerFactory; import com.alibaba.dubbo.common.utils.ConfigUtils; import com.alibaba.dubbo.qos.common.Constants; import com.alibaba.dubbo.qos.server.handler.QosProcessHandler; - import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; @@ -18,15 +33,12 @@ import io.netty.util.concurrent.DefaultThreadFactory; import java.util.concurrent.atomic.AtomicBoolean; /** - *
- * 该Server监听指定的端口,能够提供telnet以及HTTP的访问
- *
- * 通过静态方法创建Server
- * 负责启动Server,绑定监听端口
- * 关闭Server
- * 
- * - * @author weipeng2k 2015年8月27日 上午11:29:27 + * A server serves for both telnet access and http access + *
    + *
  • static initialize server
  • + *
  • start server and bind port
  • + *
  • close server
  • + *
*/ public class Server { @@ -56,16 +68,14 @@ public class Server { private AtomicBoolean hasStarted = new AtomicBoolean(); /** - * 设置telnet提供的welcome信息 - * - * @param welcome + * welcome message */ public void setWelcome(String welcome) { this.welcome = welcome; } /** - * 启动server,绑定端口 + * start server, bind port */ public void start() throws Throwable { if (!hasStarted.compareAndSet(false, true)) { @@ -95,7 +105,7 @@ public class Server { } /** - * 关闭server + * close server */ public void stop() { logger.info("qos-server stopped."); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/HttpProcessHandler.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/HttpProcessHandler.java index bc20c38422..d73b21a9e8 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/HttpProcessHandler.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/HttpProcessHandler.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.server.handler; import com.alibaba.dubbo.common.logger.Logger; @@ -7,7 +23,6 @@ import com.alibaba.dubbo.qos.command.CommandExecutor; import com.alibaba.dubbo.qos.command.DefaultCommandExecutor; import com.alibaba.dubbo.qos.command.NoSuchCommandException; import com.alibaba.dubbo.qos.command.decoder.HttpCommandDecoder; - import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; @@ -20,17 +35,15 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; /** - *
- * 根据传入的HttpRequest进行解析,分析uri以及参数
- *
- * 如果命令没有找到返回404
- * 如果执行失败500
- * 执行成功则返回内容200
- *
- * Http连接均在执行完毕之后断开
- * 
- * - * @author weipeng2k 2015年9月1日 下午5:13:56 + * Parse HttpRequest for uri and parameters + *

+ *

    + *
  • if command not found, return 404
  • + *
  • if execution fails, return 500
  • + *
  • if succeed, return 200
  • + *
+ *

+ * will disconnect after execution finishes */ public class HttpProcessHandler extends SimpleChannelInboundHandler { @@ -41,7 +54,8 @@ public class HttpProcessHandler extends SimpleChannelInboundHandler @Override protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) throws Exception { CommandContext commandContext = HttpCommandDecoder.decode(msg); - if (commandContext == null) { // 如果命令无法构造返回404 + // return 404 when fail to construct command context + if (commandContext == null) { log.warn("can not found commandContext url: " + msg.getUri()); FullHttpResponse response = http_404(); ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/LocalHostPermitHandler.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/LocalHostPermitHandler.java index 26918a2df0..832cbce9f7 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/LocalHostPermitHandler.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/LocalHostPermitHandler.java @@ -1,5 +1,18 @@ -/** +/* + * 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 com.alibaba.dubbo.qos.server.handler; @@ -15,12 +28,9 @@ import io.netty.channel.ChannelHandlerContext; import java.net.InetSocketAddress; -/** - * @author weipeng2k 2015年9月6日 下午5:52:26 - */ public class LocalHostPermitHandler extends ChannelHandlerAdapter { - // true表示能够远端连接 + // true means to accept foreign IP private static boolean acceptForeignIp = Boolean.valueOf(ConfigUtils.getProperty(Constants.ACCEPT_FOREIGN_IP, "true")); @Override diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/QosProcessHandler.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/QosProcessHandler.java index d8fc3ea748..3100c3396b 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/QosProcessHandler.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/QosProcessHandler.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.server.handler; import io.netty.buffer.ByteBuf; @@ -17,10 +33,6 @@ import io.netty.util.concurrent.ScheduledFuture; import java.util.List; import java.util.concurrent.TimeUnit; -/** - * @author weipeng2k - * @author qinliujie - */ public class QosProcessHandler extends ByteToMessageDecoder { private ScheduledFuture welcomeFuture; @@ -54,13 +66,13 @@ public class QosProcessHandler extends ByteToMessageDecoder { return; } - // 读入一个byte来猜协议 + // read one byte to guess protocol final int magic = in.getByte(in.readerIndex()); ChannelPipeline p = ctx.pipeline(); p.addLast(new LocalHostPermitHandler()); if (isHttp(magic)) { - // HTTP协议不做welcome输出 + // no welcome output for http protocol if (welcomeFuture != null && welcomeFuture.isCancellable()) { welcomeFuture.cancel(false); } @@ -77,9 +89,8 @@ public class QosProcessHandler extends ByteToMessageDecoder { p.remove(this); } } - //Http 请求头 GET/POST,就酱紫 QWQ + // G for GET, and P for POST private static boolean isHttp(int magic) { return magic == 'G' || magic == 'P'; } - } diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/TelnetProcessHandler.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/TelnetProcessHandler.java index 3603834c55..92fdb322ec 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/TelnetProcessHandler.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/server/handler/TelnetProcessHandler.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.server.handler; @@ -16,12 +32,7 @@ import io.netty.channel.SimpleChannelInboundHandler; import org.apache.commons.lang3.StringUtils; /** - *

- * 接受telnet协议,其实就是用户提交的内容,使用\r\n结尾,当然已经被netty过滤了\r\n了。
- * 经过了StringDecoder相关的Decode过程
- * 
- * - * @author weipeng2k + * Telnet process handler */ public class TelnetProcessHandler extends SimpleChannelInboundHandler { diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TComponent.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TComponent.java index 3168e803dc..6f1d5313c8 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TComponent.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TComponent.java @@ -1,13 +1,28 @@ +/* + * 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 com.alibaba.dubbo.qos.textui; /** - * 命令行控件
- * Created by oldmanpushcart@gmail.com on 15/5/7. + * render component */ public interface TComponent { /** - * 渲染组件内容 + * render */ String rendering(); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TKv.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TKv.java index 38cd9f791c..5080462bb9 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TKv.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TKv.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.textui; import org.apache.commons.lang3.StringUtils; @@ -5,8 +21,7 @@ import org.apache.commons.lang3.StringUtils; import java.util.Scanner; /** - * KV排版控件 - * Created by oldmanpushcart@gmail.com on 15/5/9. + * KV */ public class TKv implements TComponent { @@ -42,13 +57,6 @@ public class TKv implements TComponent { return filterEmptyLine(tTable.rendering()); } - - /* - * 出现多余的空行的原因是,KVview在输出时,会补全空格到最长的长度。所以在"yyyyy”后面会多出来很多的空格。 - * 再经过TableView的固定列处理,多余的空格就会在一行里放不下,输出成两行(第二行前面是空格) - * - * @see https://github.com/oldmanpushcart/greys-anatomy/issues/82 - */ private String filterEmptyLine(String content) { final StringBuilder sb = new StringBuilder(); Scanner scanner = null; @@ -57,7 +65,7 @@ public class TKv implements TComponent { while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line != null) { - //清理一行后面多余的空格 + // remove extra space at line's end line = StringUtils.stripEnd(line, " "); if (line.isEmpty()) { line = " "; diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TLadder.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TLadder.java index 7fd7b36f6e..be70363855 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TLadder.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TLadder.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.textui; import java.util.ArrayList; @@ -6,18 +22,17 @@ import java.util.List; import static org.apache.commons.lang3.StringUtils.repeat; /** - * 阶梯缩进控件 - * Created by oldmanpushcart@gmail.com on 15/5/8. + * Ladder */ public class TLadder implements TComponent { - // 分隔符 + // separator private static final String LADDER_CHAR = "`-"; - // 缩进符 + // tab private static final String STEP_CHAR = " "; - // 缩进长度 + // indent length private static final int INDENT_STEP = 2; private final List items = new ArrayList(); @@ -29,14 +44,14 @@ public class TLadder implements TComponent { int deep = 0; for (String item : items) { - // 第一个条目不需要分隔符 + // no separator is required for the first item if (deep == 0) { ladderSB .append(item) .append("\n"); } - // 其他的需要添加分隔符 + // need separator for others else { ladderSB .append(repeat(STEP_CHAR, deep * INDENT_STEP)) @@ -52,10 +67,7 @@ public class TLadder implements TComponent { } /** - * 添加一个项目 - * - * @param item 项目 - * @return this + * add one item */ public TLadder addItem(String item) { items.add(item); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TTable.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TTable.java index 0c113ee0b0..377fd46fad 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TTable.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TTable.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.textui; import org.apache.commons.lang3.StringUtils; @@ -15,18 +31,17 @@ import static org.apache.commons.lang3.StringUtils.length; import static org.apache.commons.lang3.StringUtils.repeat; /** - * 表格组件 - * Created by oldmanpushcart@gmail.com on 15/5/7. + * Table */ public class TTable implements TComponent { - // 各个列的定义 + // column definition private final ColumnDefine[] columnDefineArray; - // 边框 + // border private final Border border = new Border(); - // 内边距 + // padding private int padding; public TTable(ColumnDefine[] columnDefineArray) { @@ -59,23 +74,23 @@ public class TTable implements TComponent { final boolean isFirstRow = rowIndex == 0; final boolean isLastRow = rowIndex == rowCount - 1; - // 打印首分隔行 + // print first separation line if (isFirstRow && border.has(Border.BORDER_OUTER_TOP)) { tableSB.append(drawSeparationLine(widthCacheArray)).append("\n"); } - // 打印内部分割行 + // print inner separation lines if (!isFirstRow && border.has(Border.BORDER_INNER_H)) { tableSB.append(drawSeparationLine(widthCacheArray)).append("\n"); } - // 绘一行 + // draw one line tableSB.append(drawRow(widthCacheArray, rowIndex)); - // 打印结尾分隔行 + // print ending separation line if (isLastRow && border.has(Border.BORDER_OUTER_BOTTOM)) { tableSB.append(drawSeparationLine(widthCacheArray)).append("\n"); @@ -189,8 +204,8 @@ public class TTable implements TComponent { } } - /* - * 获取表格行数 + /** + * get row count */ private int getRowCount() { int rowCount = 0; @@ -200,8 +215,8 @@ public class TTable implements TComponent { return rowCount; } - /* - * 定位最后一个列 + /** + * position to last column */ private int indexLastCol(final int[] widthCacheArray) { for (int colIndex = widthCacheArray.length - 1; colIndex >= 0; colIndex--) { @@ -214,8 +229,8 @@ public class TTable implements TComponent { return 0; } - /* - * 打印分隔行 + /** + * draw separation line */ private String drawSeparationLine(final int[] widthCacheArray) { final StringBuilder separationLineSB = new StringBuilder(); @@ -253,9 +268,7 @@ public class TTable implements TComponent { } /** - * 添加数据行 - * - * @param columnDataArray 数据数组 + * Add a row */ public TTable addRow(Object... columnDataArray) { @@ -276,41 +289,41 @@ public class TTable implements TComponent { /** - * 对齐方向 + * alignment */ public enum Align { /** - * 左对齐 + * left-alignment */ LEFT, /** - * 右对齐 + * right-alignment */ RIGHT, /** - * 居中对齐 + * middle-alignment */ MIDDLE } /** - * 列定义 + * column definition */ public static class ColumnDefine { - // 列宽度 + // column width private final int width; - // 是否自动宽度 + // whether to auto resize private final boolean isAutoResize; - // 对齐方式 + // alignment private final Align align; - // 数据行集合 + // data rows private final List rows = new ArrayList(); public ColumnDefine(int width, boolean isAutoResize, Align align) { @@ -336,18 +349,18 @@ public class TTable implements TComponent { } /** - * 获取当前列的宽度 + * get current width * - * @return 宽度 + * @return width */ public int getWidth() { - // 如果是固定宽度,则直接返回预设定的宽度 + // if not auto resize, return preset width if (!isAutoResize) { return width; } - // 如果是自动扩展宽度,则需要根据计算当前列的所有字符串最大可视宽度 + // if it's auto resize, then calculate the possible max width int maxWidth = 0; for (String data : rows) { maxWidth = max(width(data), maxWidth); @@ -357,9 +370,9 @@ public class TTable implements TComponent { } /** - * 获取当前列的行数 + * get rows for the current column * - * @return 当前列的行数 + * @return current column's rows */ public int getRowCount() { return rows.size(); @@ -368,9 +381,9 @@ public class TTable implements TComponent { } /** - * 设置内边距大小 + * set padding * - * @param padding 内边距 + * @param padding padding */ public TTable padding(int padding) { this.padding = padding; @@ -378,9 +391,9 @@ public class TTable implements TComponent { } /** - * 获取表格列总数 + * get column count * - * @return 表格列总数 + * @return column count */ public int getColumnCount() { return columnDefineArray.length; @@ -388,23 +401,22 @@ public class TTable implements TComponent { /** - * 替换TAB制表符
- * 替换为4个空格 + * replace tab to four spaces * - * @param string 原始字符串 - * @return 替换后的字符串 + * @param string the original string + * @return the replaced string */ private static String replaceTab(String string) { return StringUtils.replace(string, "\t", " "); } /** - * 获取一个字符串的可视宽度
- * 什么叫一个字符串的可视宽度呢?很简单,因为字符串有换行行为,所以一个字符串的宽度不能简单的根据字符串的长度来判断
- * 例如:"abc\n1234",这个字符串的可视宽度为4 + * visible width for the given string. * - * @param string 字符串 - * @return 字符串可视宽度 + * for example: "abc\n1234"'s width is 4. + * + * @param string the given string + * @return visible width */ private static int width(String string) { int maxWidth = 0; @@ -421,71 +433,71 @@ public class TTable implements TComponent { /** * 获取表格边框设置 + * get border * - * @return 表格边框 + * @return table border */ public Border getBorder() { return border; } /** - * 边框样式设置 + * border style */ public class Border { private int borders = BORDER_OUTER | BORDER_INNER; /** - * 外部上边框 + * border outer top */ public static final int BORDER_OUTER_TOP = 1 << 0; /** - * 外部右边框 + * border outer right */ public static final int BORDER_OUTER_RIGHT = 1 << 1; /** - * 外部下边框 + * border outer bottom */ public static final int BORDER_OUTER_BOTTOM = 1 << 2; /** - * 外部左边框 + * border outer left */ public static final int BORDER_OUTER_LEFT = 1 << 3; /** - * 内边框:水平 + * inner border: horizon */ public static final int BORDER_INNER_H = 1 << 4; /** - * 内边框:垂直 + * inner border: vertical */ public static final int BORDER_INNER_V = 1 << 5; /** - * 外边框 + * outer border */ public static final int BORDER_OUTER = BORDER_OUTER_TOP | BORDER_OUTER_BOTTOM | BORDER_OUTER_LEFT | BORDER_OUTER_RIGHT; /** - * 内边框 + * inner border */ public static final int BORDER_INNER = BORDER_INNER_H | BORDER_INNER_V; /** - * 无边框 + * no border */ public static final int BORDER_NON = 0; /** - * 是否包含指定边框类型
- * 只要当前边框策略命中其中之一即认为命中 + * whether has one of the specified border styles * - * @param borderArray 目标边框数组 - * @return 当前边框策略是否拥有指定的边框 + * @param borderArray border styles + * @return whether has one of the specified border styles */ public boolean has(int... borderArray) { if (null == borderArray) { @@ -500,18 +512,18 @@ public class TTable implements TComponent { } /** - * 获取表格边框设置 + * get border style * - * @return 边框位 + * @return border style */ public int get() { return borders; } /** - * 设置表格边框 + * set border style * - * @param border 边框位 + * @param border border style * @return this */ public Border set(int border) { diff --git a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TTree.java b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TTree.java index 0e81254216..9766fb33b4 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TTree.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/com/alibaba/dubbo/qos/textui/TTree.java @@ -1,3 +1,19 @@ +/* + * 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 com.alibaba.dubbo.qos.textui; import org.apache.commons.lang3.StringUtils; @@ -12,8 +28,7 @@ import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.apache.commons.lang3.StringUtils.repeat; /** - * 树形控件 - * Created by oldmanpushcart@gmail.com on 15/5/26. + * tree */ public class TTree implements TComponent { @@ -22,13 +37,13 @@ public class TTree implements TComponent { private static final String STEP_HAS_BOARD = "| "; private static final String STEP_EMPTY_BOARD = " "; - // 是否输出耗时 + // should output cost or not private final boolean isPrintCost; - // 根节点 + // tree node private final Node root; - // 当前节点 + // current node private Node current; @@ -93,7 +108,7 @@ public class TTree implements TComponent { } /** - * 递归遍历 + * recursive visit */ private void recursive(int deep, boolean isLast, String prefix, Node node, Callback callback) { callback.callback(deep, isLast, prefix, node); @@ -118,9 +133,9 @@ public class TTree implements TComponent { } /** - * 创建一个分支节点 + * create a branch node * - * @param data 节点数据 + * @param data node data * @return this */ public TTree begin(Object data) { @@ -149,7 +164,7 @@ public class TTree implements TComponent { } /** - * 结束一个分支节点 + * end a branch node * * @return this */ @@ -164,37 +179,37 @@ public class TTree implements TComponent { /** - * 树节点 + * tree node */ private static class Node { /** - * 父节点 + * parent node */ final Node parent; /** - * 节点数据 + * node data */ Object data; /** - * 子节点 + * child nodes */ final List children = new ArrayList(); /** - * 开始时间戳 + * begin timestamp */ private long beginTimestamp; /** - * 结束时间戳 + * end timestamp */ private long endTimestamp; /** - * 构造树节点(根节点) + * construct root node */ private Node(Object data) { this.parent = null; @@ -202,10 +217,10 @@ public class TTree implements TComponent { } /** - * 构造树节点 + * construct a regular node * - * @param parent 父节点 - * @param data 节点数据 + * @param parent parent node + * @param data node data */ private Node(Node parent, Object data) { this.parent = parent; @@ -214,7 +229,7 @@ public class TTree implements TComponent { } /** - * 是否根节点 + * is the current node the root node * * @return true / false */ @@ -223,7 +238,7 @@ public class TTree implements TComponent { } /** - * 是否叶子节点 + * if the current node the leaf node * * @return true / false */ @@ -245,7 +260,7 @@ public class TTree implements TComponent { /** - * 遍历回调接口 + * callback interface for recursive visit */ private interface Callback { diff --git a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/StringSplitTest.java b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/StringSplitTest.java index 524b7e6d84..499e0918d3 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/StringSplitTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/StringSplitTest.java @@ -1,11 +1,23 @@ +/* + * 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 com.alibaba; import org.junit.Test; -/** - * @author qinliujie - * @date 2017/11/20 - */ public class StringSplitTest { @Test public void stringSplitTest(){ diff --git a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java index e016b473c1..d0159e6411 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/com/alibaba/dubbo/qos/textui/TKvTest.java @@ -1,11 +1,23 @@ +/* + * 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 com.alibaba.dubbo.qos.textui; import org.junit.Test; -/** - * @author qinliujie - * @date 2017/11/17 - */ public class TKvTest { @Test public void outPutTest() { diff --git a/dubbo-plugin/pom.xml b/dubbo-plugin/pom.xml index 22df9980a9..6e808592c6 100644 --- a/dubbo-plugin/pom.xml +++ b/dubbo-plugin/pom.xml @@ -1,3 +1,19 @@ +