Small improvements for `sentinel-transport`
- Modify the init order of command center init func to -1 (prioritized than before) - Add CommandConstants for common use Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
parent
8096b22eb1
commit
d88ffcd697
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed 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.csp.sentinel.command;
|
||||
|
||||
/**
|
||||
* @author Eric Zhao
|
||||
* @since 1.4.1
|
||||
*/
|
||||
public final class CommandConstants {
|
||||
|
||||
public static final String VERSION_COMMAND = "version";
|
||||
|
||||
public static final String MSG_INVALID_COMMAND = "Invalid command";
|
||||
public static final String MSG_UNKNOWN_COMMAND_PREFIX = "Unknown command";
|
||||
|
||||
public static final String MSG_SUCCESS = "success";
|
||||
public static final String MSG_FAIL = "failed";
|
||||
|
||||
private CommandConstants() {}
|
||||
}
|
||||
|
|
@ -19,12 +19,14 @@ import java.util.Iterator;
|
|||
import java.util.ServiceLoader;
|
||||
|
||||
import com.alibaba.csp.sentinel.init.InitFunc;
|
||||
import com.alibaba.csp.sentinel.init.InitOrder;
|
||||
import com.alibaba.csp.sentinel.log.RecordLog;
|
||||
import com.alibaba.csp.sentinel.transport.CommandCenter;
|
||||
|
||||
/**
|
||||
* @author Eric Zhao
|
||||
*/
|
||||
@InitOrder(-1)
|
||||
public class CommandCenterInitFunc implements InitFunc {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class HttpEventTask implements Runnable {
|
|||
new OutputStreamWriter(outputStream, Charset.forName(SentinelConfig.charset())));
|
||||
|
||||
String line = in.readLine();
|
||||
CommandCenterLog.info("[CommandCenter] socket income:" + line
|
||||
CommandCenterLog.info("[SimpleHttpCommandCenter] socket income: " + line
|
||||
+ "," + socket.getInetAddress());
|
||||
CommandRequest request = parseRequest(line);
|
||||
|
||||
|
|
@ -95,10 +95,10 @@ public class HttpEventTask implements Runnable {
|
|||
printWriter.flush();
|
||||
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
CommandCenterLog.info("[CommandCenter] deal a socket task:" + line
|
||||
+ "," + socket.getInetAddress() + ", time cost=" + cost + " ms");
|
||||
CommandCenterLog.info("[SimpleHttpCommandCenter] Deal a socket task: " + line
|
||||
+ ", address: " + socket.getInetAddress() + ", time cost: " + cost + " ms");
|
||||
} catch (Throwable e) {
|
||||
CommandCenterLog.info("CommandCenter error", e);
|
||||
CommandCenterLog.warn("[SimpleHttpCommandCenter] CommandCenter error", e);
|
||||
try {
|
||||
if (printWriter != null) {
|
||||
String errorMessage = SERVER_ERROR_MESSAGE;
|
||||
|
|
@ -110,7 +110,7 @@ public class HttpEventTask implements Runnable {
|
|||
printWriter.flush();
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
CommandCenterLog.info("CommandCenter close serverSocket failed", e);
|
||||
CommandCenterLog.warn("[SimpleHttpCommandCenter] Close server socket failed", e);
|
||||
}
|
||||
} finally {
|
||||
closeResource(in);
|
||||
|
|
@ -124,7 +124,7 @@ public class HttpEventTask implements Runnable {
|
|||
try {
|
||||
closeable.close();
|
||||
} catch (Exception e) {
|
||||
CommandCenterLog.info("CommandCenter close resource failed", e);
|
||||
CommandCenterLog.warn("[SimpleHttpCommandCenter] Close resource failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue