KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jegg > impl > MessageHandlerB


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 java.util.logging.Logger JavaDoc;
32
33 import jegg.EggBase;
34 import jegg.Port;
35 import jegg.PortException;
36 import jegg.timer.Timer;
37
38 /**
39  *
40  */

41 public class MessageHandlerB extends EggBase
42 {
43     public static final Logger JavaDoc log = Logger.getLogger(MessageHandlerB.class.getName());
44     public Object JavaDoc msg = new Object JavaDoc();
45     public Object JavaDoc response = null;
46     public Timer timer = null;
47     private String JavaDoc _name;
48     
49     public MessageHandlerB(String JavaDoc s)
50     {
51         _name = s;
52     }
53     
54     public void handle(Init i)
55     {
56         log.info("MessageHandlerB: looking up port for MessageHandlerA");
57         getContext().requestPort("egg_a:Port");
58     }
59     
60     /**
61      * Receive the requested port from the port registgry.
62      * @param p
63      * @throws PortException
64      */

65     protected void handle(Port p) throws PortException
66     {
67         log.info("Sending message to EggClassA");
68         p.send(getContext().createMessage(msg));
69     }
70     
71 // protected void handle(Timeout t)
72
// {
73
// if (t.getTimer().equals(timer))
74
// {
75
// log.info("Timer expired.");
76
// }
77
// else
78
// {
79
// log.info("Timeout from unrecognized Timer");
80
// }
81
// }
82
//
83
/**
84      * Default message handler.
85      */

86     public void handle(Object JavaDoc message)
87     {
88         log.info("EggClassB: Got response from EggClassA");
89         response = message;
90     }
91
92 }
93
Popular Tags