Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

NetworkQueue.d

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003         @file NetworkQueue.d
00004         
00005         Copyright (c) 2004 Kris Bell
00006         
00007         This software is provided 'as-is', without any express or implied
00008         warranty. In no event will the authors be held liable for damages
00009         of any kind arising from the use of this software.
00010         
00011         Permission is hereby granted to anyone to use this software for any 
00012         purpose, including commercial applications, and to alter it and/or 
00013         redistribute it freely, subject to the following restrictions:
00014         
00015         1. The origin of this software must not be misrepresented; you must 
00016            not claim that you wrote the original software. If you use this 
00017            software in a product, an acknowledgment within documentation of 
00018            said product would be appreciated but is not required.
00019 
00020         2. Altered source versions must be plainly marked as such, and must 
00021            not be misrepresented as being the original software.
00022 
00023         3. This notice may not be removed or altered from any distribution
00024            of the source.
00025 
00026         4. Derivative works are permitted, but they must carry this notice
00027            in full and credit the original source.
00028 
00029 
00030                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00031 
00032 
00033         @version        Initial version, July 2004      
00034         @author         Kris
00035 
00036 
00037 *******************************************************************************/
00038 
00039 module mango.cluster.NetworkQueue;
00040 
00041 private import  mango.cluster.Client;
00042 
00043 /*******************************************************************************
00044 
00045         Exposes a gateway to the cluster queues, which collect IPayload
00046         objects until they are removed. Because there is a finite limit
00047         to the quantity of entries stored, the put() method may throw a
00048         ClusterFullException if it cannot add a new entry.
00049 
00050 *******************************************************************************/
00051 
00052 class NetworkQueue : Client
00053 {
00054         /***********************************************************************
00055 
00056                 Construct a NetworkQueue gateway on the provided QOS cluster
00057                 for the specified channel. Each subsequent queue operation
00058                 will take place over the given channel.
00059 
00060         ***********************************************************************/
00061         
00062         this (ICluster cluster, char[] channel)
00063         {
00064                 super (cluster, channel);
00065         }
00066 
00067         /***********************************************************************
00068 
00069                 Create a listener for this channel. Listeners are invoked
00070                 when new content is placed into a corresponding queue.
00071 
00072         ***********************************************************************/
00073         
00074         IConsumer createConsumer (IEventListener listener)
00075         {
00076                 return getCluster.createConsumer (getChannel, IEvent.Style.Message, listener);
00077         }
00078 
00079         /***********************************************************************
00080         
00081                 Add an IPayload entry to the corresponding queue. This
00082                 will throw a ClusterFullException if there is no space
00083                 left in the clustered queue.
00084 
00085         ***********************************************************************/
00086         
00087         void put (IPayload payload)
00088         {
00089                 getCluster.putQueue (getChannel, payload);
00090         }
00091 
00092         /***********************************************************************
00093                 
00094                 Query the cluster for queued entries on our corresponding 
00095                 channel. Returns, and removes, a matching entry from the 
00096                 cluster. This is the synchronous (polling) approach; you
00097                 should use createConsumer() instead for asynchronous style
00098                 notification instead.
00099 
00100         ***********************************************************************/
00101         
00102         IPayload get ()
00103         {
00104                 return getCluster.getQueue (getChannel);
00105         }
00106 }
00107 
00108 
00109 /*******************************************************************************
00110 
00111 *******************************************************************************/
00112 
00113 class NetworkMessage : NetworkQueue, IConsumer
00114 {
00115         private IChannel        reply;
00116         private IConsumer       consumer;
00117 
00118         /***********************************************************************
00119 
00120                 Construct a NetworkMessage gateway on the provided QOS cluster
00121                 for the specified channel. Each subsequent queue operation
00122                 will take place over the given channel.
00123 
00124                 You can listen for cluster replies by providing an optional 
00125                 IEventListener. Outgoing messages will be tagged appropriately
00126                 such that a consumer can respond using IEvent.reply().
00127 
00128         ***********************************************************************/
00129         
00130         this (ICluster cluster, char[] channel, IEventListener listener = null)
00131         {
00132                 super (cluster, channel);
00133 
00134                 if (listener)
00135                    {
00136                    reply = cluster.createChannel (channel ~ ".reply");
00137                    consumer = cluster.createConsumer (reply, IEvent.Style.Message, listener);
00138                    }
00139         }
00140 
00141         /***********************************************************************
00142 
00143                 Cancel the listener. No more events will be dispatched to
00144                 the reply IEventListener.
00145 
00146         ***********************************************************************/
00147         
00148         void cancel()
00149         {
00150                 if (consumer)
00151                     consumer.cancel ();
00152         }
00153 
00154         /***********************************************************************
00155         
00156                 Add an IMessage entry to the corresponding queue. This
00157                 will throw a ClusterFullException if there is no space
00158                 left in the clustered queue.
00159 
00160         ***********************************************************************/
00161         
00162         void put (IMessage message)
00163         {
00164                 if (reply)
00165                     message.setReply (reply.getName);
00166 
00167                 super.put (message);
00168         }
00169 }
00170 
00171 
00172 /*******************************************************************************
00173 
00174 *******************************************************************************/
00175 
00176 class NetworkTask : NetworkMessage
00177 {
00178         /***********************************************************************
00179 
00180                 Construct a NetworkTask gateway on the provided QOS cluster
00181                 for the specified channel. Each subsequent queue operation
00182                 will take place over the given channel.
00183 
00184                 You can listen for cluster replies by providing an optional 
00185                 IEventListener. Outgoing tasks will be tagged appropriately
00186                 such that a consumer can respond using IEvent.reply().
00187 
00188         ***********************************************************************/
00189         
00190         this (ICluster cluster, char[] channel, IEventListener listener = null)
00191         {
00192                 super (cluster, channel, listener);
00193         }
00194 
00195         /***********************************************************************
00196         
00197                 Add an ITask entry to the corresponding queue. This
00198                 will throw a ClusterFullException if there is no space
00199                 left in the clustered queue.
00200 
00201         ***********************************************************************/
00202         
00203         void put (ITask task)
00204         {
00205                 super.put (task);
00206         }
00207 }

Generated on Tue Jan 25 21:18:22 2005 for Mango by doxygen 1.3.6