Browse Source

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 5 years ago
parent
commit
1b68d0c9a0
3 changed files with 12 additions and 5 deletions
  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 View File

@@ -53,7 +53,7 @@ public class NettyTransportServer implements ClusterTokenServer {
private static final int DEFAULT_EVENT_LOOP_THREADS = Math.max(1,
SystemPropertyUtil.getInt("io.netty.eventLoopThreads", Runtime.getRuntime().availableProcessors() * 2));
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;

@@ -103,7 +103,7 @@ public class NettyTransportServer implements ClusterTokenServer {
@Override
public void operationComplete(ChannelFuture future) {
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());
currentState.compareAndSet(SERVER_STATUS_STARTING, SERVER_STATUS_OFF);
int failCount = failedTimes.incrementAndGet();


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

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

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

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

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

private int port;
private int idleSeconds;

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

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 View File

@@ -15,6 +15,8 @@
*/
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.request.ClusterRequest;
import com.alibaba.csp.sentinel.cluster.response.ClusterResponse;
@@ -105,6 +107,10 @@ public class TokenServerHandler extends ChannelInboundHandlerAdapter {
}

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();
}
}

Loading…
Cancel
Save