KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > kernel > overflow > KillReceiver


1 package com.ubermq.kernel.overflow;
2
3 import com.ubermq.kernel.*;
4 import com.ubermq.util.*;
5
6 /**
7  * An overflow handler that kills any connection
8  * that causes its write buffer to overflow. Somewhat
9  * heavy handed, but works very well if overflowing
10  * typically signals an abnormal condition for the
11  * receivers.
12  */

13 public class KillReceiver
14     extends DropIncoming
15     implements IConnectionOverflowHandler
16 {
17     private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(KillReceiver.class);
18     
19     /**
20      * Creates an overflow handler that
21      * closes a connection and deregisters it with the
22      * central control processor.
23      */

24     public KillReceiver()
25     {
26     }
27     
28     /**
29      * Handles an overflow by removing the connection from the
30      * message processor and closing the connection's associated
31      * channels. <P>
32      *
33      * The outgoing message will not be retried.
34      *
35      * @param d the datagram that was being sent when the overflow
36      * occurred.
37      * @param connection the connection that was the target of the
38      * <code>output</code> call.
39      * @param messageProcessor the message processor that is calling
40      * this method.
41      */

42     public int overflow(IDatagram d,
43                         IConnectionInfo r,
44                         IMessageProcessor messageProcessor)
45     {
46         log.info("killing connection endpoint " + r + " to resolve overflow condition.");
47         r.close();
48         return IOverflowHandler.ACTION_FAIL;
49     }
50 }
51
Popular Tags