CPN
Computational Process Networks
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CPN::RemoteQueueHolder Class Reference

#include <RemoteQueueHolder.h>

+ Collaboration diagram for CPN::RemoteQueueHolder:

Public Types

typedef std::map< Key_t,
shared_ptr< RemoteQueueBase > > 
QueueMap
 
typedef std::vector
< shared_ptr< RemoteQueueBase > > 
QueueList
 

Public Member Functions

void AddQueue (shared_ptr< RemoteQueueBase > queue)
 
void CleanupQueue (Key_t key)
 
void Cleanup ()
 
void Shutdown ()
 
WakeupHandleGetWakeup ()
 

Private Member Functions

void PrintState ()
 

Private Attributes

QueueMap queuemap
 
QueueList queuelist
 
PthreadMutex lock
 
PthreadCondition cond
 
WakeupHandle wakeup
 

Detailed Description

RemoteQueueHolder takes responsibility of holding references to the remote queues so that they can exist after the node has terminated. This is required because a node can terminate and the RemoteQueue has not finished sending all its data to the other side. This class also allows us to signal to the remote queues to shut down. Note that because closing a socket while selecting on that socket is a race condition and the only other good way of breaking out of the select is to also select on some other file, this holder provides a FileHandle that will cause select to return when shutting down.

Definition at line 47 of file RemoteQueueHolder.h.

Member Typedef Documentation

typedef std::vector<shared_ptr<RemoteQueueBase> > CPN::RemoteQueueHolder::QueueList

Definition at line 50 of file RemoteQueueHolder.h.

typedef std::map<Key_t, shared_ptr<RemoteQueueBase> > CPN::RemoteQueueHolder::QueueMap

Definition at line 49 of file RemoteQueueHolder.h.

Member Function Documentation

void CPN::RemoteQueueHolder::AddQueue ( shared_ptr< RemoteQueueBase queue)

Add a queue.

Parameters
queuethe queue to add

Definition at line 29 of file RemoteQueueHolder.cc.

References lock, and queuemap.

29  {
31  queuemap.insert(std::make_pair(queue->GetKey(), queue));
32  }
void CPN::RemoteQueueHolder::Cleanup ( )

Called by the kernel periodically to clean up queues that are done.

Definition at line 44 of file RemoteQueueHolder.cc.

References lock, queuelist, and AutoLock< Lockable >::Unlock().

44  {
46  QueueList tmp;
47  tmp.swap(queuelist);
48  al.Unlock();
49  tmp.clear();
50  }
std::vector< shared_ptr< RemoteQueueBase > > QueueList

+ Here is the call graph for this function:

void CPN::RemoteQueueHolder::CleanupQueue ( Key_t  key)

Called by the RemoteQueue it self to say it has completed.

Parameters
keythe endpoint key for the queue

Definition at line 34 of file RemoteQueueHolder.cc.

References cond, lock, queuelist, queuemap, and PthreadCondition::Signal().

Referenced by CPN::RemoteQueue::FileThreadEntryPoint().

34  {
36  QueueMap::iterator entry = queuemap.find(key);
37  if (entry != queuemap.end()) {
38  queuelist.push_back(entry->second);
39  queuemap.erase(entry);
40  }
41  cond.Signal();
42  }
PthreadCondition & Signal(void)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

WakeupHandle* CPN::RemoteQueueHolder::GetWakeup ( )
inline

The WakeupHandle is used by all the RemoteQueues to break out of select when shutting down.

Returns
A WakeupHandle pointer.

Definition at line 76 of file RemoteQueueHolder.h.

References wakeup.

Referenced by CPN::RemoteQueue::FileThreadEntryPoint().

76 { return &wakeup; }

+ Here is the caller graph for this function:

void CPN::RemoteQueueHolder::PrintState ( )
private

Definition at line 66 of file RemoteQueueHolder.cc.

References queuelist, and queuemap.

66  {
67  QueueMap::iterator q = queuemap.begin();
68  while (q != queuemap.end()) {
69  q->second->LogState();
70  ++q;
71  }
72  QueueList::iterator itr = queuelist.begin();
73  while (itr != queuelist.end()) {
74  itr->get()->LogState();
75  ++itr;
76  }
77  }
void CPN::RemoteQueueHolder::Shutdown ( )

Call shutdown on each queue and cause the WakeupHandle to make select return.

Definition at line 52 of file RemoteQueueHolder.cc.

References cond, lock, queuelist, queuemap, WakeupHandle::SendWakeup(), PthreadCondition::Wait(), and wakeup.

52  {
54  QueueMap::iterator q = queuemap.begin();
55  while (q != queuemap.end()) {
56  q->second->Shutdown();
57  ++q;
58  }
60  while (!queuemap.empty()) {
61  cond.Wait(lock);
62  }
63  queuelist.clear();
64  }
PthreadCondition & Wait(PthreadMutex &mutex)
void SendWakeup()
Causes this handler to become readable any Poll on this FileHandler will then return.
Definition: WakeupHandle.cc:50

+ Here is the call graph for this function:

Member Data Documentation

PthreadCondition CPN::RemoteQueueHolder::cond
private

Definition at line 82 of file RemoteQueueHolder.h.

Referenced by CleanupQueue(), and Shutdown().

PthreadMutex CPN::RemoteQueueHolder::lock
private

Definition at line 81 of file RemoteQueueHolder.h.

Referenced by AddQueue(), Cleanup(), CleanupQueue(), and Shutdown().

QueueList CPN::RemoteQueueHolder::queuelist
private

Definition at line 80 of file RemoteQueueHolder.h.

Referenced by Cleanup(), CleanupQueue(), PrintState(), and Shutdown().

QueueMap CPN::RemoteQueueHolder::queuemap
private

Definition at line 79 of file RemoteQueueHolder.h.

Referenced by AddQueue(), CleanupQueue(), PrintState(), and Shutdown().

WakeupHandle CPN::RemoteQueueHolder::wakeup
private

Definition at line 83 of file RemoteQueueHolder.h.

Referenced by GetWakeup(), and Shutdown().


The documentation for this class was generated from the following files: