/opt/workspace/qpid/tags/M2/Final/cpp/lib/common/sys/apr/LFProcessor.h

00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
00019  *
00020  */
00021 #ifndef _LFProcessor_
00022 #define _LFProcessor_
00023 
00024 #include <apr_poll.h>
00025 #include <iostream>
00026 #include <vector>
00027 #include <sys/Monitor.h>
00028 #include <sys/Runnable.h>
00029 #include <sys/Thread.h>
00030 
00031 namespace qpid {
00032 namespace sys {
00033 
00034     class LFSessionContext;
00035 
00042     class LFProcessor : private virtual qpid::sys::Runnable
00043     {
00044         typedef std::vector<LFSessionContext*>::iterator iterator;
00045         
00046         const int size;
00047         const apr_interval_time_t timeout;
00048         apr_pollset_t* pollset;
00049         int signalledCount;
00050         int current;
00051         const apr_pollfd_t* signalledFDs;
00052         int count;
00053         const int workerCount;
00054         bool hasLeader;
00055         qpid::sys::Thread* workers;
00056         qpid::sys::Monitor leadLock;
00057         qpid::sys::Mutex countLock;
00058         std::vector<LFSessionContext*> sessions;
00059         volatile bool stopped;
00060         apr_pool_t* pool;
00061 
00062         const apr_pollfd_t* getNextEvent();
00063         void waitToLead();
00064         void relinquishLead();
00065         void poll();        
00066         virtual void run();        
00067 
00068     public:
00069         LFProcessor(int workers, int size, int timeout);
00074         void add(const apr_pollfd_t* const fd);
00078         void remove(const apr_pollfd_t* const fd);
00083         void update(const apr_pollfd_t* const fd);
00087         void reactivate(const apr_pollfd_t* const fd);
00092         void deactivate(const apr_pollfd_t* const fd);
00097         bool full();
00101         bool empty();
00105         void stop();
00109         void start();
00113         bool isStopped();
00114         
00115         ~LFProcessor();
00116     };
00117 
00118 }
00119 }
00120 
00121 
00122 #endif

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