mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
SmackReactor/NIO, Java8/Android19, Pretty print XML, FSM connections
This commit adds - SmackReactor / NIO - a framework for finite state machine connections - support for Java 8 - pretty printed XML debug output It also - reworks the integration test framework - raises the minimum Android API level to 19 - introduces XmppNioTcpConnection Furthermore fixes SMACK-801 (at least partly). Java 8 language features are available, but not all runtime library methods. For that we would need to raise the Android API level to 24 or higher.
This commit is contained in:
parent
dba12919d0
commit
e98d42790a
144 changed files with 8692 additions and 1455 deletions
|
@ -20,15 +20,13 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.AbstractConnectionClosedListener;
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.ScheduledAction;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.SmackFuture;
|
||||
|
@ -115,7 +113,7 @@ public final class PingManager extends Manager {
|
|||
*/
|
||||
private int pingInterval = defaultPingInterval;
|
||||
|
||||
private ScheduledFuture<?> nextAutomaticPing;
|
||||
private ScheduledAction nextAutomaticPing;
|
||||
|
||||
private PingManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
|
@ -396,9 +394,10 @@ public final class PingManager extends Manager {
|
|||
}
|
||||
|
||||
private void maybeStopPingServerTask() {
|
||||
final ScheduledAction nextAutomaticPing = this.nextAutomaticPing;
|
||||
if (nextAutomaticPing != null) {
|
||||
nextAutomaticPing.cancel(true);
|
||||
nextAutomaticPing = null;
|
||||
nextAutomaticPing.cancel();
|
||||
this.nextAutomaticPing = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -406,9 +405,7 @@ public final class PingManager extends Manager {
|
|||
* Ping the server if deemed necessary because automatic server pings are
|
||||
* enabled ({@link #setPingInterval(int)}) and the ping interval has expired.
|
||||
*/
|
||||
public synchronized void pingServerIfNecessary() {
|
||||
final int DELTA = 1000; // 1 seconds
|
||||
final int TRIES = 3; // 3 tries
|
||||
public void pingServerIfNecessary() {
|
||||
final XMPPConnection connection = connection();
|
||||
if (connection == null) {
|
||||
// connection has been collected by GC
|
||||
|
@ -430,45 +427,31 @@ public final class PingManager extends Manager {
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (connection.isAuthenticated()) {
|
||||
boolean res = false;
|
||||
if (!connection.isAuthenticated()) {
|
||||
LOGGER.warning(connection + " was not authenticated");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < TRIES; i++) {
|
||||
if (i != 0) {
|
||||
try {
|
||||
Thread.sleep(DELTA);
|
||||
} catch (InterruptedException e) {
|
||||
// We received an interrupt
|
||||
// This only happens if we should stop pinging
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
res = pingMyServer(false);
|
||||
}
|
||||
catch (InterruptedException | SmackException e) {
|
||||
// Note that we log the connection here, so that it is not GC'ed between the call to isAuthenticated
|
||||
// a few lines above and the usage of the connection within pingMyServer(). In order to prevent:
|
||||
// https://community.igniterealtime.org/thread/59369
|
||||
LOGGER.log(Level.WARNING, "Exception while pinging server of " + connection, e);
|
||||
res = false;
|
||||
}
|
||||
// stop when we receive a pong back
|
||||
if (res) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!res) {
|
||||
for (PingFailedListener l : pingFailedListeners) {
|
||||
l.pingFailed();
|
||||
}
|
||||
} else {
|
||||
final long minimumTimeout = TimeUnit.MINUTES.toMillis(2);
|
||||
final long connectionReplyTimeout = connection.getReplyTimeout();
|
||||
final long timeout = connectionReplyTimeout > minimumTimeout ? connectionReplyTimeout : minimumTimeout;
|
||||
|
||||
SmackFuture<Boolean, Exception> pingFuture = pingAsync(connection.getXMPPServiceDomain(), timeout);
|
||||
pingFuture.onSuccess(new SuccessCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(Boolean result) {
|
||||
// Ping was successful, wind-up the periodic task again
|
||||
maybeSchedulePingServerTask();
|
||||
}
|
||||
} else {
|
||||
LOGGER.warning("XMPPConnection was not authenticated");
|
||||
}
|
||||
});
|
||||
pingFuture.onError(new ExceptionCallback<Exception>() {
|
||||
@Override
|
||||
public void processException(Exception exception) {
|
||||
for (PingFailedListener l : pingFailedListeners) {
|
||||
l.pingFailed();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final Runnable pingServerRunnable = new Runnable() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue