Class IQRouter
- All Implemented Interfaces:
Module
- Author:
- Iain Shigeoka
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHandler
(IQHandler handler) Adds a new IQHandler to the list of registered handler.void
addIQResultListener
(String id, org.xmpp.component.IQResultListener listener) Adds anIQResultListener
that will be invoked when an IQ result is sent to the server itself and is of type result or error.void
addIQResultListener
(String id, org.xmpp.component.IQResultListener listener, long timeoutmillis) Adds anIQResultListener
that will be invoked when an IQ result is sent to the server itself and is of type result or error.void
initialize
(XMPPServer server) Initializes the basic module.void
removeHandler
(IQHandler handler) Removes an IQHandler from the list of registered handler.void
route
(org.xmpp.packet.IQ packet) Performs the actual packet routing.void
routingFailed
(org.xmpp.packet.JID recipient, org.xmpp.packet.Packet packet) Notification message indicating that a packet has failed to be routed to the recipient.boolean
Determines if this instance has support (formally: has a IQ Handler) for the provided namespace.Methods inherited from class org.jivesoftware.openfire.container.BasicModule
destroy, getName, start, stop
-
Constructor Details
-
IQRouter
public IQRouter()Creates a packet router.
-
-
Method Details
-
route
public void route(org.xmpp.packet.IQ packet) Performs the actual packet routing.
You routing is considered 'quick' and implementations may not take excessive amounts of time to complete the routing. If routing will take a long amount of time, the actual routing should be done in another thread so this method returns quickly.
Warning
Be careful to enforce concurrency DbC of concurrent by synchronizing any accesses to class resources.
- Parameters:
packet
- The packet to route- Throws:
NullPointerException
- If the packet is null
-
addHandler
Adds a new IQHandler to the list of registered handler. The new IQHandler will be responsible for handling IQ packet whose namespace matches the namespace of the IQHandler.
An IllegalArgumentException may be thrown if the IQHandler to register was already provided by the server. The server provides a certain list of IQHandlers when the server is started up.- Parameters:
handler
- the IQHandler to add to the list of registered handler.
-
removeHandler
Removes an IQHandler from the list of registered handler. The IQHandler to remove was responsible for handling IQ packet whose namespace matches the namespace of the IQHandler.
An IllegalArgumentException may be thrown if the IQHandler to remove was already provided by the server. The server provides a certain list of IQHandlers when the server is started up.- Parameters:
handler
- the IQHandler to remove from the list of registered handler.
-
addIQResultListener
Adds anIQResultListener
that will be invoked when an IQ result is sent to the server itself and is of type result or error. This is a nice way for the server to send IQ packets to other XMPP entities and be waked up when a response is received back.Once an IQ result was received, the listener will be invoked and removed from the list of listeners.
If no result was received within one minute, the timeout method of the listener will be invoked and the listener will be removed from the list of listeners.
- Parameters:
id
- the id of the IQ packet being sent from the server to an XMPP entity.listener
- the IQResultListener that will be invoked when an answer is received
-
addIQResultListener
public void addIQResultListener(String id, org.xmpp.component.IQResultListener listener, long timeoutmillis) Adds anIQResultListener
that will be invoked when an IQ result is sent to the server itself and is of type result or error. This is a nice way for the server to send IQ packets to other XMPP entities and be waked up when a response is received back.Once an IQ result was received, the listener will be invoked and removed from the list of listeners.
If no result was received within the specified amount of milliseconds, the timeout method of the listener will be invoked and the listener will be removed from the list of listeners.
Note that the listener will remain active for at least the specified timeout value. The listener will not be removed at the exact moment it times out. Instead, purging of timed out listeners is a periodic scheduled job.
- Parameters:
id
- the id of the IQ packet being sent from the server to an XMPP entity.listener
- the IQResultListener that will be invoked when an answer is received.timeoutmillis
- The amount of milliseconds after which waiting for a response should be stopped.
-
initialize
Description copied from class:BasicModule
Initializes the basic module.
Inheriting classes that choose to override this method MUST call this initialize() method before accessing BasicModule resources.
- Specified by:
initialize
in interfaceModule
- Overrides:
initialize
in classBasicModule
- Parameters:
server
- the server hosting this module.
-
supports
Determines if this instance has support (formally: has a IQ Handler) for the provided namespace.- Parameters:
namespace
- Identifier of functionality (cannot be null)- Returns:
- true if the functionality identified by the namespace is supported, otherwise false.
-
routingFailed
public void routingFailed(org.xmpp.packet.JID recipient, org.xmpp.packet.Packet packet) Notification message indicating that a packet has failed to be routed to the recipient.- Parameters:
recipient
- address of the entity that failed to receive the packet.packet
- IQ packet that failed to be sent to the recipient.
-