Skip to content

Commit

Permalink
fix reconnection defect (#152)
Browse files Browse the repository at this point in the history
* print log to bolt

* upgrade to 1.4.7-snapshot and cancel reconnect when close connection

* remove ci jdk1.6

* upgrade version
  • Loading branch information
dbl-x authored and yuemingliang committed Apr 22, 2019
1 parent de44e2a commit 8495d99
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#.travis.yml
language: java

addons:
apt:
packages:
- openjdk-6-jdk

jdk:
- oraclejdk8
- openjdk7
- openjdk6

before_install:
- echo "Downloading Maven 3.2.5"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.sofa</groupId>
<artifactId>bolt</artifactId>
<version>1.4.6</version>
<version>1.4.7</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/alipay/remoting/rpc/RpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ public boolean checkConnection(String addr) {
*/
public void closeConnection(String addr) {
Url url = this.addressParser.parse(addr);
if (globalSwitch.isOn(GlobalSwitch.CONN_RECONNECT_SWITCH) && reconnectManager != null) {
reconnectManager.addCancelUrl(url);
}
this.connectionManager.remove(url.getUniqueKey());
}

Expand All @@ -812,6 +815,9 @@ public void closeConnection(String addr) {
* @param url
*/
public void closeConnection(Url url) {
if (globalSwitch.isOn(GlobalSwitch.CONN_RECONNECT_SWITCH) && reconnectManager != null) {
reconnectManager.addCancelUrl(url);
}
this.connectionManager.remove(url.getUniqueKey());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.net.InetSocketAddress;
import java.util.List;

import com.alipay.remoting.log.BoltLoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alipay.remoting.CommandCode;
import com.alipay.remoting.CommandDecoder;
Expand All @@ -44,7 +44,7 @@
*/
public class RpcCommandDecoderV2 implements CommandDecoder {

private static final Logger logger = LoggerFactory.getLogger("RpcRemoting");
private static final Logger logger = BoltLoggerFactory.getLogger("RpcRemoting");

private int lessLen;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.io.Serializable;

import com.alipay.remoting.log.BoltLoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alipay.remoting.CommandEncoder;
import com.alipay.remoting.Connection;
Expand All @@ -41,7 +41,7 @@
*/
public class RpcCommandEncoderV2 implements CommandEncoder {
/** logger */
private static final Logger logger = LoggerFactory.getLogger("RpcRemoting");
private static final Logger logger = BoltLoggerFactory.getLogger("RpcRemoting");

/**
* @see CommandEncoder#encode(ChannelHandlerContext, Serializable, ByteBuf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,30 @@ public void testReconnectionByUserSetting() throws InterruptedException, Remotin
Assert.assertEquals(0, clientDisConnectProcessor.getDisConnectTimes());
Assert.assertEquals(1, clientConnectProcessor.getConnectTimes());
connection.close();
Thread.sleep(1000);
Thread.sleep(2000);
Assert.assertEquals(1, clientDisConnectProcessor.getDisConnectTimes());
Assert.assertEquals(2, clientConnectProcessor.getConnectTimes());
}

@Test
public void testCancelReconnection() throws RemotingException, InterruptedException {
doInit(false, true);
client.enableReconnectSwitch();

String addr = "127.0.0.1:2014?zone=RZONE&_CONNECTIONNUM=1";
Url url = addressParser.parse(addr);

client.getConnection(url, 1000);
Assert.assertEquals(0, clientDisConnectProcessor.getDisConnectTimes());
Assert.assertEquals(1, clientConnectProcessor.getConnectTimes());

client.closeConnection(url);

Thread.sleep(1000);
Assert.assertEquals(1, clientDisConnectProcessor.getDisConnectTimes());
Assert.assertEquals(1, clientConnectProcessor.getConnectTimes());
}

private void doInit(boolean enableSystem, boolean enableUser) {
if (enableSystem) {
System.setProperty(Configs.CONN_RECONNECT_SWITCH, "true");
Expand Down

0 comments on commit 8495d99

Please sign in to comment.