1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 03:52:06 +01:00

Rename "PacketReplyTimeout" → "ReplyTimeout"

This commit is contained in:
Florian Schmaus 2017-01-12 20:57:19 +01:00
parent b5415fe841
commit 7c46f58c80
21 changed files with 88 additions and 32 deletions

View file

@ -182,7 +182,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
// Wait for the response from the server // Wait for the response from the server
synchronized (this) { synchronized (this) {
if (!connected) { if (!connected) {
final long deadline = System.currentTimeMillis() + getPacketReplyTimeout(); final long deadline = System.currentTimeMillis() + getReplyTimeout();
while (!notified) { while (!notified) {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
if (now >= deadline) break; if (now >= deadline) break;

View file

@ -169,9 +169,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected String streamId; 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. * The SmackDebugger allows to log and debug XML traffic.
@ -969,14 +969,26 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
@SuppressWarnings("deprecation")
@Override @Override
public long getPacketReplyTimeout() { public long getPacketReplyTimeout() {
return packetReplyTimeout; return getReplyTimeout();
}
@SuppressWarnings("deprecation")
@Override
public void setPacketReplyTimeout(long timeout) {
setReplyTimeout(timeout);
} }
@Override @Override
public void setPacketReplyTimeout(long timeout) { public long getReplyTimeout() {
packetReplyTimeout = timeout; return replyTimeout;
}
@Override
public void setReplyTimeout(long timeout) {
replyTimeout = timeout;
} }
private static boolean replyToUnknownIqDefault = true; private static boolean replyToUnknownIqDefault = true;
@ -1466,7 +1478,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
StanzaListener callback, ExceptionCallback exceptionCallback) StanzaListener callback, ExceptionCallback exceptionCallback)
throws NotConnectedException, InterruptedException { throws NotConnectedException, InterruptedException {
sendStanzaWithResponseCallback(stanza, replyFilter, callback, exceptionCallback, sendStanzaWithResponseCallback(stanza, replyFilter, callback, exceptionCallback,
getPacketReplyTimeout()); getReplyTimeout());
} }
@Override @Override
@ -1527,7 +1539,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override @Override
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback, public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException { ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException {
sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getPacketReplyTimeout()); sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getReplyTimeout());
} }
@Override @Override
@ -1556,7 +1568,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
public void run() { public void run() {
removeSyncStanzaListener(packetListener); removeSyncStanzaListener(packetListener);
} }
}, getPacketReplyTimeout(), TimeUnit.MILLISECONDS); }, getReplyTimeout(), TimeUnit.MILLISECONDS);
} }
@Override @Override

View file

