1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-11 10:09:38 +02:00

"not connected" is now a checked Exception thrown by sendPacket()

There is a unsolveable race condition between the connection state and
sendPacket(), i.e. the connection could go down, right after the
method calling sendPacket is called, but before sendPacket() is
invoked. Before this change, sendPacket() has thrown an unchecked
IllegalStateException, which could be ignored by the Smack user, who
would also not notice the race condition. We have decided to throw a
checked Exception in this case now, to make the Smack user aware of
this situation.

SMACK-426
This commit is contained in:
Florian Schmaus 2014-03-19 14:22:20 +01:00
parent d8c656270e
commit fcc8414a92
101 changed files with 845 additions and 382 deletions

View file

@ -22,6 +22,7 @@ import java.util.WeakHashMap;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.Manager;
@ -113,8 +114,9 @@ public class CarbonManager extends Manager {
* You should first check for support using isSupportedByServer().
*
* @param new_state whether carbons should be enabled or disabled
* @throws NotConnectedException
*/
public void sendCarbonsEnabled(final boolean new_state) {
public void sendCarbonsEnabled(final boolean new_state) throws NotConnectedException {
IQ setIQ = carbonsEnabledIQ(new_state);
connection().addPacketListener(new PacketListener() {
@ -140,10 +142,11 @@ public class CarbonManager extends Manager {
* @param new_state whether carbons should be enabled or disabled
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
*
*/
public synchronized void setCarbonsEnabled(final boolean new_state) throws NoResponseException,
XMPPErrorException {
XMPPErrorException, NotConnectedException {
if (enabled_state == new_state)
return;