Procházet zdrojové kódy

Polish cluster token server handler related logic

- Enlarge retry timeout to 2s by default
- Improve remote address representation

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao před 5 roky
rodič
revize
1b68d0c9a0
3 změnil soubory, kde provedl 12 přidání a 5 odebrání
  1. +2
    -2
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/NettyTransportServer.java
  2. +3
    -2
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/config/ServerTransportConfig.java
  3. +7
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/handler/TokenServerHandler.java

+ 2
- 2
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/NettyTransportServer.java Zobrazit soubor

@@ -53,7 +53,7 @@ public class NettyTransportServer implements ClusterTokenServer {
private static final int DEFAULT_EVENT_LOOP_THREADS = Math.max(1, private static final int DEFAULT_EVENT_LOOP_THREADS = Math.max(1,
SystemPropertyUtil.getInt("io.netty.eventLoopThreads", Runtime.getRuntime().availableProcessors() * 2)); SystemPropertyUtil.getInt("io.netty.eventLoopThreads", Runtime.getRuntime().availableProcessors() * 2));
private static final int MAX_RETRY_TIMES = 3; private static final int MAX_RETRY_TIMES = 3;
private static final int RETRY_SLEEP_MS = 1000;
private static final int RETRY_SLEEP_MS = 2000;


private final int port; private final int port;


@@ -103,7 +103,7 @@ public class NettyTransportServer implements ClusterTokenServer {
@Override @Override
public void operationComplete(ChannelFuture future) { public void operationComplete(ChannelFuture future) {
if (future.cause() != null) { if (future.cause() != null) {
RecordLog.info("[NettyTransportServer] Token server start failed (port=" + port + ")",
RecordLog.info("[NettyTransportServer] Token server start failed (port=" + port + "), failedTimes: " + failedTimes.get(),
future.cause()); future.cause());
currentState.compareAndSet(SERVER_STATUS_STARTING, SERVER_STATUS_OFF); currentState.compareAndSet(SERVER_STATUS_STARTING, SERVER_STATUS_OFF);
int failCount = failedTimes.incrementAndGet(); int failCount = failedTimes.incrementAndGet();


+ 3
- 2
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/config/ServerTransportConfig.java Zobrazit soubor

@@ -15,20 +15,21 @@
*/ */
package com.alibaba.csp.sentinel.cluster.server.config; package com.alibaba.csp.sentinel.cluster.server.config;


import com.alibaba.csp.sentinel.cluster.ClusterConstants;

/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.0 * @since 1.4.0
*/ */
public class ServerTransportConfig { public class ServerTransportConfig {


public static final int DEFAULT_PORT = 8730;
public static final int DEFAULT_IDLE_SECONDS = 600; public static final int DEFAULT_IDLE_SECONDS = 600;


private int port; private int port;
private int idleSeconds; private int idleSeconds;


public ServerTransportConfig() { public ServerTransportConfig() {
this(DEFAULT_PORT, DEFAULT_IDLE_SECONDS);
this(ClusterConstants.DEFAULT_CLUSTER_SERVER_PORT, DEFAULT_IDLE_SECONDS);
} }


public ServerTransportConfig(int port, int idleSeconds) { public ServerTransportConfig(int port, int idleSeconds) {


+ 7
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/handler/TokenServerHandler.java Zobrazit soubor

@@ -15,6 +15,8 @@
*/ */
package com.alibaba.csp.sentinel.cluster.server.handler; package com.alibaba.csp.sentinel.cluster.server.handler;


import java.net.InetSocketAddress;

import com.alibaba.csp.sentinel.cluster.ClusterConstants; import com.alibaba.csp.sentinel.cluster.ClusterConstants;
import com.alibaba.csp.sentinel.cluster.request.ClusterRequest; import com.alibaba.csp.sentinel.cluster.request.ClusterRequest;
import com.alibaba.csp.sentinel.cluster.response.ClusterResponse; import com.alibaba.csp.sentinel.cluster.response.ClusterResponse;
@@ -105,6 +107,10 @@ public class TokenServerHandler extends ChannelInboundHandlerAdapter {
} }


private String getRemoteAddress(ChannelHandlerContext ctx) { private String getRemoteAddress(ChannelHandlerContext ctx) {
return ctx.channel().remoteAddress().toString();
if (ctx.channel().remoteAddress() == null) {
return null;
}
InetSocketAddress inetAddress = (InetSocketAddress) ctx.channel().remoteAddress();
return inetAddress.getAddress().getHostAddress() + ":" + inetAddress.getPort();
} }
} }

Načítá se…
Zrušit
Uložit