@ -200,7 +200,7 @@ public final class SASLAuthentication {
else { else {
currentMechanism.authenticate(username, host, xmppServiceDomain, password, authzid, sslSession); 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) { while (!authenticationSuccessful && saslException == null) {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
if (now >= deadline) break; if (now >= deadline) break;

View file

@ -101,8 +101,32 @@ public final class SmackConfiguration {
* the server. The default value is 5000 ms. * the server. The default value is 5000 ms.
* *
* @return the milliseconds to wait for a response from the server * @return the milliseconds to wait for a response from the server
* @deprecated use {@link #getDefaultReplyTimeout()} instead.
*/ */
@Deprecated
public static int getDefaultPacketReplyTimeout() { 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 // The timeout value must be greater than 0 otherwise we will answer the default value
if (defaultPacketReplyTimeout <= 0) { if (defaultPacketReplyTimeout <= 0) {
defaultPacketReplyTimeout = 5000; defaultPacketReplyTimeout = 5000;
@ -116,7 +140,7 @@ public final class SmackConfiguration {
* *
* @param timeout the milliseconds to wait for a response from the server * @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) { if (timeout <= 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }

View file

@ -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 * 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 * 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 { public static final class NoResponseException extends SmackException {
/** /**
@ -111,7 +111,7 @@ public class SmackException extends Exception {
} }
private static StringBuilder getWaitingFor(XMPPConnection connection) { private static StringBuilder getWaitingFor(XMPPConnection connection) {
final long replyTimeout = connection.getPacketReplyTimeout(); final long replyTimeout = connection.getReplyTimeout();
final StringBuilder sb = new StringBuilder(256); final StringBuilder sb = new StringBuilder(256);
sb.append("No response received within reply timeout. Timeout was " sb.append("No response received within reply timeout. Timeout was "
+ replyTimeout + "ms (~" + replyTimeout + "ms (~"

View file

@ -161,7 +161,7 @@ public class StanzaCollector {
* @throws InterruptedException * @throws InterruptedException
*/ */
public <P extends Stanza> P nextResult() throws InterruptedException { public <P extends Stanza> P nextResult() throws InterruptedException {
return nextResult(connection.getPacketReplyTimeout()); return nextResult(connection.getReplyTimeout());
} }
private volatile long waitStart; private volatile long waitStart;
@ -205,7 +205,7 @@ public class StanzaCollector {
*/ */
public <P extends Stanza> P nextResultOrThrow() throws NoResponseException, XMPPErrorException, public <P extends Stanza> P nextResultOrThrow() throws NoResponseException, XMPPErrorException,
InterruptedException, NotConnectedException { InterruptedException, NotConnectedException {
return nextResultOrThrow(connection.getPacketReplyTimeout()); return nextResultOrThrow(connection.getReplyTimeout());
} }
/** /**

View file

@ -234,7 +234,7 @@ public class SynchronizationPoint<E extends Exception> {
* @throws InterruptedException * @throws InterruptedException
*/ */
private void waitForConditionOrTimeout() 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) { while (state == State.RequestSent || state == State.Initial) {
if (remainingWait <= 0) { if (remainingWait <= 0) {
state = State.NoResponse; state = State.NoResponse;

View file

@ -407,7 +407,9 @@ public interface XMPPConnection {
* XMPPConnection instance. * XMPPConnection instance.
* *
* @return the stanza(/packet) reply timeout in milliseconds * @return the stanza(/packet) reply timeout in milliseconds
* @deprecated use {@link #getReplyTimeout()} instead.
*/ */
@Deprecated
public long getPacketReplyTimeout(); public long getPacketReplyTimeout();
/** /**
@ -415,9 +417,27 @@ public interface XMPPConnection {
* {@link NoResponseException} if no reply to a request was received within the timeout period. * {@link NoResponseException} if no reply to a request was received within the timeout period.
* *
* @param timeout the stanza(/packet) reply timeout in milliseconds * @param timeout the stanza(/packet) reply timeout in milliseconds
* @deprecated use {@link #setReplyTimeout(long)} instead.
*/ */
@Deprecated
public void setPacketReplyTimeout(long timeout); 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 * 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 * identify the connection, but beware that the ID may not be unique if you create more then

View file

@ -28,7 +28,7 @@ public class SmackConfigurationTest {
@Test @Test
public void testSmackConfiguration() { public void testSmackConfiguration() {
try { try {
SmackConfiguration.getDefaultPacketReplyTimeout(); SmackConfiguration.getDefaultReplyTimeout();
} catch (Throwable t) { } catch (Throwable t) {
fail("SmackConfiguration threw Throwable"); fail("SmackConfiguration threw Throwable");
} }
@ -40,7 +40,7 @@ public class SmackConfigurationTest {
@Ignore @Ignore
@Test @Test
public void smackConfigurationShouldNotCauseInitializationTest() { public void smackConfigurationShouldNotCauseInitializationTest() {
SmackConfiguration.getDefaultPacketReplyTimeout(); SmackConfiguration.getDefaultReplyTimeout();
// Only a call to SmackConfiguration.getVersion() should cause Smack to become initialized. // Only a call to SmackConfiguration.getVersion() should cause Smack to become initialized.
assertFalse(SmackConfiguration.isSmackInitialized()); assertFalse(SmackConfiguration.isSmackInitialized());

View file

@ -96,7 +96,7 @@ public abstract class StreamNegotiator {
final String eventKey = initiation.getFrom().toString() + '\t' + initiation.getSessionID(); final String eventKey = initiation.getFrom().toString() + '\t' + initiation.getSessionID();
IQ streamMethodInitiation; IQ streamMethodInitiation;
try { try {
streamMethodInitiation = initationSetEvents.performActionAndWaitForEvent(eventKey, connection.getPacketReplyTimeout(), new Callback<NotConnectedException>() { streamMethodInitiation = initationSetEvents.performActionAndWaitForEvent(eventKey, connection.getReplyTimeout(), new Callback<NotConnectedException>() {
@Override @Override
public void action() throws NotConnectedException { public void action() throws NotConnectedException {
try { try {

View file

@ -355,7 +355,7 @@ public class MultiUserChat {
* @since 4.2 * @since 4.2
*/ */
public MucEnterConfiguration.Builder getEnterConfigurationBuilder(Resourcepart nickname) { public MucEnterConfiguration.Builder getEnterConfigurationBuilder(Resourcepart nickname) {
return new MucEnterConfiguration.Builder(nickname, connection.getPacketReplyTimeout()); return new MucEnterConfiguration.Builder(nickname, connection.getReplyTimeout());
} }
/** /**

View file

@ -186,7 +186,7 @@ public final class PingManager extends Manager {
* @throws InterruptedException * @throws InterruptedException
*/ */
public boolean ping(Jid jid) throws NotConnectedException, NoResponseException, 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 * @throws InterruptedException
*/ */
public boolean pingMyServer(boolean notifyListeners) throws NotConnectedException, InterruptedException { public boolean pingMyServer(boolean notifyListeners) throws NotConnectedException, InterruptedException {
return pingMyServer(notifyListeners, connection().getPacketReplyTimeout()); return pingMyServer(notifyListeners, connection().getReplyTimeout());
} }
/** /**

View file

@ -248,7 +248,7 @@ public class PingTest extends InitExtensions {
*/ */
private static DummyConnection getAuthenticatedDummyConnectionWithoutIqReplies() throws SmackException, IOException, XMPPException, InterruptedException { private static DummyConnection getAuthenticatedDummyConnectionWithoutIqReplies() throws SmackException, IOException, XMPPException, InterruptedException {
DummyConnection con = new DummyConnection(); DummyConnection con = new DummyConnection();
con.setPacketReplyTimeout(500); con.setReplyTimeout(500);
con.connect(); con.connect();
con.login(); con.login();
return con; return con;

View file

@ -88,7 +88,7 @@ public class ConfigureFormTest
Node node = mgr.getNode("princely_musings"); Node node = mgr.getNode("princely_musings");
SmackConfiguration.setDefaultPacketReplyTimeout(100); SmackConfiguration.setDefaultReplyTimeout(100);
con.setTimeout(); con.setTimeout();
node.getNodeConfiguration(); node.getNodeConfiguration();

View file

@ -473,7 +473,7 @@ public final class Roster extends Manager {
} }
protected boolean waitUntilLoaded() throws InterruptedException { protected boolean waitUntilLoaded() throws InterruptedException {
long waitTime = connection().getPacketReplyTimeout(); long waitTime = connection().getReplyTimeout();
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
while (!isLoaded()) { while (!isLoaded()) {
if (waitTime <= 0) { if (waitTime <= 0) {

View file

@ -75,7 +75,7 @@ public class RosterTest extends InitSmackIm {
rosterListener = new TestRosterListener(); rosterListener = new TestRosterListener();
roster = Roster.getInstanceFor(connection); roster = Roster.getInstanceFor(connection);
roster.addRosterListener(rosterListener); roster.addRosterListener(rosterListener);
connection.setPacketReplyTimeout(1000 * 60 * 5); connection.setReplyTimeout(1000 * 60 * 5);
} }
@After @After

View file

@ -61,7 +61,7 @@ public class SubscriptionPreApprovalTest extends InitSmackIm {
rosterListener = new TestRosterListener(); rosterListener = new TestRosterListener();
roster = Roster.getInstanceFor(connection); roster = Roster.getInstanceFor(connection);
roster.addRosterListener(rosterListener); roster.addRosterListener(rosterListener);
connection.setPacketReplyTimeout(1000 * 60 * 5); connection.setReplyTimeout(1000 * 60 * 5);
} }
@After @After

View file

@ -133,7 +133,7 @@ public class SmackIntegrationTestFramework {
SmackConfiguration.DEBUG = true; SmackConfiguration.DEBUG = true;
} }
if (config.replyTimeout > 0) { if (config.replyTimeout > 0) {
SmackConfiguration.setDefaultPacketReplyTimeout(config.replyTimeout); SmackConfiguration.setDefaultReplyTimeout(config.replyTimeout);
} }
if (config.securityMode != SecurityMode.required) { if (config.securityMode != SecurityMode.required) {
AccountManager.sensitiveOperationOverInsecureConnectionDefault(true); AccountManager.sensitiveOperationOverInsecureConnectionDefault(true);

View file

@ -104,7 +104,7 @@ public class RosterIntegrationTest extends AbstractSmackIntegrationTest {
try { try {
rosterOne.createEntry(conTwo.getUser().asBareJid(), conTwosRosterName, null); rosterOne.createEntry(conTwo.getUser().asBareJid(), conTwosRosterName, null);
assertTrue(addedAndSubscribed.waitForResult(2 * connection.getPacketReplyTimeout())); assertTrue(addedAndSubscribed.waitForResult(2 * connection.getReplyTimeout()));
} }
finally { finally {
rosterTwo.removeSubscribeListener(subscribeListener); rosterTwo.removeSubscribeListener(subscribeListener);

View file

@ -75,8 +75,8 @@ public class IoT {
final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration); final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration);
final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration); final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration);
dataThingConnection.setPacketReplyTimeout(TIMEOUT); dataThingConnection.setReplyTimeout(TIMEOUT);
readingThingConnection.setPacketReplyTimeout(TIMEOUT); readingThingConnection.setReplyTimeout(TIMEOUT);
dataThingConnection.setUseStreamManagement(false); dataThingConnection.setUseStreamManagement(false);
readingThingConnection.setUseStreamManagement(false); readingThingConnection.setUseStreamManagement(false);

View file

@ -89,7 +89,7 @@ public class TlsTest {
XMPPTCPConnection connection = new XMPPTCPConnection(builder.build()); XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
connection.setPacketReplyTimeout(20000); connection.setReplyTimeout(20000);
try { try {
connection.connect().login(); connection.connect().login();