Commit 28407de7 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for blocking delivery of packets. JM-915

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6426 b35dd754-fafc-0310-a699-88a17e54d16e
parent 23a18278
......@@ -14,18 +14,12 @@ package org.jivesoftware.wildfire.component;
import org.dom4j.Element;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.PacketException;
import org.jivesoftware.wildfire.PacketRouter;
import org.jivesoftware.wildfire.RoutableChannelHandler;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.*;
import org.xmpp.component.Component;
import org.xmpp.component.ComponentException;
import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
import org.xmpp.packet.*;
import java.util.Collection;
import java.util.Collections;
......@@ -33,6 +27,8 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/**
* Manages the registration and delegation of Components. The ComponentManager
......@@ -167,6 +163,32 @@ public class InternalComponentManager implements ComponentManager, RoutableChann
}
}
public IQ query(Component component, IQ packet, int timeout) throws ComponentException {
final LinkedBlockingQueue<IQ> answer = new LinkedBlockingQueue<IQ>(8);
XMPPServer.getInstance().getIQRouter().addIQResultListener(packet.getID(), new IQResultListener() {
public void receivedAnswer(IQ packet) {
answer.offer(packet);
}
});
sendPacket(component, packet);
IQ reply = null;
try {
reply = answer.poll(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// Ignore
}
if (reply == null) {
reply = IQ.createResultIQ(packet);
reply.setError(PacketError.Condition.item_not_found);
}
return reply;
}
public void query(Component component, IQ packet, IQResultListener listener) throws ComponentException {
XMPPServer.getInstance().getIQRouter().addIQResultListener(packet.getID(), listener);
sendPacket(component, packet);
}
/**
* Adds a new listener that will be notified of component events. Events being
* notified are: 1) when a component is added to the component manager, 2) when
......
......@@ -20,6 +20,8 @@
package org.xmpp.component;
import org.jivesoftware.wildfire.IQResultListener;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet;
/**
......@@ -61,6 +63,35 @@ public interface ComponentManager {
*/
public void sendPacket(Component component, Packet packet) throws ComponentException;
/**
* Sends an IQ packet to the XMPP server and waits to get an IQ of type result or error.
* The "from" value of the packet must not be null. An <tt>IllegalArgumentException</tt>
* will be thrown when the "from" value is null.<p>
*
* If no answer is received from the server before the specified timeout then an IQ
* of type error will be returned.
*
* Components are trusted by the server and may use any value in from address. Usually
* the from address uses the component's address as the domain but this is not required.
*
* @param component the component sending the packet.
* @param packet the IQ packet to send.
* @param timeout the number of milliseconds to wait before returning an IQ error.
* @return the answer sent by the server. The answer could be an IQ of type result or
* error.
*/
public IQ query(Component component, IQ packet, int timeout) throws ComponentException;
/**
* Sends an IQ packet to the server and returns immediately. The specified IQResultListener
* will be invoked when an answer is received.
*
* @param component the component sending the packet.
* @param packet the IQ packet to send.
* @param listener the listener that will be invoked when an answer is received.
*/
public void query(Component component, IQ packet, IQResultListener listener) throws ComponentException;
/**
* Returns a property value specified by name. Properties can be used by
* components to store configuration data. It is recommended that each
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment