mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 18:48:00 +01:00
Cleanup of pingMyServer() API
only throw NotConnectedException, otherwise return false. Before as some sort of exception was always thrown in the error case.
This commit is contained in:
parent
17a254edca
commit
665d65836c
2 changed files with 21 additions and 17 deletions
|
@ -183,9 +183,10 @@ public class PingManager extends Manager {
|
|||
*
|
||||
* @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.
|
||||
* @throws SmackException if there was no response from the server.
|
||||
* @throws NotConnectedException
|
||||
* @throws NoResponseException
|
||||
*/
|
||||
public boolean ping(String jid) throws SmackException {
|
||||
public boolean ping(String jid) throws NoResponseException, NotConnectedException {
|
||||
return ping(jid, connection().getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
|
@ -210,9 +211,9 @@ public class PingManager extends Manager {
|
|||
* {@link #isPingSupported(String)} is false.
|
||||
*
|
||||
* @return true if a reply was received from the server, false otherwise.
|
||||
* @throws SmackException if there was no response from the server.
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
public boolean pingMyServer() throws SmackException {
|
||||
public boolean pingMyServer() throws NotConnectedException {
|
||||
return pingMyServer(true);
|
||||
}
|
||||
|
||||
|
@ -225,13 +226,21 @@ public class PingManager extends Manager {
|
|||
*
|
||||
* @param notifyListeners Notify the PingFailedListener in case of error if true
|
||||
* @return true if the user's server could be pinged.
|
||||
* @throws SmackException if there was no response from the server.
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
public boolean pingMyServer(boolean notifyListeners) throws SmackException {
|
||||
boolean res = ping(connection().getServiceName());
|
||||
public boolean pingMyServer(boolean notifyListeners) throws NotConnectedException {
|
||||
boolean res;
|
||||
try {
|
||||
res = ping(connection().getServiceName());
|
||||
}
|
||||
catch (NoResponseException e) {
|
||||
res = false;
|
||||
}
|
||||
|
||||
if (res) {
|
||||
pongReceived();
|
||||
} else if (notifyListeners) {
|
||||
}
|
||||
else if (notifyListeners) {
|
||||
for (PingFailedListener l : pingFailedListeners)
|
||||
l.pingFailed();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import static org.junit.Assert.fail;
|
|||
import org.jivesoftware.smack.DummyConnection;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.ThreadedDummyConnection;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
|
@ -180,18 +181,12 @@ public class PingTest extends InitExtensions {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void checkPingToServerTimeout() throws SmackException {
|
||||
public void checkPingToServerTimeout() throws NotConnectedException {
|
||||
DummyConnection con = new DummyConnection();
|
||||
PingManager pinger = PingManager.getInstanceFor(con);
|
||||
|
||||
try {
|
||||
pinger.pingMyServer();
|
||||
}
|
||||
catch (NoResponseException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
fail();
|
||||
boolean res = pinger.pingMyServer();
|
||||
assertFalse(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue