public class InterceptorManager extends Object
PacketInterceptors that are invoked before the packet is sent or processed
(when read) may change the original packet or reject the packet by throwing
a PacketRejectedException
. If the interceptor rejects a received packet
then the sender of the packet receive a
not_allowed
error.
PacketInterceptor
Constructor and Description |
---|
InterceptorManager() |
Modifier and Type | Method and Description |
---|---|
void |
addInterceptor(int index,
PacketInterceptor interceptor)
Inserts a new interceptor at specified index in the list of currently configured
interceptors.
|
void |
addInterceptor(PacketInterceptor interceptor)
Inserts a new interceptor at the end of the list of currently configured
interceptors.
|
void |
addUserInterceptor(String username,
int index,
PacketInterceptor interceptor)
Inserts a new interceptor at specified index in the list of currently configured
interceptors for a specific username.
|
static InterceptorManager |
getInstance()
Returns a singleton instance of InterceptorManager.
|
List<PacketInterceptor> |
getInterceptors()
Returns an unmodifiable list of global packet interceptors.
|
List<PacketInterceptor> |
getUserInterceptors(String username)
Returns an unmodifable list of packet interceptors that are related to the
specified username.
|
protected static void |
invokeInterceptors(Collection<PacketInterceptor> interceptors,
org.xmpp.packet.Packet packet,
Session session,
boolean read,
boolean processed)
Invokes a collection of interceptors for the provided packet.
|
void |
invokeInterceptors(org.xmpp.packet.Packet packet,
Session session,
boolean read,
boolean processed)
Invokes all currently-installed interceptors on the specified packet.
|
boolean |
removeInterceptor(PacketInterceptor interceptor)
Removes the global interceptor from the list.
|
boolean |
removeUserInterceptor(String username,
PacketInterceptor interceptor)
Removes the interceptor from the list of interceptors that are related to a specific
username.
|
public static InterceptorManager getInstance()
public List<PacketInterceptor> getInterceptors()
public void addInterceptor(PacketInterceptor interceptor)
interceptor
- the interceptor to add.public void addInterceptor(int index, PacketInterceptor interceptor)
index
- the index in the list to insert the new interceptor at.interceptor
- the interceptor to add.public boolean removeInterceptor(PacketInterceptor interceptor)
interceptor
- the interceptor to remove.public List<PacketInterceptor> getUserInterceptors(String username)
username
- the name of the user.public void addUserInterceptor(String username, int index, PacketInterceptor interceptor)
username
- the name of the user.index
- the index in the list to insert the new interceptor at.interceptor
- the interceptor to add.public boolean removeUserInterceptor(String username, PacketInterceptor interceptor)
username
- the name of the user.interceptor
- the interceptor to remove.public void invokeInterceptors(org.xmpp.packet.Packet packet, Session session, boolean read, boolean processed) throws PacketRejectedException
Interceptors are executed before and after processing an incoming packet and sending a packet to a user. This means that interceptors are able to alter or reject packets before they are processed further. If possible, interceptors should perform their work in a short time so that overall performance is not compromised.
packet
- the packet that has been read or is about to be sent.session
- the session that received the packet or that the packet
will be sent to.read
- true indicates that the packet was read. When false, the packet
is being sent to a user.processed
- true if the packet has already processed (incoming or outgoing).
If the packet hasn't already been processed, this flag will be false.PacketRejectedException
- if the packet should be prevented from being processed.protected static void invokeInterceptors(Collection<PacketInterceptor> interceptors, org.xmpp.packet.Packet packet, Session session, boolean read, boolean processed) throws PacketRejectedException
interceptors
- The interceptors to be triggered (can be null, can be empty).packet
- the packet that has been read or is about to be sent.session
- the session that received the packet or that the packet
will be sent to.read
- true indicates that the packet was read. When false, the packet
is being sent to a user.processed
- true if the packet has already processed (incoming or outgoing).
If the packet hasn't already been processed, this flag will be false.PacketRejectedException
- if the packet should be prevented from being processed.Copyright © 2003–2019 Ignite Realtime. All rights reserved.