mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-24 03:27:59 +01:00
Add XMPPConnection trySendStanza()
This commit is contained in:
parent
c7697ea9d0
commit
84f282befe
2 changed files with 63 additions and 0 deletions
|
@ -343,6 +343,29 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
|
||||
protected abstract void sendStanzaInternal(Stanza packet) throws NotConnectedException, InterruptedException;
|
||||
|
||||
@Override
|
||||
public boolean trySendStanza(Stanza stanza) throws NotConnectedException {
|
||||
// Default implementation which falls back to sendStanza() as mentioned in the methods javadoc. May be
|
||||
// overwritten by subclasses.
|
||||
try {
|
||||
sendStanza(stanza);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.FINER,
|
||||
"Thread blocked in fallback implementation of trySendStanza(Stanza) was interrupted", e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trySendStanza(Stanza stanza, long timeout, TimeUnit unit)
|
||||
throws NotConnectedException, InterruptedException {
|
||||
// Default implementation which falls back to sendStanza() as mentioned in the methods javadoc. May be
|
||||
// overwritten by subclasses.
|
||||
sendStanza(stanza);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void sendNonza(Nonza element) throws NotConnectedException, InterruptedException;
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
|
@ -163,6 +165,44 @@ public interface XMPPConnection {
|
|||
* */
|
||||
void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Try to send the given stanza. Returns {@code true} if the stanza was successfully put into the outgoing stanza
|
||||
* queue, otherwise, if {@code false} is returned, the stanza could not be scheduled for sending (for example
|
||||
* because the outgoing element queue is full). Note that this means that the stanza possibly was not put onto the
|
||||
* wire, even if {@code true} is returned, it just has been successfully scheduled for sending.
|
||||
* <p>
|
||||
* <b>Note:</b> Implementations are not required to provide that functionality. In that case this method is mapped
|
||||
* to {@link #sendStanza(Stanza)} and will possibly block until the stanza could be scheduled for sending.
|
||||
* </p>
|
||||
*
|
||||
* @param stanza the stanza to send.
|
||||
* @return {@code true} if the stanza was successfully scheduled to be send, {@code false} otherwise.
|
||||
* @throws NotConnectedException if the connection is not connected.
|
||||
* @since 4.4
|
||||
*/
|
||||
boolean trySendStanza(Stanza stanza) throws NotConnectedException;
|
||||
|
||||
/**
|
||||
* Try to send the given stanza. Returns {@code true} if the stanza was successfully put into the outgoing stanza
|
||||
* queue within the given timeout period, otherwise, if {@code false} is returned, the stanza could not be scheduled
|
||||
* for sending (for example because the outgoing element queue is full). Note that this means that the stanza
|
||||
* possibly was not put onto the wire, even if {@code true} is returned, it just has been successfully scheduled for
|
||||
* sending.
|
||||
* <p>
|
||||
* <b>Note:</b> Implementations are not required to provide that functionality. In that case this method is mapped
|
||||
* to {@link #sendStanza(Stanza)} and will possibly block until the stanza could be scheduled for sending.
|
||||
* </p>
|
||||
*
|
||||
* @param stanza the stanza to send.
|
||||
* @param timeout how long to wait before giving up, in units of {@code unit}.
|
||||
* @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter.
|
||||
* @return {@code true} if the stanza was successfully scheduled to be send, {@code false} otherwise.
|
||||
* @throws NotConnectedException if the connection is not connected.
|
||||
* @throws InterruptedException if the calling thread was interrupted.
|
||||
* @since 4.4
|
||||
*/
|
||||
boolean trySendStanza(Stanza stanza, long timeout, TimeUnit unit) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Send a Nonza.
|
||||
* <p>
|
||||
|
|
Loading…
Reference in a new issue