From 7c46f58c806eb179608c3bb662b8cfbcc7a6cc63 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 12 Jan 2017 20:57:19 +0100 Subject: [PATCH] =?UTF-8?q?Rename=20"PacketReplyTimeout"=20=E2=86=92=20"Re?= =?UTF-8?q?plyTimeout"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smack/bosh/XMPPBOSHConnection.java | 2 +- .../smack/AbstractXMPPConnection.java | 28 +++++++++++++------ .../smack/SASLAuthentication.java | 2 +- .../smack/SmackConfiguration.java | 26 ++++++++++++++++- .../jivesoftware/smack/SmackException.java | 4 +-- .../jivesoftware/smack/StanzaCollector.java | 4 +-- .../smack/SynchronizationPoint.java | 2 +- .../jivesoftware/smack/XMPPConnection.java | 20 +++++++++++++ .../smack/SmackConfigurationTest.java | 4 +-- .../smackx/filetransfer/StreamNegotiator.java | 2 +- .../smackx/muc/MultiUserChat.java | 2 +- .../jivesoftware/smackx/ping/PingManager.java | 4 +-- .../jivesoftware/smackx/ping/PingTest.java | 2 +- .../smackx/pubsub/ConfigureFormTest.java | 2 +- .../org/jivesoftware/smack/roster/Roster.java | 2 +- .../jivesoftware/smack/roster/RosterTest.java | 2 +- .../roster/SubscriptionPreApprovalTest.java | 2 +- .../SmackIntegrationTestFramework.java | 2 +- .../smack/roster/RosterIntegrationTest.java | 2 +- .../igniterealtime/smack/smackrepl/IoT.java | 4 +-- .../smack/smackrepl/TlsTest.java | 2 +- 21 files changed, 88 insertions(+), 32 deletions(-) diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index 62e5d34e0..f88cc7c3e 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -182,7 +182,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { // Wait for the response from the server synchronized (this) { if (!connected) { - final long deadline = System.currentTimeMillis() + getPacketReplyTimeout(); + final long deadline = System.currentTimeMillis() + getReplyTimeout(); while (!notified) { final long now = System.currentTimeMillis(); if (now >= deadline) break; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 75ad70bca..b75e937a5 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -169,9 +169,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { protected String streamId; /** - * + * The timeout to wait for a reply in milliseconds. */ - private long packetReplyTimeout = SmackConfiguration.getDefaultPacketReplyTimeout(); + private long replyTimeout = SmackConfiguration.getDefaultReplyTimeout(); /** * The SmackDebugger allows to log and debug XML traffic. @@ -969,14 +969,26 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } } + @SuppressWarnings("deprecation") @Override public long getPacketReplyTimeout() { - return packetReplyTimeout; + return getReplyTimeout(); + } + + @SuppressWarnings("deprecation") + @Override + public void setPacketReplyTimeout(long timeout) { + setReplyTimeout(timeout); } @Override - public void setPacketReplyTimeout(long timeout) { - packetReplyTimeout = timeout; + public long getReplyTimeout() { + return replyTimeout; + } + + @Override + public void setReplyTimeout(long timeout) { + replyTimeout = timeout; } private static boolean replyToUnknownIqDefault = true; @@ -1466,7 +1478,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { StanzaListener callback, ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException { sendStanzaWithResponseCallback(stanza, replyFilter, callback, exceptionCallback, - getPacketReplyTimeout()); + getReplyTimeout()); } @Override @@ -1527,7 +1539,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { @Override public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback, ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException { - sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getPacketReplyTimeout()); + sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getReplyTimeout()); } @Override @@ -1556,7 +1568,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { public void run() { removeSyncStanzaListener(packetListener); } - }, getPacketReplyTimeout(), TimeUnit.MILLISECONDS); + }, getReplyTimeout(), TimeUnit.MILLISECONDS); } @Override diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java index 024a7ef9e..5cc8f5dcd 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java @@ -200,7 +200,7 @@ public final class SASLAuthentication { else { currentMechanism.authenticate(username, host, xmppServiceDomain, password, authzid, sslSession); } - final long deadline = System.currentTimeMillis() + connection.getPacketReplyTimeout(); + final long deadline = System.currentTimeMillis() + connection.getReplyTimeout(); while (!authenticationSuccessful && saslException == null) { final long now = System.currentTimeMillis(); if (now >= deadline) break; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java index f68ff03ef..2e6770c7a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java @@ -101,8 +101,32 @@ public final class SmackConfiguration { * the server. The default value is 5000 ms. * * @return the milliseconds to wait for a response from the server + * @deprecated use {@link #getDefaultReplyTimeout()} instead. */ + @Deprecated public static int getDefaultPacketReplyTimeout() { + return getDefaultReplyTimeout(); + } + + /** + * Sets the number of milliseconds to wait for a response from + * the server. + * + * @param timeout the milliseconds to wait for a response from the server + * @deprecated use {@link #setDefaultReplyTimeout(int)} instead. + */ + @Deprecated + public static void setDefaultPacketReplyTimeout(int timeout) { + setDefaultReplyTimeout(timeout); + } + + /** + * Returns the number of milliseconds to wait for a response from + * the server. The default value is 5000 ms. + * + * @return the milliseconds to wait for a response from the server + */ + public static int getDefaultReplyTimeout() { // The timeout value must be greater than 0 otherwise we will answer the default value if (defaultPacketReplyTimeout <= 0) { defaultPacketReplyTimeout = 5000; @@ -116,7 +140,7 @@ public final class SmackConfiguration { * * @param timeout the milliseconds to wait for a response from the server */ - public static void setDefaultPacketReplyTimeout(int timeout) { + public static void setDefaultReplyTimeout(int timeout) { if (timeout <= 0) { throw new IllegalArgumentException(); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java index 23e76d96e..b6d190fa6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java @@ -58,7 +58,7 @@ public class SmackException extends Exception { /** * Exception thrown always when there was no response to an request within the stanza(/packet) reply timeout of the used * connection instance. You can modify (e.g. increase) the stanza(/packet) reply timeout with - * {@link XMPPConnection#setPacketReplyTimeout(long)}. + * {@link XMPPConnection#setReplyTimeout(long)}. */ public static final class NoResponseException extends SmackException { /** @@ -111,7 +111,7 @@ public class SmackException extends Exception { } private static StringBuilder getWaitingFor(XMPPConnection connection) { - final long replyTimeout = connection.getPacketReplyTimeout(); + final long replyTimeout = connection.getReplyTimeout(); final StringBuilder sb = new StringBuilder(256); sb.append("No response received within reply timeout. Timeout was " + replyTimeout + "ms (~" diff --git a/smack-core/src/main/java/org/jivesoftware/smack/StanzaCollector.java b/smack-core/src/main/java/org/jivesoftware/smack/StanzaCollector.java index 7b47bc947..888884efd 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/StanzaCollector.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/StanzaCollector.java @@ -161,7 +161,7 @@ public class StanzaCollector { * @throws InterruptedException */ public

P nextResult() throws InterruptedException { - return nextResult(connection.getPacketReplyTimeout()); + return nextResult(connection.getReplyTimeout()); } private volatile long waitStart; @@ -205,7 +205,7 @@ public class StanzaCollector { */ public

P nextResultOrThrow() throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException { - return nextResultOrThrow(connection.getPacketReplyTimeout()); + return nextResultOrThrow(connection.getReplyTimeout()); } /** diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java b/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java index ec991509e..2fa69d72f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java @@ -234,7 +234,7 @@ public class SynchronizationPoint { * @throws InterruptedException */ private void waitForConditionOrTimeout() throws InterruptedException { - long remainingWait = TimeUnit.MILLISECONDS.toNanos(connection.getPacketReplyTimeout()); + long remainingWait = TimeUnit.MILLISECONDS.toNanos(connection.getReplyTimeout()); while (state == State.RequestSent || state == State.Initial) { if (remainingWait <= 0) { state = State.NoResponse; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java index c7d64752f..87965276d 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -407,7 +407,9 @@ public interface XMPPConnection { * XMPPConnection instance. * * @return the stanza(/packet) reply timeout in milliseconds + * @deprecated use {@link #getReplyTimeout()} instead. */ + @Deprecated public long getPacketReplyTimeout(); /** @@ -415,9 +417,27 @@ public interface XMPPConnection { * {@link NoResponseException} if no reply to a request was received within the timeout period. * * @param timeout the stanza(/packet) reply timeout in milliseconds + * @deprecated use {@link #setReplyTimeout(long)} instead. */ + @Deprecated public void setPacketReplyTimeout(long timeout); + /** + * Returns the current value of the reply timeout in milliseconds for request for this + * XMPPConnection instance. + * + * @return the reply timeout in milliseconds + */ + public long getReplyTimeout(); + + /** + * Set the stanza(/packet) reply timeout in milliseconds. In most cases, Smack will throw a + * {@link NoResponseException} if no reply to a request was received within the timeout period. + * + * @param timeout for a reply in milliseconds + */ + public void setReplyTimeout(long timeout); + /** * Get the connection counter of this XMPPConnection instance. Those can be used as ID to * identify the connection, but beware that the ID may not be unique if you create more then diff --git a/smack-core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java b/smack-core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java index 5915db7f5..a863d44dd 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java @@ -28,7 +28,7 @@ public class SmackConfigurationTest { @Test public void testSmackConfiguration() { try { - SmackConfiguration.getDefaultPacketReplyTimeout(); + SmackConfiguration.getDefaultReplyTimeout(); } catch (Throwable t) { fail("SmackConfiguration threw Throwable"); } @@ -40,7 +40,7 @@ public class SmackConfigurationTest { @Ignore @Test public void smackConfigurationShouldNotCauseInitializationTest() { - SmackConfiguration.getDefaultPacketReplyTimeout(); + SmackConfiguration.getDefaultReplyTimeout(); // Only a call to SmackConfiguration.getVersion() should cause Smack to become initialized. assertFalse(SmackConfiguration.isSmackInitialized()); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java index dcc2c0ed6..0590d7aa8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java @@ -96,7 +96,7 @@ public abstract class StreamNegotiator { final String eventKey = initiation.getFrom().toString() + '\t' + initiation.getSessionID(); IQ streamMethodInitiation; try { - streamMethodInitiation = initationSetEvents.performActionAndWaitForEvent(eventKey, connection.getPacketReplyTimeout(), new Callback() { + streamMethodInitiation = initationSetEvents.performActionAndWaitForEvent(eventKey, connection.getReplyTimeout(), new Callback() { @Override public void action() throws NotConnectedException { try { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java index b47cc311d..ea823accc 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -355,7 +355,7 @@ public class MultiUserChat { * @since 4.2 */ public MucEnterConfiguration.Builder getEnterConfigurationBuilder(Resourcepart nickname) { - return new MucEnterConfiguration.Builder(nickname, connection.getPacketReplyTimeout()); + return new MucEnterConfiguration.Builder(nickname, connection.getReplyTimeout()); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java index 0535c0e0a..ce63a78ea 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java @@ -186,7 +186,7 @@ public final class PingManager extends Manager { * @throws InterruptedException */ public boolean ping(Jid jid) throws NotConnectedException, NoResponseException, InterruptedException { - return ping(jid, connection().getPacketReplyTimeout()); + return ping(jid, connection().getReplyTimeout()); } /** @@ -231,7 +231,7 @@ public final class PingManager extends Manager { * @throws InterruptedException */ public boolean pingMyServer(boolean notifyListeners) throws NotConnectedException, InterruptedException { - return pingMyServer(notifyListeners, connection().getPacketReplyTimeout()); + return pingMyServer(notifyListeners, connection().getReplyTimeout()); } /** diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java index 2218aa0fa..9b4b9a178 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java @@ -248,7 +248,7 @@ public class PingTest extends InitExtensions { */ private static DummyConnection getAuthenticatedDummyConnectionWithoutIqReplies() throws SmackException, IOException, XMPPException, InterruptedException { DummyConnection con = new DummyConnection(); - con.setPacketReplyTimeout(500); + con.setReplyTimeout(500); con.connect(); con.login(); return con; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java index 038af40d1..a3686b1a8 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java @@ -88,7 +88,7 @@ public class ConfigureFormTest Node node = mgr.getNode("princely_musings"); - SmackConfiguration.setDefaultPacketReplyTimeout(100); + SmackConfiguration.setDefaultReplyTimeout(100); con.setTimeout(); node.getNodeConfiguration(); diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java index 6082f9400..71d01fa42 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java @@ -473,7 +473,7 @@ public final class Roster extends Manager { } protected boolean waitUntilLoaded() throws InterruptedException { - long waitTime = connection().getPacketReplyTimeout(); + long waitTime = connection().getReplyTimeout(); long start = System.currentTimeMillis(); while (!isLoaded()) { if (waitTime <= 0) { diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java index eea54d25a..10ffd1c3d 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java @@ -75,7 +75,7 @@ public class RosterTest extends InitSmackIm { rosterListener = new TestRosterListener(); roster = Roster.getInstanceFor(connection); roster.addRosterListener(rosterListener); - connection.setPacketReplyTimeout(1000 * 60 * 5); + connection.setReplyTimeout(1000 * 60 * 5); } @After diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java index a864273da..634a7def8 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java @@ -61,7 +61,7 @@ public class SubscriptionPreApprovalTest extends InitSmackIm { rosterListener = new TestRosterListener(); roster = Roster.getInstanceFor(connection); roster.addRosterListener(rosterListener); - connection.setPacketReplyTimeout(1000 * 60 * 5); + connection.setReplyTimeout(1000 * 60 * 5); } @After diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java index 5989a92b4..35edeac47 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java @@ -133,7 +133,7 @@ public class SmackIntegrationTestFramework { SmackConfiguration.DEBUG = true; } if (config.replyTimeout > 0) { - SmackConfiguration.setDefaultPacketReplyTimeout(config.replyTimeout); + SmackConfiguration.setDefaultReplyTimeout(config.replyTimeout); } if (config.securityMode != SecurityMode.required) { AccountManager.sensitiveOperationOverInsecureConnectionDefault(true); diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/RosterIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/RosterIntegrationTest.java index 537d00c7e..3b9c148aa 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/RosterIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/RosterIntegrationTest.java @@ -104,7 +104,7 @@ public class RosterIntegrationTest extends AbstractSmackIntegrationTest { try { rosterOne.createEntry(conTwo.getUser().asBareJid(), conTwosRosterName, null); - assertTrue(addedAndSubscribed.waitForResult(2 * connection.getPacketReplyTimeout())); + assertTrue(addedAndSubscribed.waitForResult(2 * connection.getReplyTimeout())); } finally { rosterTwo.removeSubscribeListener(subscribeListener); diff --git a/smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/IoT.java b/smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/IoT.java index 489d9b424..e1c3d4da1 100644 --- a/smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/IoT.java +++ b/smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/IoT.java @@ -75,8 +75,8 @@ public class IoT { final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration); final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration); - dataThingConnection.setPacketReplyTimeout(TIMEOUT); - readingThingConnection.setPacketReplyTimeout(TIMEOUT); + dataThingConnection.setReplyTimeout(TIMEOUT); + readingThingConnection.setReplyTimeout(TIMEOUT); dataThingConnection.setUseStreamManagement(false); readingThingConnection.setUseStreamManagement(false); diff --git a/smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/TlsTest.java b/smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/TlsTest.java index 16ee15a12..2145cf41b 100644 --- a/smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/TlsTest.java +++ b/smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/TlsTest.java @@ -89,7 +89,7 @@ public class TlsTest { XMPPTCPConnection connection = new XMPPTCPConnection(builder.build()); - connection.setPacketReplyTimeout(20000); + connection.setReplyTimeout(20000); try { connection.connect().login();