From 66370c7ef5b214e3ac99dd48eec938d99a1c8823 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 2 Jun 2022 09:41:23 +0200 Subject: [PATCH] [core] Add SmackConfiguration.TRUELY_ASYNC_SENDS This option is meant a quick and dirty hack until XMPPConnection.sendStanza() throws a dedicated Exception in case the connection's outgoing queue is full. --- .../smack/AbstractXMPPConnection.java | 19 +++++++++++++------ .../smack/SmackConfiguration.java | 12 +++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) 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 294cd87c2..5a3ae04ac 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -1,6 +1,6 @@ /** * - * Copyright 2009 Jive Software, 2018-2020 Florian Schmaus. + * Copyright 2009 Jive Software, 2018-2022 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -2000,11 +2000,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { }, timeout, TimeUnit.MILLISECONDS); addAsyncStanzaListener(stanzaListener, replyFilter); - try { - sendStanza(stanza); - } - catch (NotConnectedException | InterruptedException exception) { - future.setException(exception); + Runnable sendOperation = () -> { + try { + sendStanza(stanza); + } + catch (NotConnectedException | InterruptedException exception) { + future.setException(exception); + } + }; + if (SmackConfiguration.TRUELY_ASYNC_SENDS) { + Async.go(sendOperation); + } else { + sendOperation.run(); } return future; 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 746c611a0..ff1dd53f5 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java @@ -1,6 +1,6 @@ /** * - * Copyright 2003-2007 Jive Software, 2018-2020 Florian Schmaus. + * Copyright 2003-2007 Jive Software, 2018-2022 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -387,4 +387,14 @@ public final class SmackConfiguration { } } } + + /** + * If enabled, causes {@link AbstractXMPPConnection} to create a thread for every asynchronous send operation. This + * is meant to work-around a shortcoming of Smack 4.4, where certain send operations are not asynchronous even if + * they should be. This is an expert setting, do not toggle if you do not understand the consequences or have been + * told to do so. Note that it is expected that this will not be needed in future Smack versions. + * + * @since 4.4.6 + */ + public static boolean TRUELY_ASYNC_SENDS = false; }