mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
Add Manager.getAuthenticatedConnectionOrThrow()
This commit is contained in:
parent
dddba8f08c
commit
1eb315d6b7
2 changed files with 19 additions and 17 deletions
|
@ -18,6 +18,7 @@ package org.jivesoftware.smack;
|
|||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
||||
public abstract class Manager {
|
||||
|
@ -33,4 +34,18 @@ public abstract class Manager {
|
|||
protected final XMPPConnection connection() {
|
||||
return weakConnection.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the XMPPConnection of this Manager if it's authenticated, i.e. logged in. Otherwise throw a {@link NotLoggedInException}.
|
||||
*
|
||||
* @return the XMPPConnection of this Manager.
|
||||
* @throws NotLoggedInException if the connection is not authenticated.
|
||||
*/
|
||||
protected final XMPPConnection getAuthenticatedConnectionOrThrow() throws NotLoggedInException {
|
||||
XMPPConnection connection = connection();
|
||||
if (!connection.isAuthenticated()) {
|
||||
throw new NotLoggedInException();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue