XMPPConnection.java

  1. /**
  2.  *
  3.  * Copyright 2009 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smack;


  18. import org.jivesoftware.smack.SmackException.NoResponseException;
  19. import org.jivesoftware.smack.SmackException.NotConnectedException;
  20. import org.jivesoftware.smack.filter.IQReplyFilter;
  21. import org.jivesoftware.smack.filter.StanzaFilter;
  22. import org.jivesoftware.smack.iqrequest.IQRequestHandler;
  23. import org.jivesoftware.smack.packet.IQ;
  24. import org.jivesoftware.smack.packet.Stanza;
  25. import org.jivesoftware.smack.packet.ExtensionElement;
  26. import org.jivesoftware.smack.packet.PlainStreamElement;
  27. import org.jxmpp.jid.DomainBareJid;
  28. import org.jxmpp.jid.FullJid;

  29. /**
  30.  * The XMPPConnection interface provides an interface for connections to an XMPP server and
  31.  * implements shared methods which are used by the different types of connections (e.g.
  32.  * {@link XMPPTCPConnection} or {@link XMPPBOSHConnection}). To create a connection to an XMPP server
  33.  * a simple usage of this API might look like the following:
  34.  * <p>
  35.  *
  36.  * <pre>
  37.  * // Create a connection to the igniterealtime.org XMPP server.
  38.  * XMPPTCPConnection con = new XMPPTCPConnection("igniterealtime.org");
  39.  * // Connect to the server
  40.  * con.connect();
  41.  * // Most servers require you to login before performing other tasks.
  42.  * con.login("jsmith", "mypass");
  43.  * // Start a new conversation with John Doe and send him a message.
  44.  * Chat chat = ChatManager.getInstanceFor(con).createChat(<font color="green">"jdoe@igniterealtime.org"</font>, new MessageListener() {
  45.  *     public void processMessage(Chat chat, Message message) {
  46.  *         // Print out any messages we get back to standard out.
  47.  *         System.out.println(<font color="green">"Received message: "</font> + message);
  48.  *     }
  49.  * });
  50.  * chat.sendMessage(<font color="green">"Howdy!"</font>);
  51.  * // Disconnect from the server
  52.  * con.disconnect();
  53.  * </pre>
  54.  * </p>
  55.  * <p>
  56.  * Note that the XMPPConnection interface does intentionally not declare any methods that manipulate
  57.  * the connection state, e.g. <code>connect()</code>, <code>disconnect()</code>. You should use the
  58.  * most specific connection type, e.g. <code>XMPPTCPConnection</code> as declared type and use the
  59.  * XMPPConnection interface when you don't need to manipulate the connection state.
  60.  * </p>
  61.  * <p>
  62.  * XMPPConnections can be reused between connections. This means that an Connection may be connected,
  63.  * disconnected and then connected again. Listeners of the XMPPConnection will be retained across
  64.  * connections.
  65.  * </p>
  66.  *
  67.  * @author Matt Tucker
  68.  * @author Guenther Niess
  69.  */
  70. @SuppressWarnings("javadoc")
  71. public interface XMPPConnection {

  72.     /**
  73.      * Returns the name of the service provided by the XMPP server for this connection.
  74.      * This is also called XMPP domain of the connected server. After
  75.      * authenticating with the server the returned value may be different.
  76.      *
  77.      * @return the name of the service provided by the XMPP server.
  78.      */
  79.     public DomainBareJid getServiceName();

  80.     /**
  81.      * Returns the host name of the server where the XMPP server is running. This would be the
  82.      * IP address of the server or a name that may be resolved by a DNS server.
  83.      *
  84.      * @return the host name of the server where the XMPP server is running or null if not yet connected.
  85.      */
  86.     public String getHost();

  87.     /**
  88.      * Returns the port number of the XMPP server for this connection. The default port
  89.      * for normal connections is 5222.
  90.      *
  91.      * @return the port number of the XMPP server or 0 if not yet connected.
  92.      */
  93.     public int getPort();

  94.     /**
  95.      * Returns the full XMPP address of the user that is logged in to the connection or
  96.      * <tt>null</tt> if not logged in yet. An XMPP address is in the form
  97.      * username@server/resource.
  98.      *
  99.      * @return the full XMPP address of the user logged in.
  100.      */
  101.     public FullJid getUser();

  102.     /**
  103.      * Returns the stream ID for this connection, which is the value set by the server
  104.      * when opening an XMPP stream. This value will be <tt>null</tt> if not connected to the server.
  105.      *
  106.      * @return the ID of this connection returned from the XMPP server or <tt>null</tt> if
  107.      *      not connected to the server.
  108.      * @see <a href="http://xmpp.org/rfcs/rfc6120.html#streams-attr-id">RFC 6120 ยง 4.7.3. id</a>
  109.      */
  110.     public String getStreamId();

  111.     /**
  112.      * Returns true if currently connected to the XMPP server.
  113.      *
  114.      * @return true if connected.
  115.      */
  116.     public boolean isConnected();

  117.     /**
  118.      * Returns true if currently authenticated by successfully calling the login method.
  119.      *
  120.      * @return true if authenticated.
  121.      */
  122.     public boolean isAuthenticated();

  123.     /**
  124.      * Returns true if currently authenticated anonymously.
  125.      *
  126.      * @return true if authenticated anonymously.
  127.      */
  128.     public boolean isAnonymous();

  129.     /**
  130.      * Returns true if the connection to the server has successfully negotiated encryption.
  131.      *
  132.      * @return true if a secure connection to the server.
  133.      */
  134.     public boolean isSecureConnection();

  135.     /**
  136.      * Returns true if network traffic is being compressed. When using stream compression network
  137.      * traffic can be reduced up to 90%. Therefore, stream compression is ideal when using a slow
  138.      * speed network connection. However, the server will need to use more CPU time in order to
  139.      * un/compress network data so under high load the server performance might be affected.
  140.      *
  141.      * @return true if network traffic is being compressed.
  142.      */
  143.     public boolean isUsingCompression();

  144.     /**
  145.      * Sends the specified packet to the server.
  146.      *
  147.      * @param packet the packet to send.
  148.      * @throws NotConnectedException
  149.      * @throws InterruptedException
  150.      * @deprecated use {@link #sendStanza(Stanza)} instead.
  151.      */
  152.     @Deprecated
  153.     public void sendPacket(Stanza packet) throws NotConnectedException, InterruptedException;

  154.     /**
  155.      * Sends the specified stanza to the server.
  156.      *
  157.      * @param stanza the stanza to send.
  158.      * @throws NotConnectedException if the connection is not connected.
  159.      * @throws InterruptedException
  160.      * */
  161.     public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException;

  162.     /**
  163.      * Send a PlainStreamElement.
  164.      * <p>
  165.      * <b>This method is not meant for end-user usage!</b> It allows sending plain stream elements, which should not be
  166.      * done by a user manually. <b>Doing so may result in a unstable or unusable connection.</b> Certain Smack APIs use
  167.      * this method to send plain stream elements.
  168.      * </p>
  169.      *
  170.      * @param element
  171.      * @throws NotConnectedException
  172.      * @throws InterruptedException
  173.      */
  174.     public void send(PlainStreamElement element) throws NotConnectedException, InterruptedException;

  175.     /**
  176.      * Adds a connection listener to this connection that will be notified when
  177.      * the connection closes or fails.
  178.      *
  179.      * @param connectionListener a connection listener.
  180.      */
  181.     public void addConnectionListener(ConnectionListener connectionListener);

  182.     /**
  183.      * Removes a connection listener from this connection.
  184.      *
  185.      * @param connectionListener a connection listener.
  186.      */
  187.     public void removeConnectionListener(ConnectionListener connectionListener);

  188.     /**
  189.      * Creates a new packet collector collecting packets that are replies to <code>packet</code>.
  190.      * Does also send <code>packet</code>. The packet filter for the collector is an
  191.      * {@link IQReplyFilter}, guaranteeing that packet id and JID in the 'from' address have
  192.      * expected values.
  193.      *
  194.      * @param packet the packet to filter responses from
  195.      * @return a new packet collector.
  196.      * @throws NotConnectedException
  197.      * @throws InterruptedException
  198.      */
  199.     public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException;

  200.     /**
  201.      * Creates a new packet collector for this connection. A packet filter determines
  202.      * which packets will be accumulated by the collector. A PacketCollector is
  203.      * more suitable to use than a {@link StanzaListener} when you need to wait for
  204.      * a specific result.
  205.      *
  206.      * @param packetFilter the packet filter to use.
  207.      * @param packet the packet to send right after the collector got created
  208.      * @return a new packet collector.
  209.      * @throws InterruptedException
  210.      * @throws NotConnectedException
  211.      */
  212.     public PacketCollector createPacketCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
  213.                     throws NotConnectedException, InterruptedException;

  214.     /**
  215.      * Creates a new packet collector for this connection. A packet filter
  216.      * determines which packets will be accumulated by the collector. A
  217.      * PacketCollector is more suitable to use than a {@link StanzaListener}
  218.      * when you need to wait for a specific result.
  219.      * <p>
  220.      * <b>Note:</b> If you send a Packet right after using this method, then
  221.      * consider using
  222.      * {@link #createPacketCollectorAndSend(StanzaFilter, Stanza)} instead.
  223.      * Otherwise make sure cancel the PacketCollector in every case, e.g. even
  224.      * if an exception is thrown, or otherwise you may leak the PacketCollector.
  225.      * </p>
  226.      *
  227.      * @param packetFilter the packet filter to use.
  228.      * @return a new packet collector.
  229.      */
  230.     public PacketCollector createPacketCollector(StanzaFilter packetFilter);

  231.     /**
  232.      * Create a new packet collector with the given packet collector configuration.
  233.      * <p>
  234.      * Please make sure to cancel the collector when it is no longer required. See also
  235.      * {@link #createPacketCollector(StanzaFilter)}.
  236.      * </p>
  237.      *
  238.      * @param configuration the packet collector configuration.
  239.      * @return a new packet collector.
  240.      * @since 4.1
  241.      */
  242.     public PacketCollector createPacketCollector(PacketCollector.Configuration configuration);

  243.     /**
  244.      * Remove a packet collector of this connection.
  245.      *
  246.      * @param collector a packet collectors which was created for this connection.
  247.      */
  248.     public void removePacketCollector(PacketCollector collector);

  249.     /**
  250.      * Registers a packet listener with this connection.
  251.      * <p>
  252.      * This method has been deprecated. It is important to differentiate between using an asynchronous packet listener
  253.      * (preferred where possible) and a synchronous packet lister. Refer
  254.      * {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)} and
  255.      * {@link #addSyncStanzaListener(StanzaListener, StanzaFilter)} for more information.
  256.      * </p>
  257.      *
  258.      * @param packetListener the packet listener to notify of new received packets.
  259.      * @param packetFilter the packet filter to use.
  260.      * @deprecated use {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)} or
  261.      *             {@link #addSyncStanzaListener(StanzaListener, StanzaFilter)}.
  262.      */
  263.     @Deprecated
  264.     public void addPacketListener(StanzaListener packetListener, StanzaFilter packetFilter);

  265.     /**
  266.      * Removes a packet listener for received packets from this connection.
  267.      *
  268.      * @param packetListener the packet listener to remove.
  269.      * @return true if the packet listener was removed
  270.      * @deprecated use {@link #removeAsyncStanzaListener(StanzaListener)} or {@link #removeSyncStanzaListener(StanzaListener)}.
  271.      */
  272.     @Deprecated
  273.     public boolean removePacketListener(StanzaListener packetListener);

  274.     /**
  275.      * Registers a <b>synchronous</b> packet listener with this connection. A packet listener will be invoked only when
  276.      * an incoming packet is received. A packet filter determines which packets will be delivered to the listener. If
  277.      * the same packet listener is added again with a different filter, only the new filter will be used.
  278.      * <p>
  279.      * <b>Important:</b> This packet listeners will be called in the same <i>single</i> thread that processes all
  280.      * incoming stanzas. Only use this kind of packet filter if it does not perform any XMPP activity that waits for a
  281.      * response. Consider using {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)} when possible, i.e. when
  282.      * the invocation order doesn't have to be the same as the order of the arriving packets. If the order of the
  283.      * arriving packets, consider using a {@link PacketCollector} when possible.
  284.      * </p>
  285.      *
  286.      * @param packetListener the packet listener to notify of new received packets.
  287.      * @param packetFilter the packet filter to use.
  288.      * @see #addPacketInterceptor(StanzaListener, StanzaFilter)
  289.      * @since 4.1
  290.      */
  291.     public void addSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter);

  292.     /**
  293.      * Removes a packet listener for received packets from this connection.
  294.      *
  295.      * @param packetListener the packet listener to remove.
  296.      * @return true if the packet listener was removed
  297.      * @since 4.1
  298.      */
  299.     public boolean removeSyncStanzaListener(StanzaListener packetListener);

  300.     /**
  301.      * Registers an <b>asynchronous</b> packet listener with this connection. A packet listener will be invoked only
  302.      * when an incoming packet is received. A packet filter determines which packets will be delivered to the listener.
  303.      * If the same packet listener is added again with a different filter, only the new filter will be used.
  304.      * <p>
  305.      * Unlike {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)} packet listeners added with this method will be
  306.      * invoked asynchronously in their own thread. Use this method if the order of the packet listeners must not depend
  307.      * on the order how the stanzas where received.
  308.      * </p>
  309.      *
  310.      * @param packetListener the packet listener to notify of new received packets.
  311.      * @param packetFilter the packet filter to use.
  312.      * @see #addPacketInterceptor(StanzaListener, StanzaFilter)
  313.      * @since 4.1
  314.     */
  315.     public void addAsyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter);

  316.     /**
  317.      * Removes an <b>asynchronous</b> packet listener for received packets from this connection.
  318.      *
  319.      * @param packetListener the packet listener to remove.
  320.      * @return true if the packet listener was removed
  321.      * @since 4.1
  322.      */
  323.     public boolean removeAsyncStanzaListener(StanzaListener packetListener);

  324.     /**
  325.      * Registers a packet listener with this connection. The listener will be
  326.      * notified of every packet that this connection sends. A packet filter determines
  327.      * which packets will be delivered to the listener. Note that the thread
  328.      * that writes packets will be used to invoke the listeners. Therefore, each
  329.      * packet listener should complete all operations quickly or use a different
  330.      * thread for processing.
  331.      *
  332.      * @param packetListener the packet listener to notify of sent packets.
  333.      * @param packetFilter   the packet filter to use.
  334.      */
  335.     public void addPacketSendingListener(StanzaListener packetListener, StanzaFilter packetFilter);

  336.     /**
  337.      * Removes a packet listener for sending packets from this connection.
  338.      *
  339.      * @param packetListener the packet listener to remove.
  340.      */
  341.     public void removePacketSendingListener(StanzaListener packetListener);

  342.     /**
  343.      * Registers a packet interceptor with this connection. The interceptor will be
  344.      * invoked every time a packet is about to be sent by this connection. Interceptors
  345.      * may modify the packet to be sent. A packet filter determines which packets
  346.      * will be delivered to the interceptor.
  347.      *
  348.      * <p>
  349.      * NOTE: For a similar functionality on incoming packets, see {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)}.
  350.      *
  351.      * @param packetInterceptor the packet interceptor to notify of packets about to be sent.
  352.      * @param packetFilter      the packet filter to use.
  353.      */
  354.     public void addPacketInterceptor(StanzaListener packetInterceptor, StanzaFilter packetFilter);
  355.  
  356.     /**
  357.      * Removes a packet interceptor.
  358.      *
  359.      * @param packetInterceptor the packet interceptor to remove.
  360.      */
  361.     public void removePacketInterceptor(StanzaListener packetInterceptor);

  362.     /**
  363.      * Returns the current value of the reply timeout in milliseconds for request for this
  364.      * XMPPConnection instance.
  365.      *
  366.      * @return the packet reply timeout in milliseconds
  367.      */
  368.     public long getPacketReplyTimeout();

  369.     /**
  370.      * Set the packet reply timeout in milliseconds. In most cases, Smack will throw a
  371.      * {@link NoResponseException} if no reply to a request was received within the timeout period.
  372.      *
  373.      * @param timeout the packet reply timeout in milliseconds
  374.      */
  375.     public void setPacketReplyTimeout(long timeout);

  376.     /**
  377.      * Get the connection counter of this XMPPConnection instance. Those can be used as ID to
  378.      * identify the connection, but beware that the ID may not be unique if you create more then
  379.      * <tt>2*Integer.MAX_VALUE</tt> instances as the counter could wrap.
  380.      *
  381.      * @return the connection counter of this XMPPConnection
  382.      */
  383.     public int getConnectionCounter();

  384.     public static enum FromMode {
  385.         /**
  386.          * Leave the 'from' attribute unchanged. This is the behavior of Smack < 4.0
  387.          */
  388.         UNCHANGED,
  389.         /**
  390.          * Omit the 'from' attribute. According to RFC 6120 8.1.2.1 1. XMPP servers "MUST (...)
  391.          * override the 'from' attribute specified by the client". It is therefore safe to specify
  392.          * FromMode.OMITTED here.
  393.          */
  394.         OMITTED,
  395.         /**
  396.          * Set the from to the clients full JID. This is usually not required.
  397.          */
  398.         USER
  399.     }

  400.     /**
  401.      * Set the FromMode for this connection instance. Defines how the 'from' attribute of outgoing
  402.      * stanzas should be populated by Smack.
  403.      *
  404.      * @param fromMode
  405.      */
  406.     public void setFromMode(FromMode fromMode);

  407.     /**
  408.      * Get the currently active FromMode.
  409.      *
  410.      * @return the currently active {@link FromMode}
  411.      */
  412.     public FromMode getFromMode();

  413.     /**
  414.      * Get the feature packet extensions for a given stream feature of the
  415.      * server, or <code>null</code> if the server doesn't support that feature.
  416.      *
  417.      * @param element
  418.      * @param namespace
  419.      * @return a packet extensions of the feature or <code>null</code>
  420.      */
  421.     public <F extends ExtensionElement> F getFeature(String element, String namespace);

  422.     /**
  423.      * Return true if the server supports the given stream feature.
  424.      *
  425.      * @param element
  426.      * @param namespace
  427.      * @return true if the server supports the stream feature.
  428.      */
  429.     public boolean hasFeature(String element, String namespace);

  430.     /**
  431.      * Send a stanza and wait asynchronously for a response by using <code>replyFilter</code>.
  432.      * <p>
  433.      * If there is a response, then <code>callback</code> will be invoked. The callback will be
  434.      * invoked at most once and it will be not invoked after the connections default reply timeout
  435.      * has been elapsed.
  436.      * </p>
  437.      *
  438.      * @param stanza the stanza to send (required)
  439.      * @param replyFilter the filter used to determine response stanza (required)
  440.      * @param callback the callback invoked if there is a response (required)
  441.      * @throws NotConnectedException
  442.      * @throws InterruptedException
  443.      */
  444.     public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
  445.                     StanzaListener callback) throws NotConnectedException, InterruptedException;

  446.     /**
  447.      * Send a stanza and wait asynchronously for a response by using <code>replyFilter</code>.
  448.      * <p>
  449.      * If there is a response, then <code>callback</code> will be invoked. If there is no response
  450.      * after the connections default reply timeout, then <code>exceptionCallback</code> will be invoked
  451.      * with a {@link SmackException.NoResponseException}. The callback will be invoked at most once.
  452.      * </p>
  453.      *
  454.      * @param stanza the stanza to send (required)
  455.      * @param replyFilter the filter used to determine response stanza (required)
  456.      * @param callback the callback invoked if there is a response (required)
  457.      * @param exceptionCallback the callback invoked if there is an exception (optional)
  458.      * @throws NotConnectedException
  459.      * @throws InterruptedException
  460.      */
  461.     public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter, StanzaListener callback,
  462.                     ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;

  463.     /**
  464.      * Send a stanza and wait asynchronously for a response by using <code>replyFilter</code>.
  465.      * <p>
  466.      * If there is a response, then <code>callback</code> will be invoked. If there is no response
  467.      * after <code>timeout</code> milliseconds, then <code>exceptionCallback</code> will be invoked
  468.      * with a {@link SmackException.NoResponseException}. The callback will be invoked at most once.
  469.      * </p>
  470.      *
  471.      * @param stanza the stanza to send (required)
  472.      * @param replyFilter the filter used to determine response stanza (required)
  473.      * @param callback the callback invoked if there is a response (required)
  474.      * @param exceptionCallback the callback invoked if there is an exception (optional)
  475.      * @param timeout the timeout in milliseconds to wait for a response
  476.      * @throws NotConnectedException
  477.      * @throws InterruptedException
  478.      */
  479.     public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
  480.                     final StanzaListener callback, final ExceptionCallback exceptionCallback,
  481.                     long timeout) throws NotConnectedException, InterruptedException;

  482.     /**
  483.      * Send a IQ stanza and invoke <code>callback</code> if there is a result of
  484.      * {@link org.jivesoftware.smack.packet.IQ.Type#result} with that result IQ. The callback will
  485.      * not be invoked after the connections default reply timeout has been elapsed.
  486.      *
  487.      * @param iqRequest the IQ stanza to send (required)
  488.      * @param callback the callback invoked if there is result response (required)
  489.      * @throws NotConnectedException
  490.      * @throws InterruptedException
  491.      */
  492.     public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback) throws NotConnectedException, InterruptedException;

  493.     /**
  494.      * Send a IQ stanza and invoke <code>callback</code> if there is a result of
  495.      * {@link org.jivesoftware.smack.packet.IQ.Type#result} with that result IQ. If there is an
  496.      * error response <code>exceptionCallback</code> will be invoked, if not null, with the received
  497.      * error as {@link XMPPException.XMPPErrorException}. If there is no response after the
  498.      * connections default reply timeout, then <code>exceptionCallback</code> will be invoked with a
  499.      * {@link SmackException.NoResponseException}.
  500.      *
  501.      * @param iqRequest the IQ stanza to send (required)
  502.      * @param callback the callback invoked if there is result response (required)
  503.      * @param exceptionCallback the callback invoked if there is an Exception optional
  504.      * @throws NotConnectedException
  505.      * @throws InterruptedException
  506.      */
  507.     public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback,
  508.                     ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;

  509.     /**
  510.      * Send a IQ stanza and invoke <code>callback</code> if there is a result of
  511.      * {@link org.jivesoftware.smack.packet.IQ.Type#result} with that result IQ. If there is an
  512.      * error response <code>exceptionCallback</code> will be invoked, if not null, with the received
  513.      * error as {@link XMPPException.XMPPErrorException}. If there is no response after
  514.      * <code>timeout</code>, then <code>exceptionCallback</code> will be invoked with a
  515.      * {@link SmackException.NoResponseException}.
  516.      *
  517.      * @param iqRequest the IQ stanza to send (required)
  518.      * @param callback the callback invoked if there is result response (required)
  519.      * @param exceptionCallback the callback invoked if there is an Exception optional
  520.      * @param timeout the timeout in milliseconds to wait for a response
  521.      * @throws NotConnectedException
  522.      * @throws InterruptedException
  523.      */
  524.     public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callback,
  525.                     final ExceptionCallback exceptionCallback, long timeout)
  526.                     throws NotConnectedException, InterruptedException;

  527.     /**
  528.      * Add a callback that is called exactly once and synchronously with the incoming stanza that matches the given
  529.      * packet filter.
  530.      *
  531.      * @param callback the callback invoked once the packet filter matches a stanza.
  532.      * @param packetFilter the filter to match stanzas or null to match all.
  533.      */
  534.     public void addOneTimeSyncCallback(StanzaListener callback, StanzaFilter packetFilter);

  535.     /**
  536.      * Register an IQ request handler with this connection.
  537.      * <p>
  538.      * IQ request handler process incoming IQ requests, i.e. incoming IQ stanzas of type 'get' or 'set', and return a result.
  539.      * </p>
  540.      * @param iqRequestHandler the IQ request handler to register.
  541.      * @return the previously registered IQ request handler or null.
  542.      */
  543.     public IQRequestHandler registerIQRequestHandler(IQRequestHandler iqRequestHandler);

  544.     /**
  545.      * Convenience method for {@link #unregisterIQRequestHandler(String, String, org.jivesoftware.smack.packet.IQ.Type)}.
  546.      *
  547.      * @param iqRequestHandler
  548.      * @return the previously registered IQ request handler or null.
  549.      */
  550.     public IQRequestHandler unregisterIQRequestHandler(IQRequestHandler iqRequestHandler);

  551.     /**
  552.      * Unregister an IQ request handler with this connection.
  553.      *
  554.      * @param element the IQ element the IQ request handler is responsible for.
  555.      * @param namespace the IQ namespace the IQ request handler is responsible for.
  556.      * @param type the IQ type the IQ request handler is responsible for.
  557.      * @return the previously registered IQ request handler or null.
  558.      */
  559.     public IQRequestHandler unregisterIQRequestHandler(String element, String namespace, IQ.Type type);

  560.     /**
  561.      * Returns the timestamp in milliseconds when the last stanza was received.
  562.      *
  563.      * @return the timestamp in milliseconds
  564.      */
  565.     public long getLastStanzaReceived();

  566. }