KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > interceptor > PacketInterceptor


1 /**
2  * $RCSfile: PacketInterceptor.java,v $
3  * $Revision: 1.2 $
4  * $Date: 2005/05/23 17:55:45 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.messenger.interceptor;
13
14 import org.jivesoftware.messenger.Session;
15 import org.xmpp.packet.Packet;
16
17 /**
18  * A packet interceptor encapsulates an action that is invoked on a packet immediately
19  * before or after it was received by a SocketReader and also when the packet is about to
20  * be sent in SocketConnection. These types of actions fall into two broad categories:<ul>
21  * <li> Interceptors that reject the packet by throwing an exception (only when the packet
22  * has not been processed yet).
23  * <li> Interceptors that dynamically transform the packet content.
24  * </ul>
25  *
26  * Any number of interceptors can be installed and removed at run-time. They can be installed
27  * globally or per-user. Global interceptors are run first, followed by any that are installed
28  * for the username.<p>
29  *
30  * @see InterceptorManager
31  * @author Gaston Dombiak
32  */

33 public interface PacketInterceptor {
34
35     /**
36      * Invokes the interceptor on the specified packet. The interceptor can either modify
37      * the packet, or throw a PacketRejectedException to block it from being sent or processed
38      * (when read).<p>
39      *
40      * The exception can only be thrown when <tt>processed</tt> is false which means that the read
41      * packet has not been processed yet or the packet was not sent yet. If the exception is thrown
42      * with a "read" packet then the sender of the packet will receive an answer with an error. But
43      * if the exception is thrown with a "sent" packet then nothing will happen.
44      *
45      * @param packet the packet to take action on.
46      * @param session the session that received or is sending the packet.
47      * @param read flag that indicates if the packet was read or sent.
48      * @param processed flag that indicates if the action (read/send) was performed. (PRE vs. POST).
49      * @throws PacketRejectedException if the packet should be prevented from being processed.
50      */

51     void interceptPacket(Packet packet, Session session, boolean read, boolean processed)
52             throws PacketRejectedException;
53 }
54
Popular Tags