2013-01-04 12:43:35 +01:00
|
|
|
/**
|
2014-02-17 18:57:38 +01:00
|
|
|
*
|
2014-02-23 21:36:57 +01:00
|
|
|
* Copyright 2012-2014 Florian Schmaus
|
2013-01-04 12:43:35 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-01-04 12:43:35 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.ping;
|
|
|
|
|
2013-04-16 03:39:17 +02:00
|
|
|
import java.util.Collections;
|
2014-02-23 21:36:57 +01:00
|
|
|
import java.util.HashSet;
|
2013-04-16 03:39:17 +02:00
|
|
|
import java.util.Map;
|
2014-02-23 21:36:57 +01:00
|
|
|
import java.util.Set;
|
2013-04-16 03:39:17 +02:00
|
|
|
import java.util.WeakHashMap;
|
2014-05-26 17:36:00 +02:00
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
2014-02-23 21:36:57 +01:00
|
|
|
import java.util.concurrent.ScheduledFuture;
|
2014-05-26 17:36:00 +02:00
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
|
import java.util.concurrent.ThreadFactory;
|
2014-02-23 21:36:57 +01:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2014-03-12 11:50:05 +01:00
|
|
|
import java.util.logging.Level;
|
2014-02-23 21:36:57 +01:00
|
|
|
import java.util.logging.Logger;
|
2013-04-16 03:39:17 +02:00
|
|
|
|
2014-03-14 01:48:33 +01:00
|
|
|
import org.jivesoftware.smack.AbstractConnectionListener;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException;
|
|
|
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
2014-03-19 14:22:20 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2014-03-10 09:45:50 +01:00
|
|
|
import org.jivesoftware.smack.XMPPConnection;
|
2013-04-16 03:39:17 +02:00
|
|
|
import org.jivesoftware.smack.ConnectionCreationListener;
|
2014-03-09 11:19:44 +01:00
|
|
|
import org.jivesoftware.smack.Manager;
|
2013-04-16 03:39:17 +02:00
|
|
|
import org.jivesoftware.smack.PacketListener;
|
2014-05-25 12:28:08 +02:00
|
|
|
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
2013-01-04 12:43:35 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
2013-04-16 03:39:17 +02:00
|
|
|
import org.jivesoftware.smack.filter.AndFilter;
|
|
|
|
import org.jivesoftware.smack.filter.IQTypeFilter;
|
|
|
|
import org.jivesoftware.smack.filter.PacketFilter;
|
|
|
|
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
|
|
|
import org.jivesoftware.smack.packet.Packet;
|
2014-02-15 11:35:08 +01:00
|
|
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
2014-02-14 18:13:51 +01:00
|
|
|
import org.jivesoftware.smackx.ping.packet.Ping;
|
2013-01-04 12:43:35 +01:00
|
|
|
|
|
|
|
/**
|
2014-02-23 21:36:57 +01:00
|
|
|
* Implements the XMPP Ping as defined by XEP-0199. The XMPP Ping protocol allows one entity to
|
|
|
|
* ping any other entity by simply sending a ping to the appropriate JID. PingManger also
|
|
|
|
* periodically sends XMPP pings to the server every 30 minutes to avoid NAT timeouts and to test
|
|
|
|
* the connection status.
|
2013-01-04 12:43:35 +01:00
|
|
|
*
|
|
|
|
* @author Florian Schmaus
|
2014-02-23 21:36:57 +01:00
|
|
|
* @see <a href="http://www.xmpp.org/extensions/xep-0199.html">XEP-0199:XMPP Ping</a>
|
2013-01-04 12:43:35 +01:00
|
|
|
*/
|
2014-03-09 11:19:44 +01:00
|
|
|
public class PingManager extends Manager {
|
2014-02-23 21:36:57 +01:00
|
|
|
private static final Logger LOGGER = Logger.getLogger(PingManager.class.getName());
|
|
|
|
|
2014-03-10 09:45:50 +01:00
|
|
|
private static final Map<XMPPConnection, PingManager> INSTANCES = Collections
|
|
|
|
.synchronizedMap(new WeakHashMap<XMPPConnection, PingManager>());
|
2014-02-23 21:36:57 +01:00
|
|
|
|
|
|
|
private static final PacketFilter PING_PACKET_FILTER = new AndFilter(
|
2014-05-29 16:05:20 +02:00
|
|
|
new PacketTypeFilter(Ping.class), IQTypeFilter.GET);
|
2014-02-23 21:36:57 +01:00
|
|
|
|
2013-04-16 03:39:17 +02:00
|
|
|
static {
|
2014-05-25 12:28:08 +02:00
|
|
|
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
2014-03-10 09:45:50 +01:00
|
|
|
public void connectionCreated(XMPPConnection connection) {
|
2013-11-03 22:49:58 +01:00
|
|
|
getInstanceFor(connection);
|
2013-04-16 03:39:17 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-10 09:45:50 +01:00
|
|
|
* Retrieves a {@link PingManager} for the specified {@link XMPPConnection}, creating one if it doesn't already
|
2013-04-16 03:39:17 +02:00
|
|
|
* exist.
|
|
|
|
*
|
|
|
|
* @param connection
|
|
|
|
* The connection the manager is attached to.
|
|
|
|
* @return The new or existing manager.
|
|
|
|
*/
|
2014-03-10 09:45:50 +01:00
|
|
|
public synchronized static PingManager getInstanceFor(XMPPConnection connection) {
|
2014-02-23 21:36:57 +01:00
|
|
|
PingManager pingManager = INSTANCES.get(connection);
|
2013-04-16 03:39:17 +02:00
|
|
|
if (pingManager == null) {
|
|
|
|
pingManager = new PingManager(connection);
|
|
|
|
}
|
|
|
|
return pingManager;
|
|
|
|
}
|
|
|
|
|
2014-02-23 21:36:57 +01:00
|
|
|
private static int defaultPingInterval = 60 * 30;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the default ping interval which will be used for new connections.
|
|
|
|
*
|
|
|
|
* @param interval the interval in seconds
|
|
|
|
*/
|
|
|
|
public static void setDefaultPingInterval(int interval) {
|
|
|
|
defaultPingInterval = interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Set<PingFailedListener> pingFailedListeners = Collections
|
|
|
|
.synchronizedSet(new HashSet<PingFailedListener>());
|
|
|
|
|
2014-05-26 17:36:00 +02:00
|
|
|
private final ScheduledExecutorService executorService;
|
|
|
|
|
|
|
|
private static class PingExecutorThreadFactory implements ThreadFactory {
|
|
|
|
private final int connectionCounterValue;
|
|
|
|
|
|
|
|
public PingExecutorThreadFactory(int connectionCounterValue) {
|
|
|
|
this.connectionCounterValue = connectionCounterValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Thread newThread(Runnable runnable) {
|
|
|
|
Thread thread = new Thread(runnable, "Smack Scheduled Ping Executor Service ("
|
|
|
|
+ connectionCounterValue + ")");
|
|
|
|
thread.setDaemon(true);
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-02-23 21:36:57 +01:00
|
|
|
/**
|
|
|
|
* The interval in seconds between pings are send to the users server.
|
|
|
|
*/
|
|
|
|
private int pingInterval = defaultPingInterval;
|
|
|
|
|
|
|
|
private ScheduledFuture<?> nextAutomaticPing;
|
|
|
|
|
2014-03-10 09:45:50 +01:00
|
|
|
private PingManager(XMPPConnection connection) {
|
2014-03-09 11:19:44 +01:00
|
|
|
super(connection);
|
2014-05-26 17:36:00 +02:00
|
|
|
executorService = new ScheduledThreadPoolExecutor(1,
|
|
|
|
new PingExecutorThreadFactory(connection.getConnectionCounter()));
|
2013-01-04 12:43:35 +01:00
|
|
|
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
2014-08-21 10:55:33 +02:00
|
|
|
sdm.addFeature(Ping.NAMESPACE);
|
2014-02-23 21:36:57 +01:00
|
|
|
INSTANCES.put(connection, this);
|
|
|
|
|
2013-04-16 03:39:17 +02:00
|
|
|
connection.addPacketListener(new PacketListener() {
|
2014-02-23 21:36:57 +01:00
|
|
|
// Send a Pong for every Ping
|
|
|
|
@Override
|
2014-03-19 14:22:20 +01:00
|
|
|
public void processPacket(Packet packet) throws NotConnectedException {
|
2014-08-21 10:55:33 +02:00
|
|
|
Ping ping = (Ping) packet;
|
|
|
|
connection().sendPacket(ping.getPong());
|
2013-04-16 03:39:17 +02:00
|
|
|
}
|
2014-02-23 21:36:57 +01:00
|
|
|
}, PING_PACKET_FILTER);
|
2014-03-14 01:48:33 +01:00
|
|
|
connection.addConnectionListener(new AbstractConnectionListener() {
|
|
|
|
@Override
|
|
|
|
public void authenticated(XMPPConnection connection) {
|
|
|
|
maybeSchedulePingServerTask();
|
|
|
|
}
|
2014-02-23 21:36:57 +01:00
|
|
|
@Override
|
|
|
|
public void connectionClosed() {
|
|
|
|
maybeStopPingServerTask();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void connectionClosedOnError(Exception arg0) {
|
|
|
|
maybeStopPingServerTask();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
maybeSchedulePingServerTask();
|
2013-01-04 12:43:35 +01:00
|
|
|
}
|
2013-02-27 23:49:04 +01:00
|
|
|
|
2013-01-04 12:43:35 +01:00
|
|
|
/**
|
2013-03-23 12:59:08 +01:00
|
|
|
* Pings the given jid. This method will return false if an error occurs. The exception
|
|
|
|
* to this, is a server ping, which will always return true if the server is reachable,
|
|
|
|
* event if there is an error on the ping itself (i.e. ping not supported).
|
2013-03-19 03:37:36 +01:00
|
|
|
* <p>
|
|
|
|
* Use {@link #isPingSupported(String)} to determine if XMPP Ping is supported
|
2013-01-04 12:43:35 +01:00
|
|
|
* by the entity.
|
|
|
|
*
|
2013-03-19 03:37:36 +01:00
|
|
|
* @param jid The id of the entity the ping is being sent to
|
2014-09-29 13:52:13 +02:00
|
|
|
* @param pingTimeout The time to wait for a reply in milliseconds
|
2013-03-19 03:37:36 +01:00
|
|
|
* @return true if a reply was received from the entity, false otherwise.
|
2014-04-28 11:07:14 +02:00
|
|
|
* @throws NoResponseException if there was no response from the jid.
|
2014-03-19 14:22:20 +01:00
|
|
|
* @throws NotConnectedException
|
2013-01-04 12:43:35 +01:00
|
|
|
*/
|
2014-04-28 11:07:14 +02:00
|
|
|
public boolean ping(String jid, long pingTimeout) throws NotConnectedException, NoResponseException {
|
2013-03-19 03:37:36 +01:00
|
|
|
Ping ping = new Ping(jid);
|
|
|
|
try {
|
2014-09-29 13:52:13 +02:00
|
|
|
connection().createPacketCollectorAndSend(ping).nextResultOrThrow(pingTimeout);
|
2013-02-27 23:49:04 +01:00
|
|
|
}
|
2013-03-19 03:37:36 +01:00
|
|
|
catch (XMPPException exc) {
|
2014-03-12 11:50:05 +01:00
|
|
|
return jid.equals(connection().getServiceName());
|
2013-01-04 12:43:35 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-23 21:36:57 +01:00
|
|
|
|
2013-01-04 12:43:35 +01:00
|
|
|
/**
|
2013-03-19 03:37:36 +01:00
|
|
|
* Same as calling {@link #ping(String, long)} with the defaultpacket reply
|
|
|
|
* timeout.
|
2013-01-04 12:43:35 +01:00
|
|
|
*
|
2013-03-19 03:37:36 +01:00
|
|
|
* @param jid The id of the entity the ping is being sent to
|
|
|
|
* @return true if a reply was received from the entity, false otherwise.
|
2014-03-28 14:27:14 +01:00
|
|
|
* @throws NotConnectedException
|
2014-04-28 11:07:14 +02:00
|
|
|
* @throws NoResponseException if there was no response from the jid.
|
2013-01-04 12:43:35 +01:00
|
|
|
*/
|
2014-04-28 11:07:14 +02:00
|
|
|
public boolean ping(String jid) throws NotConnectedException, NoResponseException {
|
2014-03-09 11:19:44 +01:00
|
|
|
return ping(jid, connection().getPacketReplyTimeout());
|
2013-01-04 12:43:35 +01:00
|
|
|
}
|
2014-02-23 21:36:57 +01:00
|
|
|
|
2013-02-27 23:49:04 +01:00
|
|
|
/**
|
2013-03-19 03:37:36 +01:00
|
|
|
* Query the specified entity to see if it supports the Ping protocol (XEP-0199)
|
2013-02-27 23:49:04 +01:00
|
|
|
*
|
2013-03-19 03:37:36 +01:00
|
|
|
* @param jid The id of the entity the query is being sent to
|
|
|
|
* @return true if it supports ping, false otherwise.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws XMPPErrorException An XMPP related error occurred during the request
|
2014-04-28 11:07:14 +02:00
|
|
|
* @throws NoResponseException if there was no response from the jid.
|
2014-03-19 14:22:20 +01:00
|
|
|
* @throws NotConnectedException
|
2013-02-27 23:49:04 +01:00
|
|
|
*/
|
2014-03-19 14:22:20 +01:00
|
|
|
public boolean isPingSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
2014-08-21 10:55:33 +02:00
|
|
|
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Ping.NAMESPACE);
|
2013-01-04 12:43:35 +01:00
|
|
|
}
|
2013-03-23 12:59:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pings the server. This method will return true if the server is reachable. It
|
|
|
|
* is the equivalent of calling <code>ping</code> with the XMPP domain.
|
|
|
|
* <p>
|
|
|
|
* Unlike the {@link #ping(String)} case, this method will return true even if
|
|
|
|
* {@link #isPingSupported(String)} is false.
|
|
|
|
*
|
|
|
|
* @return true if a reply was received from the server, false otherwise.
|
2014-03-28 14:27:14 +01:00
|
|
|
* @throws NotConnectedException
|
2013-03-23 12:59:08 +01:00
|
|
|
*/
|
2014-03-28 14:27:14 +01:00
|
|
|
public boolean pingMyServer() throws NotConnectedException {
|
2014-03-01 15:29:35 +01:00
|
|
|
return pingMyServer(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pings the server. This method will return true if the server is reachable. It
|
|
|
|
* is the equivalent of calling <code>ping</code> with the XMPP domain.
|
|
|
|
* <p>
|
|
|
|
* Unlike the {@link #ping(String)} case, this method will return true even if
|
|
|
|
* {@link #isPingSupported(String)} is false.
|
|
|
|
*
|
|
|
|
* @param notifyListeners Notify the PingFailedListener in case of error if true
|
2014-03-10 18:31:45 +01:00
|
|
|
* @return true if the user's server could be pinged.
|
2014-03-28 14:27:14 +01:00
|
|
|
* @throws NotConnectedException
|
2014-03-01 15:29:35 +01:00
|
|
|
*/
|
2014-03-28 14:27:14 +01:00
|
|
|
public boolean pingMyServer(boolean notifyListeners) throws NotConnectedException {
|
|
|
|
boolean res;
|
|
|
|
try {
|
|
|
|
res = ping(connection().getServiceName());
|
|
|
|
}
|
|
|
|
catch (NoResponseException e) {
|
|
|
|
res = false;
|
|
|
|
}
|
2014-04-28 11:07:14 +02:00
|
|
|
if (!res && notifyListeners) {
|
2014-02-23 21:36:57 +01:00
|
|
|
for (PingFailedListener l : pingFailedListeners)
|
|
|
|
l.pingFailed();
|
|
|
|
}
|
|
|
|
return res;
|
2013-03-23 12:59:08 +01:00
|
|
|
}
|
2014-02-23 21:36:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the interval between the server is automatic pinged. A negative value disables automatic server pings.
|
|
|
|
*
|
|
|
|
* @param pingInterval the interval between the ping
|
|
|
|
*/
|
|
|
|
public void setPingInterval(int pingInterval) {
|
|
|
|
this.pingInterval = pingInterval;
|
|
|
|
maybeSchedulePingServerTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current ping interval.
|
|
|
|
*
|
|
|
|
* @return the interval between pings in seconds
|
|
|
|
*/
|
|
|
|
public int getPingInterval() {
|
|
|
|
return pingInterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a new PingFailedListener
|
|
|
|
*
|
|
|
|
* @param listener the listener to invoke
|
|
|
|
*/
|
|
|
|
public void registerPingFailedListener(PingFailedListener listener) {
|
|
|
|
pingFailedListeners.add(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister a PingFailedListener
|
|
|
|
*
|
|
|
|
* @param listener the listener to remove
|
|
|
|
*/
|
|
|
|
public void unregisterPingFailedListener(PingFailedListener listener) {
|
|
|
|
pingFailedListeners.remove(listener);
|
|
|
|
}
|
|
|
|
|
2014-04-28 11:07:14 +02:00
|
|
|
private void maybeSchedulePingServerTask() {
|
|
|
|
maybeSchedulePingServerTask(0);
|
2014-02-23 21:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels any existing periodic ping task if there is one and schedules a new ping task if
|
|
|
|
* pingInterval is greater then zero.
|
2014-04-28 11:07:14 +02:00
|
|
|
*
|
2014-08-20 10:44:02 +02:00
|
|
|
* @param delta the delta to the last received stanza in seconds
|
2014-02-23 21:36:57 +01:00
|
|
|
*/
|
2014-04-28 11:07:14 +02:00
|
|
|
private synchronized void maybeSchedulePingServerTask(int delta) {
|
2014-02-23 21:36:57 +01:00
|
|
|
maybeStopPingServerTask();
|
|
|
|
if (pingInterval > 0) {
|
2014-04-28 11:07:14 +02:00
|
|
|
int nextPingIn = pingInterval - delta;
|
|
|
|
LOGGER.fine("Scheduling ServerPingTask in " + nextPingIn + " seconds (pingInterval="
|
|
|
|
+ pingInterval + ", delta=" + delta + ")");
|
2014-08-20 10:35:45 +02:00
|
|
|
nextAutomaticPing = executorService.schedule(pingServerRunnable, nextPingIn, TimeUnit.SECONDS);
|
2014-02-23 21:36:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void maybeStopPingServerTask() {
|
|
|
|
if (nextAutomaticPing != null) {
|
|
|
|
nextAutomaticPing.cancel(true);
|
|
|
|
nextAutomaticPing = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-08 10:07:01 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
final XMPPConnection connection = connection();
|
|
|
|
if (connection == null) {
|
|
|
|
// connection has been collected by GC
|
|
|
|
// which means we can stop the thread by breaking the loop
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pingInterval <= 0) {
|
|
|
|
// Ping has been disabled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
long lastStanzaReceived = connection.getLastStanzaReceived();
|
|
|
|
if (lastStanzaReceived > 0) {
|
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
// Delta since the last stanza was received
|
|
|
|
int deltaInSeconds = (int) ((now - lastStanzaReceived) / 1000);
|
|
|
|
// If the delta is small then the ping interval, then we can defer the ping
|
|
|
|
if (deltaInSeconds < pingInterval) {
|
|
|
|
maybeSchedulePingServerTask(deltaInSeconds);
|
2014-04-28 11:07:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-09-08 10:07:01 +02:00
|
|
|
}
|
|
|
|
if (connection.isAuthenticated()) {
|
|
|
|
boolean res = false;
|
|
|
|
|
|
|
|
for (int i = 0; i < TRIES; i++) {
|
|
|
|
if (i != 0) {
|
2014-03-12 11:50:05 +01:00
|
|
|
try {
|
2014-09-08 10:07:01 +02:00
|
|
|
Thread.sleep(DELTA);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
// We received an interrupt
|
|
|
|
// This only happens if we should stop pinging
|
|
|
|
return;
|
2014-02-23 21:36:57 +01:00
|
|
|
}
|
|
|
|
}
|
2014-09-08 10:07:01 +02:00
|
|
|
try {
|
|
|
|
res = pingMyServer(false);
|
|
|
|
}
|
|
|
|
catch (SmackException e) {
|
|
|
|
LOGGER.log(Level.WARNING, "SmackError while pinging server", e);
|
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
// stop when we receive a pong back
|
|
|
|
if (res) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!res) {
|
|
|
|
for (PingFailedListener l : pingFailedListeners) {
|
|
|
|
l.pingFailed();
|
2014-02-23 21:36:57 +01:00
|
|
|
}
|
|
|
|
} else {
|
2014-09-08 10:07:01 +02:00
|
|
|
// Ping was successful, wind-up the periodic task again
|
|
|
|
maybeSchedulePingServerTask();
|
2014-02-23 21:36:57 +01:00
|
|
|
}
|
2014-09-08 10:07:01 +02:00
|
|
|
} else {
|
|
|
|
LOGGER.warning("XMPPConnection was not authenticated");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Runnable pingServerRunnable = new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
LOGGER.fine("ServerPingTask run()");
|
|
|
|
pingServerIfNecessary();
|
2014-02-23 21:36:57 +01:00
|
|
|
}
|
|
|
|
};
|
2014-05-26 17:36:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
try {
|
|
|
|
executorService.shutdown();
|
|
|
|
} finally {
|
|
|
|
super.finalize();
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 12:43:35 +01:00
|
|
|
}
|