view tango/tango/net/cluster/tina/QueueThread.d @ 341:1bb99290e03a trunk

[svn r362] Started merging the old 'test' dir as well as the newer 'tangotests' dir into 'tests/mini' and 'tests/minicomplex'.
author lindquist
date Sun, 13 Jul 2008 02:51:19 +0200
parents 1700239cab2e
children
line wrap: on
line source

/*******************************************************************************

        copyright:      Copyright (c) 2004 Kris Bell. All rights reserved

        license:        BSD style: $(LICENSE)
        
        version:        July 2004: Initial release      
        
        author:         Kris

*******************************************************************************/

module tango.net.cluster.tina.QueueThread;

private import  tango.core.Exception;

private import  tango.net.cluster.tina.ClusterQueue,
                tango.net.cluster.tina.ClusterTypes,
                tango.net.cluster.tina.ClusterThread;

/******************************************************************************

        Thread for handling queue requests.

******************************************************************************/

class QueueThread : ClusterThread
{
        private ClusterQueue queue;
        
        /**********************************************************************

                Note that the conduit stays open until the client kills it

        **********************************************************************/

        this (AbstractServer server, IConduit conduit, Cluster cluster, ClusterQueue queue)
        {
                super (server, conduit, cluster);
                this.queue = queue;
        }

        /**********************************************************************

                process client requests
                
        **********************************************************************/

        void dispatch ()
        {
                ProtocolWriter.Command  cmd;
                long                    time;
                char[]                  channel;
                char[]                  element;

                // wait for request to arrive
                auto content = reader.getPacket (cmd, channel, element, time);

                switch (cmd)
                       {
                       case ProtocolWriter.Command.AddQueue:
                            logger.trace (sprint ("{} add queue entry on channel '{}'", client, channel)); 
        
                            if (queue.put (channel, content))
                                writer.success;
                            else
                               writer.full ("cluster queue is full");
                            break;
        
                       case ProtocolWriter.Command.RemoveQueue:
                            logger.trace (sprint ("{} remove queue entry on channel '{}'", client, channel)); 
        
                            writer.reply (queue.get (channel));
                            break;
             
                       default:
                            throw new IllegalArgumentException ("invalid command");
                       }
        }
}