DUBBO-490 graceful shutdown :当注册中心尚未推送到客户端时,重连时不能报error级别日志。
重试连接报错时间距离上一次成功连接10秒内 则warn 否则error git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@73 1a56cb94-b969-4eaa-88fa-be21384802f2
This commit is contained in:
parent
718ec7cf68
commit
eb62512fae
|
|
@ -225,6 +225,8 @@ public class Constants {
|
|||
|
||||
public static final int DEFAULT_RECONNECT_PERIOD = 2000;
|
||||
|
||||
public static final String SHUTDOWN_TIMEOUT_KEY = "shutdown.timeout";
|
||||
|
||||
public static final int DEFAULT_SHUTDOWN_TIMEOUT = 10000;
|
||||
|
||||
public static final String CHECK_KEY = "check";
|
||||
|
|
|
|||
|
|
@ -57,13 +57,20 @@ public abstract class AbstractClient extends AbstractEndpoint implements Client
|
|||
|
||||
protected volatile ExecutorService executor;
|
||||
|
||||
private final boolean send_reconnect ;
|
||||
private final boolean send_reconnect ;
|
||||
|
||||
//the last successed connected time
|
||||
private long lastConnectedTime = System.currentTimeMillis();
|
||||
|
||||
private final int shutdown_timeout ;
|
||||
|
||||
|
||||
public AbstractClient(URL url, ChannelHandler handler) throws RemotingException {
|
||||
super(url, handler);
|
||||
|
||||
send_reconnect = url.getBooleanParameter(Constants.SEND_RECONNECT_KEY, false);
|
||||
send_reconnect = url.getBooleanParameter(Constants.SEND_RECONNECT_KEY, false);
|
||||
|
||||
shutdown_timeout = url.getIntParameter(Constants.SHUTDOWN_TIMEOUT_KEY, Constants.DEFAULT_SHUTDOWN_TIMEOUT);
|
||||
|
||||
try {
|
||||
doOpen();
|
||||
|
|
@ -103,17 +110,23 @@ public abstract class AbstractClient extends AbstractEndpoint implements Client
|
|||
* init reconnect thread
|
||||
*/
|
||||
private synchronized void initConnectStatusCheckCommand(){
|
||||
//如果配置了 reconnect = false 则不尝试重连。
|
||||
//reconnect=false to close reconnect
|
||||
int reconnect = getReconnectParam(getUrl());
|
||||
if(reconnect > 0 && reconnectExecutorFuture == null){
|
||||
Runnable connectStatusCheckCommand = new Runnable() {
|
||||
Runnable connectStatusCheckCommand = new Runnable() {
|
||||
String errorMsg = "Unexpected error occur at client reconnect";
|
||||
public void run() {
|
||||
try {
|
||||
if (! isConnected()) {
|
||||
connect();//定时检查与消息发送时检测都要做。
|
||||
connect();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// wait registry sync provider list
|
||||
if (System.currentTimeMillis() - lastConnectedTime > shutdown_timeout){
|
||||
logger.warn(errorMsg, t);
|
||||
} else {
|
||||
logger.error(errorMsg, t);
|
||||
}
|
||||
} catch (Throwable t) { // 防御性容错
|
||||
logger.error("Unexpected error occur at client reconnect", t);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -236,7 +249,8 @@ public abstract class AbstractClient extends AbstractEndpoint implements Client
|
|||
throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName()
|
||||
+ NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()
|
||||
+ ", cause: Connect wait timeout: " + getTimeout() + "ms.");
|
||||
}
|
||||
}
|
||||
lastConnectedTime = System.currentTimeMillis();
|
||||
} catch (RemotingException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue