Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to reconnect based on number of failed ping requests #18

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
27 changes: 27 additions & 0 deletions doc/configuration-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Configuration Options

Configuration file: sip-communicator.properties<br>
Location of file depends on your installation type, possible locations are /HOME/.sip-communicator and /etc/jitsi

Connection Options
------------------
Pings are sent to determine whether or not a valid connection still exists. There are several configuration
properties you can set to fine tune this behavior.

The name of the property which configures ping interval in ms. -1 to disable pings.<br>
property: **org.jitsi.*componentName*.PING_INTERVAL**<br>
default: 10000 ms

The name of the property used to configure ping timeout in ms.<br>
property: **org.jitsi.*componentName*.PING_TIMEOUT**<br>
default: 5000 ms

The name of the property which configures {@link #pingThreshold}.<br>
property: **org.jitsi.*componentName*.PING_THRESHOLD**<br>
default: 3

The name of the property used to determine if we should reconnect on ping failures. Setting this value to true will
force the connection to be reset when the ping threshold is reached<br>
property: **org.jitsi.*componentName*.RECONNECT_ON_PING_FAILURES**<br>
default: false

15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jitsi-protocol-jabber</artifactId>
<version>2.9-20151214.211356-5</version>
<version>2.9-20160505.143533-15</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -98,6 +98,19 @@
</plugins>
</build>

<distributionManagement>
<repository>
<id>inin-release</id>
<name>ININ Release Repository</name>
<url>http://purecloud.artifactoryonline.com/purecloud/inin-release</url>
</repository>
<snapshotRepository>
<id>inin-snapshot</id>
<name>ININ Snapshot Repository</name>
<url>http://purecloud.artifactoryonline.com/purecloud/inin-snapshot</url>
</snapshotRepository>
</distributionManagement>

<repositories>
<repository>
<id>jitsi-maven-repository-releases</id>
Expand Down
41 changes: 40 additions & 1 deletion src/main/java/org/jitsi/xmpp/component/ComponentBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public abstract class ComponentBase
public final static String PROCESSING_TIME_LIMIT_PNAME
= "PROCESSING_TIME_LIMIT";

/**
* The name of the property used to determine if we should
* reconnect on ping failures
*/
private final static String RECONNECT_ON_PING_FAILURES
= "RECONNECT_ON_PING_FAILURES";

/**
* The hostname or IP address to which this component will be connected.
*/
Expand Down Expand Up @@ -123,6 +130,12 @@ public abstract class ComponentBase
*/
private int pingFailures = 0;

/**
* If we exceed the maximum number of ping failures should we trigger a
* reconnect to the xmpp server
*/
private boolean reconnectOnPingFailure = false;

/**
* Time used to schedule ping and timeout tasks.
*/
Expand Down Expand Up @@ -197,10 +210,14 @@ protected void loadConfig(ConfigurationService config,
configPropertiesBase + PROCESSING_TIME_LIMIT_PNAME,
DEFAULT_PROCESSING_TIME_LIMIT);

reconnectOnPingFailure = config.getBoolean(
configPropertiesBase + RECONNECT_ON_PING_FAILURES, false);

logger.info("Component " + configPropertiesBase + " config: ");
logger.info(" ping interval: " + pingInterval + " ms");
logger.info(" ping timeout: " + pingTimeout + " ms");
logger.info(" ping threshold: " + pingThreshold);
logger.info(" reconnect on ping failures: " + reconnectOnPingFailure);
}

/**
Expand Down Expand Up @@ -277,6 +294,7 @@ public void preComponentShutdown()
}

timeouts.clear();
pingFailures = 0;
}
}

Expand All @@ -295,6 +313,24 @@ public boolean isConnectionAlive()
}
}

/**
* Restart the component connection if we have exceeded the
* threshold for ping failures
*/
public void reconnectComponent() {
// need to make externalComponent here
logger.info("Restarting xmpp component connection that failed");
shutdown();
timeouts.clear();
try {
compMan.removeComponent(this.getSubdomain());
dispose();
compMan.addComponent(getSubdomain(), this);
} catch (Exception ex) {
logger.error("Failed to restart xmpp component");
}
}

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -627,8 +663,11 @@ public void run()
pingFailures++;

logger.error("Ping timeout for ID: " + packetId);

timeouts.remove(packetId);

if(!isConnectionAlive() && reconnectOnPingFailure) {
reconnectComponent();
}
}
}
}
Expand Down