KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jegg > impl > MessageHandlerA1


1 /*
2  * Copyright (c) 2004, Bruce Lowery
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * - Neither the name of JEGG nor the names of its contributors may be used
14  * to endorse or promote products derived from this software without
15  * specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */

29 package jegg.impl;
30
31 import jegg.Egg;
32 import jegg.EggContext;
33 import jegg.impl.EggContextImpl;
34
35 /**
36  *
37  */

38 class MessageHandlerA1 implements Egg
39 {
40     private String JavaDoc _name ;
41     private EggContext _context;
42     
43     /**
44      * Constructor.
45      * @param s the name of the test egg.
46      */

47     public MessageHandlerA1(final String JavaDoc s)
48     {
49         _name = s;
50     }
51         
52     public void init() {}
53     
54     public void setContext(EggContext c)
55     {
56         _context = c;
57     }
58     
59     /** The number of messages received by handler 1 */
60     private long _numMessages1 = 0;
61     /**
62      * Return number of messages received by handler 1.
63      * @return number of messages handled.
64      */

65     public final long getNumMessages1()
66     {
67         return _numMessages1;
68     }
69     /** The number of messages received by handler 2 */
70     private long _numMessages2 = 0;
71     /**
72      * Return number of messages received by handler 2.
73      * @return number of messages handled.
74      */

75     public final long getNumMessages2()
76     {
77         return _numMessages2;
78     }
79     
80     /** The number of 'short' messages received */
81     private int _numMessages3;
82     
83     /**
84      * Return number of messages received by handler 3.
85      * @return number of short type messages received.
86      */

87     public final long getNumMessages3()
88     {
89         return _numMessages3;
90     }
91     
92     /** Counter */
93     private long _sum = 0;
94
95     /**
96      * Return counter
97      * @return counter
98      */

99     public final long getSum()
100     {
101         return _sum;
102     }
103
104     /**
105      * Message handler
106      * @param m the message to handle.
107      */

108     public final void handle(final Object JavaDoc m)
109     {
110         _numMessages1++;
111         _sum += 1;
112     }
113     /**
114      * Message handler
115      * @param l the message to handle.
116      */

117     public final void handle(final Long JavaDoc l)
118     {
119         _numMessages2++;
120         _sum += l.longValue();
121     }
122     
123     public final void handle(final Short JavaDoc s)
124     {
125         _numMessages3++;
126         _sum += s.intValue();
127     }
128 }
129
Popular Tags