/opt/workspace/qpid/tags/M2/Final/cpp/lib/common/sys/posix/EventChannelThreads.h

00001 #ifndef _posix_EventChannelThreads_h
00002 #define _sys_EventChannelThreads_h
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 #include <vector>
00025 
00026 #include <Exception.h>
00027 #include <sys/Time.h>
00028 #include <sys/Monitor.h>
00029 #include <sys/Thread.h>
00030 #include <sys/AtomicCount.h>
00031 #include "EventChannel.h"
00032 
00033 namespace qpid {
00034 namespace sys {
00035 
00042 class EventChannelThreads :
00043         public qpid::SharedObject<EventChannelThreads>,
00044         public sys::Monitor, private sys::Runnable
00045 {
00046   public:
00048     static EventChannelThreads::shared_ptr create(
00049         EventChannel::shared_ptr channel
00050     );
00051 
00052     ~EventChannelThreads();
00053 
00055     void postEvent(Event& event) { channel->postEvent(event); }
00056 
00058     void postEvent(Event* event) { channel->postEvent(event); }
00059 
00066     void shutdown();
00067     
00069     void join();
00070 
00071   private:
00072     typedef std::vector<sys::Thread> Threads;
00073     typedef enum {
00074         RUNNING, TERMINATE_SENT, JOINING, SHUTDOWN
00075     } State;
00076 
00077     EventChannelThreads(EventChannel::shared_ptr underlyingChannel);
00078     void addThread();
00079 
00080     void run();
00081     bool keepRunning();
00082     void adjustThreads();
00083 
00084     EventChannel::shared_ptr channel;
00085     Threads workers;
00086     sys::AtomicCount nWaiting;
00087     State state;
00088     Event terminate;
00089 };
00090 
00091 
00092 }}
00093 
00094 
00095 #endif  

Generated on Mon Nov 26 19:13:17 2007 for Qpid by  doxygen 1.5.1