132
|
1 /*******************************************************************************
|
|
2
|
|
3 copyright: Copyright (c) 2004 Kris Bell. All rights reserved
|
|
4
|
|
5 license: BSD style: $(LICENSE)
|
|
6
|
|
7 version: July 2004: Initial release
|
|
8
|
|
9 author: Kris
|
|
10
|
|
11 *******************************************************************************/
|
|
12
|
|
13 module tango.net.cluster.model.IChannel;
|
|
14
|
|
15 private import tango.util.log.Logger;
|
|
16
|
|
17 private import tango.net.cluster.model.IMessage,
|
|
18 tango.net.cluster.model.IConsumer;
|
|
19
|
|
20 /*******************************************************************************
|
|
21
|
|
22 A channel represents something akin to a publish/subscribe topic,
|
|
23 or a radio station. These are used to segregate cluster operations
|
|
24 into a set of groups, where each group is represented by a channel.
|
|
25 Channel names are whatever you want then to be: use of dot notation
|
|
26 has proved useful in the past. See Client.createChannel
|
|
27
|
|
28 *******************************************************************************/
|
|
29
|
|
30 interface IChannel
|
|
31 {
|
|
32 /***********************************************************************
|
|
33
|
|
34 Return the Logger associated with this cluster
|
|
35
|
|
36 ***********************************************************************/
|
|
37
|
|
38 Logger log ();
|
|
39
|
|
40 /***********************************************************************
|
|
41
|
|
42 Return the name of this channel. This is the name provided
|
|
43 when the channel was constructed.
|
|
44
|
|
45 ***********************************************************************/
|
|
46
|
|
47 char[] name ();
|
|
48
|
|
49 /***********************************************************************
|
|
50
|
|
51 Create a message listener on the given
|
|
52 channel. The ChannelListener should be called whenever
|
|
53 a corresponding cluster event happens. Note that the
|
|
54 notification is expected to be on a seperate thread.
|
|
55
|
|
56 ***********************************************************************/
|
|
57
|
|
58 IConsumer createConsumer (ChannelListener notify);
|
|
59
|
|
60 /***********************************************************************
|
|
61
|
|
62 Create a bulletin listener on the given
|
|
63 channel. The ChannelListener should be called whenever
|
|
64 a corresponding cluster event happens. Note that the
|
|
65 notification is expected to be on a seperate thread.
|
|
66
|
|
67 ***********************************************************************/
|
|
68
|
|
69 IConsumer createBulletinConsumer (ChannelListener notify);
|
|
70
|
|
71 /***********************************************************************
|
|
72
|
|
73 Place a cache entry into the cluster. If there is already
|
|
74 a matching entry, it is replaced.
|
|
75
|
|
76 ***********************************************************************/
|
|
77
|
|
78 bool putCache (char[] key, IMessage message);
|
|
79
|
|
80 /***********************************************************************
|
|
81
|
|
82 Return a cluster cache entry, and optionally remove it
|
|
83 from the cluster.
|
|
84
|
|
85 ***********************************************************************/
|
|
86
|
|
87 IMessage getCache (char[] key, bool remove, IMessage host=null);
|
|
88
|
|
89 /***********************************************************************
|
|
90
|
|
91 Ask the cache host to load an entry, via the provided
|
|
92 message. Note that the message itself should contain all
|
|
93 pertinent information to load the entry (such as whatever
|
|
94 key values are required).
|
|
95
|
|
96 The host executes the message in a manner akin to RPC, thus
|
|
97 the message also needs to be registered with the host server
|
|
98
|
|
99 ***********************************************************************/
|
|
100
|
|
101 bool loadCache (char[] key, IMessage message);
|
|
102
|
|
103 /***********************************************************************
|
|
104
|
|
105 Place a new entry into the cluster queue. This may throw
|
|
106 a ClusterFullException when there is no space left within
|
|
107 the cluster queues.
|
|
108
|
|
109 ***********************************************************************/
|
|
110
|
|
111 IMessage putQueue (IMessage message);
|
|
112
|
|
113 /***********************************************************************
|
|
114
|
|
115 Query the cluster for queued entries on our corresponding
|
|
116 channel. Removes, and returns, the first matching entry
|
|
117 from the cluster.
|
|
118
|
|
119 ***********************************************************************/
|
|
120
|
|
121 IMessage getQueue (IMessage host = null);
|
|
122
|
|
123 /***********************************************************************
|
|
124
|
|
125 Scatter a message to all registered listeners. This is
|
|
126 akin to multicast.
|
|
127
|
|
128 ***********************************************************************/
|
|
129
|
|
130 void broadcast (IMessage message = null);
|
|
131
|
|
132 /***********************************************************************
|
|
133
|
|
134 Execute the provided message on the cluster, and return the
|
|
135 results internally
|
|
136
|
|
137 ***********************************************************************/
|
|
138
|
|
139 bool execute (IMessage message);
|
|
140 }
|
|
141
|
|
142
|
|
143 /*******************************************************************************
|
|
144
|
|
145 An IEvent is passed as the argument to each ChannelListener callback
|
|
146
|
|
147 *******************************************************************************/
|
|
148
|
|
149 interface IEvent
|
|
150 {
|
|
151 /***********************************************************************
|
|
152
|
|
153 Return the channel used to initiate the listener
|
|
154
|
|
155 ***********************************************************************/
|
|
156
|
|
157 IChannel channel ();
|
|
158
|
|
159 /***********************************************************************
|
|
160
|
|
161 Return one or more messages associated with this event, or
|
|
162 null if there is nothing available
|
|
163
|
|
164 ***********************************************************************/
|
|
165
|
|
166 IMessage get (IMessage host = null);
|
|
167
|
|
168 /***********************************************************************
|
|
169
|
|
170 Send a message back to the producer. This should support all
|
|
171 the various event styles.
|
|
172
|
|
173 ***********************************************************************/
|
|
174
|
|
175 void reply (IChannel channel, IMessage message);
|
|
176
|
|
177 /***********************************************************************
|
|
178
|
|
179 Return an appropriate reply channel for the given message,
|
|
180 or return null if no reply is expected
|
|
181
|
|
182 ***********************************************************************/
|
|
183
|
|
184 IChannel replyChannel (IMessage message);
|
|
185
|
|
186 /***********************************************************************
|
|
187
|
|
188 Return the Logger associated with this cluster
|
|
189
|
|
190 ***********************************************************************/
|
|
191
|
|
192 Logger log ();
|
|
193 }
|
|
194
|
|
195 /*******************************************************************************
|
|
196
|
|
197 Declares the contract for listeners within the cluster package.
|
|
198 When creating a listener, you provide a callback delegate matching
|
|
199 this signature. The delegate is invoked, on a seperate thread, each
|
|
200 time a relevant event occurs.
|
|
201
|
|
202 *******************************************************************************/
|
|
203
|
|
204 alias void delegate (IEvent event) ChannelListener;
|
|
205
|
|
206
|