KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > protocols > DUMMY_TP


1 // $Id: DUMMY_TP.java,v 1.1 2005/04/14 14:39:32 belaban Exp $
2

3 package org.jgroups.protocols;
4
5
6 import org.jgroups.Address;
7 import org.jgroups.Event;
8 import org.jgroups.stack.Protocol;
9
10
11 /**
12  * Dummy transport, returns a fake local address and responds to CONNECT with CONNECT_OK.
13  * Compared to LOOPBACK, this discards everything
14  * @author Bela Ban
15  * @version $Id: DUMMY_TP.java,v 1.1 2005/04/14 14:39:32 belaban Exp $
16  */

17 public class DUMMY_TP extends Protocol {
18     private Address local_addr=null;
19
20     public DUMMY_TP() {
21     }
22
23
24     public String JavaDoc toString() {
25         return "Protocol DUMMY_TP (local address: " + local_addr + ')';
26     }
27
28
29     /*------------------------------ Protocol interface ------------------------------ */
30
31     public String JavaDoc getName() {
32         return "DUMMY_TP";
33     }
34
35
36
37
38     public void init() throws Exception JavaDoc {
39         local_addr=new org.jgroups.stack.IpAddress("localhost", 10000); // fake address
40
}
41
42     public void start() throws Exception JavaDoc {
43         passUp(new Event(Event.SET_LOCAL_ADDRESS, local_addr));
44     }
45
46
47     /**
48      * Caller by the layer above this layer. Usually we just put this Message
49      * into the send queue and let one or more worker threads handle it. A worker thread
50      * then removes the Message from the send queue, performs a conversion and adds the
51      * modified Message to the send queue of the layer below it, by calling Down).
52      */

53     public void down(Event evt) {
54
55         switch(evt.getType()) {
56
57         case Event.CONNECT:
58             passUp(new Event(Event.CONNECT_OK));
59             break;
60
61         case Event.DISCONNECT:
62             passUp(new Event(Event.DISCONNECT_OK));
63             break;
64         }
65     }
66
67
68
69     /*--------------------------- End of Protocol interface -------------------------- */
70
71
72
73
74 }
75
Popular Tags