Mercurial > projects > ldc
comparison tango/tango/net/cluster/NetworkQueue.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
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.NetworkQueue; | |
14 | |
15 private import tango.net.cluster.NetworkClient; | |
16 | |
17 /******************************************************************************* | |
18 | |
19 Exposes a gateway to the cluster queues, which collect ICached | |
20 objects until they are removed. Because there is a finite limit | |
21 to the quantity of entries stored, the put() method may throw a | |
22 ClusterFullException if it cannot add a new entry. | |
23 | |
24 *******************************************************************************/ | |
25 | |
26 class NetworkQueue : NetworkClient, IConsumer | |
27 { | |
28 private IChannel reply; | |
29 private IConsumer consumer; | |
30 | |
31 /*********************************************************************** | |
32 | |
33 Construct a NetworkMessage gateway on the provided QOS cluster | |
34 for the specified channel. Each subsequent queue operation | |
35 will take place over the given channel. | |
36 | |
37 You can listen for cluster replies by providing an optional | |
38 ChannelListener. Outgoing messages will be tagged appropriately | |
39 such that a consumer can respond using IEvent.reply | |
40 | |
41 ***********************************************************************/ | |
42 | |
43 this (ICluster cluster, char[] channel, ChannelListener listener = null) | |
44 { | |
45 super (cluster, channel); | |
46 | |
47 if (listener) | |
48 { | |
49 reply = cluster.createChannel (channel ~ ".reply"); | |
50 consumer = reply.createConsumer (listener); | |
51 } | |
52 } | |
53 | |
54 /*********************************************************************** | |
55 | |
56 Add an IMessage entry to the corresponding queue. This | |
57 will throw a ClusterFullException if there is no space | |
58 left in the clustered queue. | |
59 | |
60 ***********************************************************************/ | |
61 | |
62 void put (IMessage message) | |
63 { | |
64 assert (message); | |
65 | |
66 if (reply) | |
67 message.reply = reply.name; | |
68 | |
69 channel.putQueue (message); | |
70 } | |
71 | |
72 /*********************************************************************** | |
73 | |
74 Query the cluster for queued entries on our corresponding | |
75 channel. Returns, and removes, a matching entry from the | |
76 cluster. This is the synchronous (polling) approach; you | |
77 should use createConsumer() instead for asynchronous style | |
78 notification instead. | |
79 | |
80 ***********************************************************************/ | |
81 | |
82 IMessage get () | |
83 { | |
84 return channel.getQueue; | |
85 } | |
86 | |
87 /*********************************************************************** | |
88 | |
89 Cancel the listener. No more events will be dispatched to | |
90 the reply ChannelListener. | |
91 | |
92 ***********************************************************************/ | |
93 | |
94 void cancel() | |
95 { | |
96 if (consumer) | |
97 consumer.cancel; | |
98 consumer = null; | |
99 } | |
100 | |
101 /*********************************************************************** | |
102 | |
103 Create a listener for this channel. Listeners are invoked | |
104 when new content is placed into a corresponding queue. | |
105 | |
106 ***********************************************************************/ | |
107 | |
108 IConsumer createConsumer (ChannelListener listener) | |
109 { | |
110 return channel.createConsumer (listener); | |
111 } | |
112 } |