(file) Return to Monitor.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 karl  1.35 //%2005////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.30 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.23 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.30 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.35 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 mike  1.2  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 kumpf 1.6  // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 mike  1.2  // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18            // 
 19 kumpf 1.6  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 mike  1.2  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 kumpf 1.6  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 mike  1.2  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29            //
 30            // Author: Mike Brasher (mbrasher@bmc.com)
 31            //
 32 a.arora 1.26 // Modified By:   Amit Arora (amita@in.ibm.com) for Bug#1170
 33 sushma.fernandes 1.29 //                Sushma Fernandes (sushma@hp.com) for Bug#2057
 34 joyce.j          1.31 //              Josephine Eskaline Joyce (jojustin@in.ibm.com) for PEP#101
 35 kumpf            1.32 //                Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 36 mike             1.2  //
 37                       //%/////////////////////////////////////////////////////////////////////////////
 38                       
 39                       #ifndef Pegasus_Monitor_h 
 40                       #define Pegasus_Monitor_h 
 41                       
 42                       #include <Pegasus/Common/Config.h>
 43 kumpf            1.12 #include <Pegasus/Common/ArrayInternal.h>
 44 mike             1.2  #include <Pegasus/Common/String.h>
 45                       #include <Pegasus/Common/Message.h>
 46 mday             1.4  #include <Pegasus/Common/ModuleController.h>
 47 kumpf            1.33 #include <Pegasus/Common/Socket.h>
 48 mday             1.15 #include <Pegasus/Common/DQueue.h>
 49 mday             1.16 #include <Pegasus/Common/Sharable.h>
 50                       #include <Pegasus/Common/Linkage.h> 
 51 joyce.j          1.31 #include <Pegasus/Common/AutoPtr.h>
 52 mike             1.2  
 53                       PEGASUS_NAMESPACE_BEGIN
 54                       
 55 mday             1.13 class PEGASUS_COMMON_LINKAGE _MonitorEntry
 56 mike             1.2  {
 57 mday             1.15 public:
 58                         Sint32 socket;
 59                         Uint32 queueId;
 60                         AtomicInt _status;
 61                         int _type;
 62 mday             1.5        
 63 mday             1.15   _MonitorEntry(Sint32 sock, Uint32 q, int Type)
 64                           : socket(sock), queueId(q), _status(EMPTY), _type(Type)
 65 mday             1.5  	   
 66 mday             1.15   {
 67                         }
 68 keith.petley     1.14 
 69 mday             1.15   _MonitorEntry() : socket(0), queueId(0), _status(EMPTY), _type(0)
 70                         {
 71                         }
 72                             
 73                         Boolean operator ==(const void *key) const 
 74                         {
 75                           if(key != 0 && 
 76                              (socket == (reinterpret_cast<_MonitorEntry *>(const_cast<void *>(key)))->socket))
 77                             return true;
 78                           return false;
 79                         }
 80                             
 81                         Boolean operator ==(const _MonitorEntry & key) const
 82                         {
 83                           if(key.socket == socket)
 84                             return true;
 85                           return false;
 86                         }
 87                       
 88                         _MonitorEntry & operator =(const _MonitorEntry & entry)
 89                         {
 90 mday             1.15     if( this != &entry )
 91                             {
 92                       	this->socket = entry.socket;
 93                       	this->queueId = entry.queueId;
 94                       	this->_status = entry._status;
 95                       	this->_type = entry._type;
 96 mday             1.10       }
 97                       	 
 98 mday             1.15     return *this;
 99                         }
100 mday             1.10       
101 mday             1.15   enum entry_status 
102                           {
103                             IDLE,
104                             BUSY,
105                             DYING,
106                             EMPTY
107                           };
108 mike             1.2  };
109                       
110                       /** This message occurs when there is activity on a socket. */
111                       class SocketMessage : public Message
112                       {
113                       public:
114                       
115 mday             1.15   enum Events { READ = 1, WRITE = 2, EXCEPTION = 4 };
116 mday             1.5        
117 mike             1.2  
118 mday             1.15   SocketMessage(Sint32 socket_, Uint32 events_) :
119                           Message(SOCKET_MESSAGE), socket(socket_), events(events_)
120                         {
121                         }
122 mike             1.2  
123 mday             1.15   Sint32 socket;
124                         Uint32 events;
125 mike             1.2  };
126                       
127                       /** This class monitors system-level events and notifies its clients of these
128                           events by posting messages to their queues.
129                       
130                           The monitor generates following message types:
131                       
132                           <ul>
133 mday             1.15     <li> SocketMessage - occurs when activity on a socket </li>
134 mike             1.2      </ul>
135                       
136                           Clients solicit these messages by calling one of the following methods:
137                       
138                           <ul>
139 mday             1.15     <li> solicitSocketMessages() </li>
140 mike             1.2      </ul>
141                       
142                           The following example shows how to solicit socket messages:
143                       
144                           <pre>
145 mday             1.15     Monitor monitor;
146                           Sint32 socket;
147                           Uint32 queueId;
148 mike             1.2  
149 mday             1.4  
150 mday             1.15     ...
151 mike             1.2  
152 mday             1.15     monitor.solicitSocketMessages(
153                           socket, 
154                           SocketMessage::READ | SocketMessage::WRITE, 
155                           queueId);
156 mike             1.2      </pre>
157                       
158                           Each time activity occurs on the given socket, a SocketMessage is
159                           enqueued on the given queue.
160                       
161                           In order the monitor to generate messages, it must be run by calling
162                           the run() method as shown below:
163                       
164                           <pre>
165 mday             1.15     Monitor monitor;
166 mike             1.2  
167 mday             1.15     ...
168 mike             1.2  
169 mday             1.15     Uint32 milliseconds = 5000;
170                           monitor.run(milliseconds);
171 mike             1.2      </pre>
172                       
173                           In this example, the monitor is run for five seconds. The run method
174                           returns after the first message is occurs or five seconds has transpired
175                           (whichever occurs first).
176                       */
177                       class PEGASUS_COMMON_LINKAGE Monitor
178                       {
179 mday             1.15 public:
180                         enum Type 
181                           {
182 a.arora          1.27       UNTYPED, ACCEPTOR, CONNECTOR, CONNECTION, INTERNAL
183 mday             1.15     };
184 mday             1.5        
185                             
186 mday             1.15   /** Default constructor. */
187                         Monitor();
188 mike             1.2  
189 mday             1.15   /** This destruct deletes all handlers which were installed. */
190                         ~Monitor();
191 mike             1.2  
192 sushma.fernandes 1.29   /** Sets the state of the monitor entry to the specified state.
193                             This is used to synchronize the monitor and the worker
194                             thread. Bug# 2057 */
195                         void setState( Uint32 index, _MonitorEntry::entry_status status );
196                       
197 a.arora          1.27   void initializeTickler();
198                         void tickle();
199 mday             1.15   /** Monitor system-level for the given number of milliseconds. Post a
200                             message to the corresponding queue when such an event occurs.
201                             Return after the time has elapsed or a single event has occurred,
202                             whichever occurs first.
203                       
204                             @param timeoutMsec the number of milliseconds to wait for an event.
205                             @return true if an event occured.
206                         */
207                         Boolean run(Uint32 timeoutMsec);
208                       
209                         /** Solicit interest in SocketMessages. Note that there may only 
210                             be one solicitor per socket.
211                       
212                             @param socket the socket to monitor for activity.
213                             @param events socket events to monitor (see the SocketMessage::Events
214                             enumeration for details).
215                             @param queueId of queue on which to post socket messages.
216                             @return false if messages have already been solicited on this socket.
217                         */
218                         int solicitSocketMessages(
219                       			    Sint32 socket, 
220 mday             1.15 			    Uint32 events,
221                       			    Uint32 queueId,
222                       			    int type);
223                       
224                         /** Unsolicit messages on the given socket.
225                       
226                         @param socket on which to unsolicit messages.
227                         @return false if no such solicitation has been made on the given socket.
228                         */
229                         void unsolicitSocketMessages(Sint32);
230                       
231                         /** dispatch a message to the cimom on an independent thread 
232 kumpf            1.24       Note: The Monitor class uses the MessageQueueService ThreadPool.
233                             This ThreadPool is only available if it has been initialized by
234                             the MessageQueueService.  Therefore, the Monitor class should
235                             only be used when the MessageQueueService is active in the
236                             system.
237 mday             1.15    */
238                         static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL _dispatch(void *);
239 mday             1.7        
240 kumpf            1.18   /** stop listening for client connections 
241                          */
242 chuck            1.28   void stopListeningForConnections(Boolean wait);
243 kumpf            1.18 
244 mike             1.2  private:
245 mday             1.5        
246 mday             1.15   Array<_MonitorEntry> _entries;
247                         Mutex _entry_mut;
248 kumpf            1.18   AtomicInt _stopConnections;
249 a.arora          1.27   Semaphore _stopConnectionsSem;
250                         Uint32 _solicitSocketCount;  // tracks how many times solicitSocketCount() has been called
251 mday             1.15   friend class HTTPConnection;
252 a.arora          1.27   struct sockaddr_in _tickle_server_addr;
253                         struct sockaddr_in _tickle_client_addr;
254                         struct sockaddr_in _tickle_peer_addr;
255                         Sint32 _tickle_client_socket; 
256                         Sint32 _tickle_server_socket;      
257                         Sint32 _tickle_peer_socket;
258 sushma.fernandes 1.29   Mutex _tickle_mutex;
259 mike             1.2  };
260 mday             1.15 
261 mike             1.2  PEGASUS_NAMESPACE_END
262                       
263                       #endif /* Pegasus_Monitor_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2