CPN
Computational Process Networks
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
CPN::RemoteContextClient Class Referenceabstract

This abstract class is the remote context client. More...

#include <RemoteContextClient.h>

+ Inheritance diagram for CPN::RemoteContextClient:
+ Collaboration diagram for CPN::RemoteContextClient:

Classes

struct  GenericWaiter
 
struct  WaiterInfo
 

Public Member Functions

virtual ~RemoteContextClient ()
 
virtual int LogLevel () const
 
virtual int LogLevel (int level)
 
virtual void Log (int level, const std::string &logmsg)
 Log a message to this outputer. More...
 
virtual CPN::Key_t SetupKernel (const std::string &name, const std::string &hostname, const std::string &servname, CPN::KernelBase *kernel)
 Called by the Kernel when it has successfully set it self up. This gives the Context a way to notify the Kernel of events and lets other Kernels look up the connection information for this Kernel. More...
 
virtual CPN::Key_t SetupKernel (const std::string &name, KernelBase *kernel)
 Called by the kernel when it is not in remote mode. More...
 
virtual CPN::Key_t GetKernelKey (const std::string &kernel)
 
virtual std::string GetKernelName (CPN::Key_t kernelkey)
 
virtual void GetKernelConnectionInfo (CPN::Key_t kernelkey, std::string &hostname, std::string &servname)
 obtain the connection information for the given kernel More...
 
virtual CPN::Key_t WaitForKernelStart (const std::string &kernel)
 Does not return until the given kernel has started. More...
 
virtual void SignalKernelStart (CPN::Key_t kernelkey)
 Signal to the context that the given kernel has started. More...
 
virtual void SignalKernelEnd (CPN::Key_t kernelkey)
 Signal to the Context that the given kernel is dead. More...
 
virtual void SendCreateWriter (CPN::Key_t kernelkey, const CPN::SimpleQueueAttr &attr)
 Tell a given kernel that it needs to create a queue write end. More...
 
virtual void SendCreateReader (CPN::Key_t kernelkey, const CPN::SimpleQueueAttr &attr)
 Tell a given kernel that it needs to create a queue read end. More...
 
virtual void SendCreateQueue (CPN::Key_t kernelkey, const CPN::SimpleQueueAttr &attr)
 Tell a given kernel that it needs to create a queue. More...
 
virtual void SendCreateNode (CPN::Key_t kernelkey, const CPN::NodeAttr &attr)
 Tell a given kernel that it needs to create a node. More...
 
virtual CPN::Key_t CreateNodeKey (CPN::Key_t kernelkey, const std::string &nodename)
 Tell the context to allocate a new node key and data structure for a node with nodename which is on kernelkey. More...
 
virtual CPN::Key_t GetNodeKey (const std::string &nodename)
 
virtual std::string GetNodeName (CPN::Key_t nodekey)
 
virtual CPN::Key_t GetNodeKernel (CPN::Key_t nodekey)
 
virtual void SignalNodeStart (CPN::Key_t nodekey)
 Called by the node startup routine to indicate that the node has started. More...
 
virtual void SignalNodeEnd (CPN::Key_t nodekey)
 Called by the node cleanup routine to indicate that the node has ended. More...
 
virtual CPN::Key_t WaitForNodeStart (const std::string &nodename)
 Waits until the node starts and returns the key, if the node is already started returns the key. More...
 
virtual void WaitForNodeEnd (const std::string &nodename)
 Waits for the given node to signal end. More...
 
virtual void WaitForAllNodeEnd ()
 Convenience method which waits until there are no nodes running. If no node have started then this will return immediately. More...
 
virtual CPN::Key_t GetCreateReaderKey (CPN::Key_t nodekey, const std::string &portname)
 Get the key associated with the given endpoint for the given node. Creates the information if it does not exist. More...
 
virtual CPN::Key_t GetReaderNode (CPN::Key_t portkey)
 
virtual CPN::Key_t GetReaderKernel (CPN::Key_t portkey)
 
virtual std::string GetReaderName (CPN::Key_t portkey)
 
virtual CPN::Key_t GetCreateWriterKey (CPN::Key_t nodekey, const std::string &portname)
 
virtual CPN::Key_t GetWriterNode (CPN::Key_t portkey)
 
virtual CPN::Key_t GetWriterKernel (CPN::Key_t portkey)
 
virtual std::string GetWriterName (CPN::Key_t portkey)
 
virtual void ConnectEndpoints (CPN::Key_t writerkey, CPN::Key_t readerkey, const std::string &qname)
 Called by the kernel when a queue is created. Note that the endpoints may have been created when the node requests them but the queue may be created long after that. More...
 
virtual CPN::Key_t GetReadersWriter (CPN::Key_t readerkey)
 
virtual CPN::Key_t GetWritersReader (CPN::Key_t writerkey)
 
virtual void Terminate ()
 Signal to the Context that the network is terminating. After this call most methods will throw a ShutdownException. More...
 
virtual bool IsTerminated ()
 
virtual bool RequireRemote ()
 Lets the kernel know that this context type requires remote activity. This overrides the kernel option for remote activity. Default value is false. More...
 
void DispatchMessage (const Variant &msg)
 
void CheckTerminated ()
 Convenience method that checks IsTerminated and if so throws a ShutdownException. More...
 
virtual unsigned CalculateGrowSize (unsigned currentsize, unsigned request)
 Calculate the new queue size when a queue needs to grow. More...
 

Static Public Member Functions

static shared_ptr< ContextLocal ()
 Create a local context. More...
 

Protected Member Functions

 RemoteContextClient ()
 
virtual void SendMessage (const Variant &msg)=0
 

Protected Attributes

PthreadMutex lock
 

Private Types

typedef shared_ptr< GenericWaiterGenericWaiterPtr
 
typedef std::map< unsigned,
WaiterInfo * > 
WaiterMap
 
typedef std::list< weak_ptr
< GenericWaiter > > 
WaiterList
 
typedef std::map< CPN::Key_t,
CPN::KernelBase * > 
KernelMap
 

Private Member Functions

void SendQueueMsg (CPN::Key_t kernelkey, RCTXMT_t msgtype, const CPN::SimpleQueueAttr &attr)
 
unsigned NewTranID ()
 
void AddWaiter (WaiterInfo *info)
 
GenericWaiterPtr NewGenericWaiter ()
 
void InternalTerminate ()
 
void InternalCheckTerminated ()
 
void * TerminateThread ()
 
Variant RemoteCall (Variant msg)
 
CPN::Key_t GetCreateEndpointKey (RCTXMT_t msgtype, CPN::Key_t nodekey, const std::string &portname)
 
Variant GetEndpointInfo (RCTXMT_t msgtype, CPN::Key_t portkey)
 

Private Attributes

auto_ptr< PthreadterminateThread
 
WaiterMap callwaiters
 
WaiterList waiters
 
KernelMap kernels
 
unsigned trancounter
 
bool shutdown
 
int loglevel
 

Detailed Description

This abstract class is the remote context client.

An implementor only needs to override SendMessage to send the necessary messages to the RemoteContextServer and then call DispatchMessage for the replies from the server.

Definition at line 48 of file RemoteContextClient.h.

Member Typedef Documentation

Definition at line 139 of file RemoteContextClient.h.

Definition at line 158 of file RemoteContextClient.h.

typedef std::list<weak_ptr<GenericWaiter> > CPN::RemoteContextClient::WaiterList
private

Definition at line 156 of file RemoteContextClient.h.

typedef std::map<unsigned, WaiterInfo*> CPN::RemoteContextClient::WaiterMap
private

Definition at line 154 of file RemoteContextClient.h.

Constructor & Destructor Documentation

CPN::RemoteContextClient::~RemoteContextClient ( )
virtual

Definition at line 40 of file RemoteContextClient.cc.

References terminateThread.

40  {
41  if (terminateThread.get()) {
42  terminateThread->Join();
43  }
44  }
auto_ptr< Pthread > terminateThread
CPN::RemoteContextClient::RemoteContextClient ( )
protected

Member Function Documentation

void CPN::RemoteContextClient::AddWaiter ( WaiterInfo info)
private

Definition at line 566 of file RemoteContextClient.cc.

References callwaiters, and CPN::RemoteContextClient::WaiterInfo::waiterid.

Referenced by RemoteCall().

566  {
567  callwaiters.insert(std::make_pair(info->waiterid, info));
568  }

+ Here is the caller graph for this function:

virtual unsigned CPN::Context::CalculateGrowSize ( unsigned  currentsize,
unsigned  request 
)
inlinevirtualinherited

Calculate the new queue size when a queue needs to grow.

Returns
the new queue size

Definition at line 275 of file Context.h.

275 { return currentsize + request; }
void CPN::Context::CheckTerminated ( )
inherited

Convenience method that checks IsTerminated and if so throws a ShutdownException.

Exceptions
ShutdownException

Definition at line 44 of file Context.cc.

References CPN::Context::IsTerminated().

44  {
45  if (IsTerminated()) {
46  throw ShutdownException();
47  }
48  }
virtual bool IsTerminated()=0

+ Here is the call graph for this function:

void CPN::RemoteContextClient::ConnectEndpoints ( CPN::Key_t  writerkey,
CPN::Key_t  readerkey,
const std::string &  qname 
)
virtual

Called by the kernel when a queue is created. Note that the endpoints may have been created when the node requests them but the queue may be created long after that.

Parameters
writerkeythe unique key for the writer endpoint
readerkeythe unique key for the reader endpoint
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 481 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_CONNECT_ENDPOINTS, and SendMessage().

481  {
484  Variant msg(Variant::MapType);
485  msg["type"] = RCTXMT_CONNECT_ENDPOINTS;
486  msg["readerkey"] = readerkey;
487  msg["writerkey"] = writerkey;
488  msg["qname"] = qname;
489  SendMessage(msg);
490  }
virtual void SendMessage(const Variant &msg)=0

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::CreateNodeKey ( CPN::Key_t  kernelkey,
const std::string &  nodename 
)
virtual

Tell the context to allocate a new node key and data structure for a node with nodename which is on kernelkey.

Parameters
kernelkeythe id of the kernel that the node will run on
nodenamethe name of the node
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 266 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_CREATE_NODE_KEY, and RemoteCall().

266  {
269  Variant msg(Variant::MapType);
270  msg["type"] = RCTXMT_CREATE_NODE_KEY;
271  msg["kernelkey"] = kernelkey;
272  msg["name"] = nodename;
273  Variant reply = RemoteCall(msg);
274  if (!reply.Get("success", false).IsTrue()) {
275  throw std::invalid_argument("Node " + nodename + " already exists.");
276  }
277  return reply["nodeinfo"]["key"].AsNumber<Key_t>();
278  }
Variant RemoteCall(Variant msg)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

void CPN::RemoteContextClient::DispatchMessage ( const Variant &  msg)

Handle a message from the RemoteContextServer.

Parameters
msgthe message

Definition at line 580 of file RemoteContextClient.cc.

References ASSERT, callwaiters, InternalTerminate(), kernels, lock, CPN::MsgToNodeAttr(), CPN::MsgToQueueAttr(), CPN::RCTXMT_CREATE_NODE, CPN::RCTXMT_CREATE_QUEUE, CPN::RCTXMT_CREATE_READER, CPN::RCTXMT_CREATE_WRITER, CPN::RCTXMT_TERMINATE, CPN::KernelBase::RemoteCreateNode(), CPN::KernelBase::RemoteCreateQueue(), CPN::KernelBase::RemoteCreateReader(), CPN::KernelBase::RemoteCreateWriter(), AutoLock< Lockable >::Unlock(), and waiters.

Referenced by CPN::RemoteContext::EntryPoint().

580  {
581  if (!msg.IsMap()) { return; }
583  if (msg.Contains("type") && msg["type"].AsNumber<RCTXMT_t>() == RCTXMT_TERMINATE) {
585  return;
586  }
587  // Need to add for the general informative messages.
588  //
589  // The specific reply messages
590  std::string msgtype = msg["msgtype"].AsString();
591  if (msgtype == "reply") {
592  unsigned tranid = msg["msgid"].AsUnsigned();
593  WaiterMap::iterator entry;
594  entry = callwaiters.find(tranid);
595  ASSERT(entry != callwaiters.end());
596  entry->second->msg = msg;
597  entry->second->signaled = true;
598  entry->second->cond.Signal();
599  callwaiters.erase(entry);
600  } else if (msgtype == "broadcast") {
601  WaiterList::iterator entry;
602  entry = waiters.begin();
603  while (entry != waiters.end()) {
604  GenericWaiterPtr waiter = entry->lock();
605  if (waiter) {
606  waiter->messages.push_back(msg);
607  waiter->cond.Signal();
608  ++entry;
609  } else {
610  entry = waiters.erase(entry);
611  }
612  }
613  } else if (msgtype == "kernel") {
614  Key_t kernelkey = msg["kernelkey"].AsNumber<Key_t>();
615  KernelMap::iterator entry = kernels.find(kernelkey);
616  if (entry != kernels.end()) {
617  KernelBase *kernel = entry->second;
618  // Cannot call a kernel method with the lock.
619  plock.Unlock();
620  ASSERT(kernel);
621  switch (msg["type"].AsNumber<RCTXMT_t>()) {
622  case RCTXMT_CREATE_NODE:
623  kernel->RemoteCreateNode(MsgToNodeAttr(msg["nodeattr"]));
624  break;
625  case RCTXMT_CREATE_QUEUE:
626  kernel->RemoteCreateQueue(MsgToQueueAttr(msg["queueattr"]));
627  break;
629  kernel->RemoteCreateWriter(MsgToQueueAttr(msg["queueattr"]));
630  break;
632  kernel->RemoteCreateReader(MsgToQueueAttr(msg["queueattr"]));
633  break;
634  default:
635  ASSERT(false, "Unknown kernel message type");
636  }
637  } else {
638  ASSERT(false, "Message for kernel %llu but said kernel doesn't exist!", kernelkey);
639  }
640  } else {
641  ASSERT(false);
642  }
643  }
RCTXMT_t
RCTXMT Remote Context Message Type These are the message types that the remote context uses to send i...
Definition: RCTXMT.h:33
uint64_t Key_t
Definition: common.h:79
SimpleQueueAttr MsgToQueueAttr(const Variant &msg)
shared_ptr< GenericWaiter > GenericWaiterPtr
NodeAttr MsgToNodeAttr(const Variant &msg)
#define ASSERT(exp,...)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Key_t CPN::RemoteContextClient::GetCreateEndpointKey ( RCTXMT_t  msgtype,
CPN::Key_t  nodekey,
const std::string &  portname 
)
private

Definition at line 645 of file RemoteContextClient.cc.

References InternalCheckTerminated(), and RemoteCall().

Referenced by GetCreateReaderKey(), and GetCreateWriterKey().

645  {
647  Variant msg(Variant::MapType);
648  msg["type"] = msgtype;
649  msg["nodekey"] = nodekey;
650  msg["name"] = portname;
651  Variant reply = RemoteCall(msg);
652  if (!reply.Get("success", false).IsTrue()) {
653  throw std::invalid_argument("No such port");
654  }
655  return reply["endpointinfo"]["key"].AsNumber<Key_t>();
656  }
Variant RemoteCall(Variant msg)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Key_t CPN::RemoteContextClient::GetCreateReaderKey ( CPN::Key_t  nodekey,
const std::string &  portname 
)
virtual

Get the key associated with the given endpoint for the given node. Creates the information if it does not exist.

Parameters
nodekeythe unique id for the node
portnamethe name of the endpoint.
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 435 of file RemoteContextClient.cc.

References GetCreateEndpointKey(), lock, and CPN::RCTXMT_GET_CREATE_READER_KEY.

435  {
437  return GetCreateEndpointKey(RCTXMT_GET_CREATE_READER_KEY, nodekey, portname);
438  }
CPN::Key_t GetCreateEndpointKey(RCTXMT_t msgtype, CPN::Key_t nodekey, const std::string &portname)

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetCreateWriterKey ( CPN::Key_t  nodekey,
const std::string &  portname 
)
virtual
See Also
GetCreateReaderKey

Implements CPN::Context.

Definition at line 458 of file RemoteContextClient.cc.

References GetCreateEndpointKey(), lock, and CPN::RCTXMT_GET_CREATE_WRITER_KEY.

458  {
460  return GetCreateEndpointKey(RCTXMT_GET_CREATE_WRITER_KEY, nodekey, portname);
461  }
CPN::Key_t GetCreateEndpointKey(RCTXMT_t msgtype, CPN::Key_t nodekey, const std::string &portname)

+ Here is the call graph for this function:

Variant CPN::RemoteContextClient::GetEndpointInfo ( RCTXMT_t  msgtype,
CPN::Key_t  portkey 
)
private

Definition at line 658 of file RemoteContextClient.cc.

References ASSERT, InternalCheckTerminated(), and RemoteCall().

Referenced by GetReaderKernel(), GetReaderName(), GetReaderNode(), GetReadersWriter(), GetWriterKernel(), GetWriterName(), GetWriterNode(), and GetWritersReader().

658  {
660  Variant msg(Variant::MapType);
661  msg["type"] = msgtype;
662  msg["key"] = portkey;
663  Variant reply = RemoteCall(msg);
664  ASSERT(reply.Get("success", false).IsTrue(), "msg: %s", libvariant::SerializeJSON(reply).c_str());
665  return reply["endpointinfo"];
666  }
Variant RemoteCall(Variant msg)
#define ASSERT(exp,...)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CPN::RemoteContextClient::GetKernelConnectionInfo ( CPN::Key_t  kernelkey,
std::string &  hostname,
std::string &  servname 
)
virtual

obtain the connection information for the given kernel

Parameters
kernelkeythe unique id for the kernel
hostname(output) string to be filled with the hostname
servname(output) string to be filled with the service name
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 111 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_GET_KERNEL_INFO, and RemoteCall().

111  {
114  Variant msg(Variant::MapType);
115  msg["type"] = RCTXMT_GET_KERNEL_INFO;
116  msg["key"] = kernelkey;
117  Variant reply = RemoteCall(msg);
118  if (!reply.Get("success", false).IsTrue()) {
119  throw std::invalid_argument("No such kernel");
120  }
121  Variant kernelinfo = reply["kernelinfo"];
122  hostname = kernelinfo["hostname"].AsString();
123  servname = kernelinfo["servname"].AsString();
124  }
Variant RemoteCall(Variant msg)

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetKernelKey ( const std::string &  kernel)
virtual
Parameters
kernelthe name of the kernel
Returns
the key for the given kernel.
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 85 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_GET_KERNEL_INFO, and RemoteCall().

85  {
88  Variant msg(Variant::MapType);
89  msg["type"] = RCTXMT_GET_KERNEL_INFO;
90  msg["name"] = kernel;
91  Variant reply = RemoteCall(msg);
92  if (!reply.Get("success", false).IsTrue()) {
93  throw std::invalid_argument("No such kernel");
94  }
95  return reply["kernelinfo"]["key"].AsNumber<Key_t>();
96  }
Variant RemoteCall(Variant msg)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

std::string CPN::RemoteContextClient::GetKernelName ( CPN::Key_t  kernelkey)
virtual
Parameters
kernelkeythe key to the kernel
Returns
the name for the kernel
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 98 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_GET_KERNEL_INFO, and RemoteCall().

98  {
101  Variant msg(Variant::MapType);
102  msg["type"] = RCTXMT_GET_KERNEL_INFO;
103  msg["key"] = kernelkey;
104  Variant reply = RemoteCall(msg);
105  if (!reply.Get("success", false).IsTrue()) {
106  throw std::invalid_argument("No such kernel");
107  }
108  return reply["kernelinfo"]["name"].AsString();
109  }
Variant RemoteCall(Variant msg)

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetNodeKernel ( CPN::Key_t  nodekey)
virtual
Parameters
nodekeythe unique key for the node
Returns
the key for the kernel the node is running on
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 421 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_GET_NODE_INFO, and RemoteCall().

421  {
424  Variant msg(Variant::MapType);
425  msg["type"] = RCTXMT_GET_NODE_INFO;
426  msg["key"] = nodekey;
427  Variant reply = RemoteCall(msg);
428  if (!reply.Get("success", false).IsTrue()) {
429  throw std::invalid_argument("No such node");
430  }
431  return reply["nodeinfo"]["kernelkey"].AsNumber<Key_t>();
432  }
Variant RemoteCall(Variant msg)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetNodeKey ( const std::string &  nodename)
virtual
Returns
the unique key associated with the given node name.
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 280 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_GET_NODE_INFO, and RemoteCall().

280  {
283  Variant msg(Variant::MapType);
284  msg["type"] = RCTXMT_GET_NODE_INFO;
285  msg["name"] = nodename;
286  Variant reply = RemoteCall(msg);
287  if (!reply.Get("success", false).IsTrue()) {
288  throw std::invalid_argument("No such node");
289  }
290  return reply["nodeinfo"]["key"].AsNumber<Key_t>();
291  }
Variant RemoteCall(Variant msg)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

std::string CPN::RemoteContextClient::GetNodeName ( CPN::Key_t  nodekey)
virtual
Returns
the name associated with the given node key
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 293 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_GET_NODE_INFO, and RemoteCall().

293  {
296  Variant msg(Variant::MapType);
297  msg["type"] = RCTXMT_GET_NODE_INFO;
298  msg["key"] = nodekey;
299  Variant reply = RemoteCall(msg);
300  if (!reply.Get("success", false).IsTrue()) {
301  throw std::invalid_argument("No such node");
302  }
303  return reply["nodeinfo"]["name"].AsString();
304  }
Variant RemoteCall(Variant msg)

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetReaderKernel ( CPN::Key_t  portkey)
virtual
Parameters
portkeythe unique id for the port
Returns
the key for the kernel this port is on
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 446 of file RemoteContextClient.cc.

References GetEndpointInfo(), lock, and CPN::RCTXMT_GET_READER_INFO.

446  {
448  Variant info = GetEndpointInfo(RCTXMT_GET_READER_INFO, portkey);
449  return info["kernelkey"].AsNumber<Key_t>();
450  }
Variant GetEndpointInfo(RCTXMT_t msgtype, CPN::Key_t portkey)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

std::string CPN::RemoteContextClient::GetReaderName ( CPN::Key_t  portkey)
virtual
Parameters
portkeythe unique id for the port
Returns
the name of the port
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 452 of file RemoteContextClient.cc.

References GetEndpointInfo(), lock, and CPN::RCTXMT_GET_READER_INFO.

452  {
454  Variant info = GetEndpointInfo(RCTXMT_GET_READER_INFO, portkey);
455  return info["name"].AsString();
456  }
Variant GetEndpointInfo(RCTXMT_t msgtype, CPN::Key_t portkey)

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetReaderNode ( CPN::Key_t  portkey)
virtual
Parameters
portkeythe unique id for the port
Returns
the key for the node this port is on
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 440 of file RemoteContextClient.cc.

References GetEndpointInfo(), lock, and CPN::RCTXMT_GET_READER_INFO.

440  {
442  Variant info = GetEndpointInfo(RCTXMT_GET_READER_INFO, portkey);
443  return info["nodekey"].AsNumber<Key_t>();
444  }
Variant GetEndpointInfo(RCTXMT_t msgtype, CPN::Key_t portkey)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetReadersWriter ( CPN::Key_t  readerkey)
virtual
Parameters
readerkeya unique reader key
Returns
the writer key associated with this reader key if there is one
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 492 of file RemoteContextClient.cc.

References GetEndpointInfo(), lock, and CPN::RCTXMT_GET_READER_INFO.

492  {
494  Variant info = GetEndpointInfo(RCTXMT_GET_READER_INFO, readerkey);
495  return info["writerkey"].AsNumber<Key_t>();
496  }
Variant GetEndpointInfo(RCTXMT_t msgtype, CPN::Key_t portkey)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetWriterKernel ( CPN::Key_t  portkey)
virtual
See Also
GetReaderKernel

Implements CPN::Context.

Definition at line 469 of file RemoteContextClient.cc.

References GetEndpointInfo(), lock, and CPN::RCTXMT_GET_WRITER_INFO.

469  {
471  Variant info = GetEndpointInfo(RCTXMT_GET_WRITER_INFO, portkey);
472  return info["kernelkey"].AsNumber<Key_t>();
473  }
Variant GetEndpointInfo(RCTXMT_t msgtype, CPN::Key_t portkey)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

std::string CPN::RemoteContextClient::GetWriterName ( CPN::Key_t  portkey)
virtual
See Also
GetReaderName

Implements CPN::Context.

Definition at line 475 of file RemoteContextClient.cc.

References GetEndpointInfo(), lock, and CPN::RCTXMT_GET_WRITER_INFO.

475  {
477  Variant info = GetEndpointInfo(RCTXMT_GET_WRITER_INFO, portkey);
478  return info["name"].AsString();
479  }
Variant GetEndpointInfo(RCTXMT_t msgtype, CPN::Key_t portkey)

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetWriterNode ( CPN::Key_t  portkey)
virtual
See Also
GetReaderNode

Implements CPN::Context.

Definition at line 463 of file RemoteContextClient.cc.

References GetEndpointInfo(), lock, and CPN::RCTXMT_GET_WRITER_INFO.

463  {
465  Variant info = GetEndpointInfo(RCTXMT_GET_WRITER_INFO, portkey);
466  return info["nodekey"].AsNumber<Key_t>();
467  }
Variant GetEndpointInfo(RCTXMT_t msgtype, CPN::Key_t portkey)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::GetWritersReader ( CPN::Key_t  writerkey)
virtual
Parameters
writerkeya unique writer key
Returns
the reader key associated with this writer
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 498 of file RemoteContextClient.cc.

References GetEndpointInfo(), lock, and CPN::RCTXMT_GET_WRITER_INFO.

498  {
500  Variant info = GetEndpointInfo(RCTXMT_GET_WRITER_INFO, writerkey);
501  return info["readerkey"].AsNumber<Key_t>();
502  }
Variant GetEndpointInfo(RCTXMT_t msgtype, CPN::Key_t portkey)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

void CPN::RemoteContextClient::InternalCheckTerminated ( )
private
void CPN::RemoteContextClient::InternalTerminate ( )
private

Definition at line 530 of file RemoteContextClient.cc.

References callwaiters, CreatePthreadFunctional(), shutdown, TerminateThread(), terminateThread, and waiters.

Referenced by DispatchMessage(), and Terminate().

530  {
531  if (shutdown) return;
532  shutdown = true;
533  WaiterMap::iterator cwitr = callwaiters.begin();
534  while (cwitr != callwaiters.end()) {
535  cwitr->second->cond.Signal();
536  ++cwitr;
537  }
538  WaiterList::iterator gwitr;
539  gwitr = waiters.begin();
540  while (gwitr != waiters.end()) {
541  GenericWaiterPtr ptr = gwitr->lock();
542  if (ptr) {
543  ptr->cond.Signal();
544  }
545  ++gwitr;
546  }
548  terminateThread->Start();
549  }
PthreadFunctional * CreatePthreadFunctional(T *obj, void *(T::*meth)(void))
auto_ptr< Pthread > terminateThread
shared_ptr< GenericWaiter > GenericWaiterPtr

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CPN::RemoteContextClient::IsTerminated ( )
virtual
Returns
true if Terminate has been called

Implements CPN::Context.

Definition at line 551 of file RemoteContextClient.cc.

References lock, and shutdown.

shared_ptr< Context > CPN::Context::Local ( )
staticinherited

Create a local context.

Returns
a new local context.

Definition at line 29 of file Context.cc.

Referenced by CPN::Kernel::Kernel(), and CPN::VariantCPNLoader::LoadContext().

29  {
30  return shared_ptr<Context>(new LocalContext);
31  }

+ Here is the caller graph for this function:

void CPN::RemoteContextClient::Log ( int  level,
const std::string &  msg 
)
virtual

Log a message to this outputer.

Parameters
levelthe level of this message
msgthe message

Implements LoggerOutput.

Definition at line 56 of file RemoteContextClient.cc.

References lock, loglevel, CPN::RCTXMT_LOG, and SendMessage().

56  {
58  if (level >= loglevel) {
59  Variant msg(Variant::MapType);
60  msg["type"] = RCTXMT_LOG;
61  msg["msg"] = logmsg;
62  SendMessage(msg);
63  }
64  }
virtual void SendMessage(const Variant &msg)=0

+ Here is the call graph for this function:

int CPN::RemoteContextClient::LogLevel ( ) const
virtual
Returns
the current log level

Implements LoggerOutput.

Definition at line 46 of file RemoteContextClient.cc.

References lock, and loglevel.

int CPN::RemoteContextClient::LogLevel ( int  level)
virtual
Parameters
levelthe new log level
Returns
the new log level

Implements LoggerOutput.

Definition at line 51 of file RemoteContextClient.cc.

References lock, and loglevel.

RemoteContextClient::GenericWaiterPtr CPN::RemoteContextClient::NewGenericWaiter ( )
private

Definition at line 570 of file RemoteContextClient.cc.

References waiters.

Referenced by WaitForAllNodeEnd(), WaitForKernelStart(), WaitForNodeEnd(), and WaitForNodeStart().

570  {
571  GenericWaiterPtr gw = GenericWaiterPtr(new GenericWaiter);
572  waiters.push_back(gw);
573  return gw;
574  }
shared_ptr< GenericWaiter > GenericWaiterPtr

+ Here is the caller graph for this function:

unsigned CPN::RemoteContextClient::NewTranID ( )
private

Definition at line 576 of file RemoteContextClient.cc.

References trancounter.

Referenced by RemoteCall().

576  {
577  return ++trancounter;
578  }

+ Here is the caller graph for this function:

Variant CPN::RemoteContextClient::RemoteCall ( Variant  msg)
private

Definition at line 668 of file RemoteContextClient.cc.

References AddWaiter(), CPN::RemoteContextClient::WaiterInfo::cond, InternalCheckTerminated(), lock, CPN::RemoteContextClient::WaiterInfo::msg, NewTranID(), SendMessage(), CPN::RemoteContextClient::WaiterInfo::signaled, PthreadCondition::Wait(), and CPN::RemoteContextClient::WaiterInfo::waiterid.

Referenced by CreateNodeKey(), GetCreateEndpointKey(), GetEndpointInfo(), GetKernelConnectionInfo(), GetKernelKey(), GetKernelName(), GetNodeKernel(), GetNodeKey(), GetNodeName(), SetupKernel(), WaitForAllNodeEnd(), WaitForKernelStart(), WaitForNodeEnd(), and WaitForNodeStart().

668  {
669  WaiterInfo winfo(NewTranID());
670  AddWaiter(&winfo);
671  msg["msgid"] = winfo.waiterid;
672  SendMessage(msg);
673  while (!winfo.signaled) {
674  winfo.cond.Wait(lock);
676  }
677  return winfo.msg;
678  }
void AddWaiter(WaiterInfo *info)
virtual void SendMessage(const Variant &msg)=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CPN::RemoteContextClient::RequireRemote ( )
virtual

Lets the kernel know that this context type requires remote activity. This overrides the kernel option for remote activity. Default value is false.

Returns
true or false

Reimplemented from CPN::Context.

Definition at line 556 of file RemoteContextClient.cc.

556  {
557  return true;
558  }
void CPN::RemoteContextClient::SendCreateNode ( CPN::Key_t  kernelkey,
const CPN::NodeAttr attr 
)
virtual

Tell a given kernel that it needs to create a node.

Parameters
kernelkeythe id of the kernel
attrthe node attribute
Exceptions
ShutdownException

Implements CPN::Context.

Definition at line 193 of file RemoteContextClient.cc.

References CPN::NodeAttr::GetKernel(), CPN::NodeAttr::GetKey(), CPN::NodeAttr::GetName(), CPN::NodeAttr::GetParams(), CPN::NodeAttr::GetTypeName(), InternalCheckTerminated(), lock, CPN::RCTXMT_CREATE_NODE, and SendMessage().

193  {
196  Variant msg(Variant::MapType);
197  msg["msgtype"] = "kernel";
198  msg["type"] = RCTXMT_CREATE_NODE;
199  msg["kernelkey"] = kernelkey;
200  Variant nodeattr;
201  nodeattr["kernelkey"] = kernelkey;
202  nodeattr["kernel"] = attr.GetKernel();
203  nodeattr["name"] = attr.GetName();
204  nodeattr["nodetype"] = attr.GetTypeName();
205  const std::map<std::string, std::string> &params = attr.GetParams();
206  for (std::map<std::string, std::string>::const_iterator i = params.begin(),
207  e = params.end(); i != e; ++i) {
208  nodeattr["param"][i->first] = i->second;
209  }
210  nodeattr["key"] = attr.GetKey();
211  msg["nodeattr"] = nodeattr;
212  SendMessage(msg);
213  }
Key_t GetKey() const
Definition: NodeAttr.h:116
const std::map< std::string, std::string > & GetParams() const
Definition: NodeAttr.h:114
virtual void SendMessage(const Variant &msg)=0
const std::string & GetName() const
Definition: NodeAttr.h:110
const std::string & GetTypeName() const
Definition: NodeAttr.h:112
const std::string & GetKernel() const
Definition: NodeAttr.h:107

+ Here is the call graph for this function:

void CPN::RemoteContextClient::SendCreateQueue ( CPN::Key_t  kernelkey,
const CPN::SimpleQueueAttr attr 
)
virtual

Tell a given kernel that it needs to create a queue.

Parameters
kernelkeythe id of the kernel
attrthe queue attribute
Exceptions
ShutdownException

Implements CPN::Context.

Definition at line 187 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_CREATE_QUEUE, and SendQueueMsg().

187  {
190  SendQueueMsg(kernelkey, RCTXMT_CREATE_QUEUE, attr);
191  }
void SendQueueMsg(CPN::Key_t kernelkey, RCTXMT_t msgtype, const CPN::SimpleQueueAttr &attr)

+ Here is the call graph for this function:

void CPN::RemoteContextClient::SendCreateReader ( CPN::Key_t  kernelkey,
const CPN::SimpleQueueAttr attr 
)
virtual

Tell a given kernel that it needs to create a queue read end.

Parameters
kernelkeythe id of the kernel
attrthe queue attribute
Exceptions
ShutdownException

Implements CPN::Context.

Definition at line 181 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_CREATE_READER, and SendQueueMsg().

181  {
184  SendQueueMsg(kernelkey, RCTXMT_CREATE_READER, attr);
185  }
void SendQueueMsg(CPN::Key_t kernelkey, RCTXMT_t msgtype, const CPN::SimpleQueueAttr &attr)

+ Here is the call graph for this function:

void CPN::RemoteContextClient::SendCreateWriter ( CPN::Key_t  kernelkey,
const CPN::SimpleQueueAttr attr 
)
virtual

Tell a given kernel that it needs to create a queue write end.

Parameters
kernelkeythe id of the kernel
attrthe queue attribute
Exceptions
ShutdownException

Implements CPN::Context.

Definition at line 175 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_CREATE_WRITER, and SendQueueMsg().

175  {
178  SendQueueMsg(kernelkey, RCTXMT_CREATE_WRITER, attr);
179  }
void SendQueueMsg(CPN::Key_t kernelkey, RCTXMT_t msgtype, const CPN::SimpleQueueAttr &attr)

+ Here is the call graph for this function:

virtual void CPN::RemoteContextClient::SendMessage ( const Variant &  msg)
protectedpure virtual

Called by the functions to send a message to the RemoteContextServer.

Parameters
msgthe message

Implemented in CPN::RemoteContext.

Referenced by ConnectEndpoints(), Log(), RemoteCall(), SendCreateNode(), SendQueueMsg(), SignalKernelEnd(), SignalKernelStart(), SignalNodeEnd(), SignalNodeStart(), and Terminate().

+ Here is the caller graph for this function:

void CPN::RemoteContextClient::SendQueueMsg ( CPN::Key_t  kernelkey,
RCTXMT_t  msgtype,
const CPN::SimpleQueueAttr attr 
)
private

Definition at line 229 of file RemoteContextClient.cc.

References CPN::SimpleQueueAttr::GetAlpha(), CPN::SimpleQueueAttr::GetDatatype(), CPN::SimpleQueueAttr::GetHint(), CPN::SimpleQueueAttr::GetLength(), CPN::SimpleQueueAttr::GetMaxThreshold(), CPN::SimpleQueueAttr::GetMaxWriteThreshold(), CPN::SimpleQueueAttr::GetNumChannels(), CPN::SimpleQueueAttr::GetReaderKey(), CPN::SimpleQueueAttr::GetReaderNodeKey(), CPN::SimpleQueueAttr::GetWriterKey(), CPN::SimpleQueueAttr::GetWriterNodeKey(), and SendMessage().

Referenced by SendCreateQueue(), SendCreateReader(), and SendCreateWriter().

229  {
230  Variant msg(Variant::MapType);
231  msg["msgtype"] = "kernel";
232  msg["type"] = msgtype;
233  msg["kernelkey"] = kernelkey;
234  Variant queueattr;
235  queueattr["queuehint"] = attr.GetHint();
236  queueattr["datatype"] = attr.GetDatatype();
237  queueattr["queueLength"] = attr.GetLength();
238  queueattr["maxThreshold"] = attr.GetMaxThreshold();
239  queueattr["numChannels"] = attr.GetNumChannels();
240  queueattr["readerkey"] = attr.GetReaderKey();
241  queueattr["writerkey"] = attr.GetWriterKey();
242  queueattr["readernodekey"] = attr.GetReaderNodeKey();
243  queueattr["writernodekey"] = attr.GetWriterNodeKey();
244  queueattr["alpha"] = attr.GetAlpha();
245  queueattr["maxwritethreshold"] = attr.GetMaxWriteThreshold();
246  msg["queueattr"] = queueattr;
247  SendMessage(msg);
248  }
unsigned GetLength() const
Definition: QueueAttr.h:325
unsigned GetNumChannels() const
Definition: QueueAttr.h:327
Key_t GetWriterKey() const
Definition: QueueAttr.h:323
double GetAlpha() const
Definition: QueueAttr.h:330
unsigned GetMaxThreshold() const
Definition: QueueAttr.h:326
Key_t GetReaderKey() const
Definition: QueueAttr.h:324
virtual void SendMessage(const Variant &msg)=0
Key_t GetWriterNodeKey() const
Definition: QueueAttr.h:321
const std::string & GetDatatype() const
Definition: QueueAttr.h:329
unsigned GetMaxWriteThreshold() const
Definition: QueueAttr.h:331
Key_t GetReaderNodeKey() const
Definition: QueueAttr.h:322
std::string GetHint() const
Definition: QueueAttr.h:328

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Key_t CPN::RemoteContextClient::SetupKernel ( const std::string &  name,
const std::string &  hostname,
const std::string &  servname,
CPN::KernelBase kernel 
)
virtual

Called by the Kernel when it has successfully set it self up. This gives the Context a way to notify the Kernel of events and lets other Kernels look up the connection information for this Kernel.

Parameters
namethe kernel name
hostnamethe hostname to use to connect to this kernel
servnamethe service name the kernel is listening on
kernelcallback reference
Returns
the unique key for the new kernel
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 66 of file RemoteContextClient.cc.

References InternalCheckTerminated(), kernels, lock, CPN::RCTXMT_SETUP_KERNEL, and RemoteCall().

67  {
70  if (!kernel) { throw std::invalid_argument("Must have non null Kernel."); }
71  Variant msg(Variant::MapType);
72  msg["type"] = RCTXMT_SETUP_KERNEL;
73  msg["name"] = name;
74  msg["hostname"] = hostname;
75  msg["servname"] = servname;
76  Variant reply = RemoteCall(msg);
77  if (!reply.Get("success", false).IsTrue()) {
78  throw std::invalid_argument("Cannot create two kernels with the same name");
79  }
80  Key_t key = reply["kernelinfo"]["key"].AsNumber<Key_t>();
81  kernels.insert(std::make_pair(key, kernel));
82  return key;
83  }
Variant RemoteCall(Variant msg)
uint64_t Key_t
Definition: common.h:79

+ Here is the call graph for this function:

virtual CPN::Key_t CPN::RemoteContextClient::SetupKernel ( const std::string &  name,
KernelBase kernel 
)
inlinevirtual

Called by the kernel when it is not in remote mode.

Parameters
namethe kernel name
kernelcallback reference
Returns
the unique key for the new kernel

Implements CPN::Context.

Definition at line 58 of file RemoteContextClient.h.

References ASSERT.

58 { ASSERT(false, "RemoteContextClient requires remote operation is turned on."); }
#define ASSERT(exp,...)
void CPN::RemoteContextClient::SignalKernelEnd ( CPN::Key_t  kernelkey)
virtual

Signal to the Context that the given kernel is dead.

Parameters
kernelkeyid of the kernel that died
Exceptions
std::invalid_argument

Implements CPN::Context.

Definition at line 126 of file RemoteContextClient.cc.

References kernels, lock, CPN::RCTXMT_SIGNAL_KERNEL_END, and SendMessage().

126  {
128  Variant msg(Variant::MapType);
129  msg["type"] = RCTXMT_SIGNAL_KERNEL_END;
130  msg["key"] = kernelkey;
131  SendMessage(msg);
132  kernels.erase(kernelkey);
133  }
virtual void SendMessage(const Variant &msg)=0

+ Here is the call graph for this function:

void CPN::RemoteContextClient::SignalKernelStart ( CPN::Key_t  kernelkey)
virtual

Signal to the context that the given kernel has started.

Parameters
kernelkeythe id for the kernel
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 166 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_SIGNAL_KERNEL_START, and SendMessage().

166  {
169  Variant msg(Variant::MapType);
170  msg["key"] = kernelkey;
171  msg["type"] = RCTXMT_SIGNAL_KERNEL_START;
172  SendMessage(msg);
173  }
virtual void SendMessage(const Variant &msg)=0

+ Here is the call graph for this function:

void CPN::RemoteContextClient::SignalNodeEnd ( CPN::Key_t  nodekey)
virtual

Called by the node cleanup routine to indicate that the node has ended.

Parameters
nodekeythe unique key for the node
Exceptions
std::invalid_argument

Implements CPN::Context.

Definition at line 315 of file RemoteContextClient.cc.

References lock, CPN::RCTXMT_SIGNAL_NODE_END, and SendMessage().

315  {
317  Variant msg(Variant::MapType);
318  msg["type"] = RCTXMT_SIGNAL_NODE_END;
319  msg["key"] = nodekey;
320  SendMessage(msg);
321  }
virtual void SendMessage(const Variant &msg)=0

+ Here is the call graph for this function:

void CPN::RemoteContextClient::SignalNodeStart ( CPN::Key_t  nodekey)
virtual

Called by the node startup routine to indicate that the node has started.

Parameters
nodekeythe unique key for the node
Exceptions
ShutdownException
std::invalid_argument

Implements CPN::Context.

Definition at line 306 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, CPN::RCTXMT_SIGNAL_NODE_START, and SendMessage().

306  {
309  Variant msg(Variant::MapType);
310  msg["type"] = RCTXMT_SIGNAL_NODE_START;
311  msg["key"] = nodekey;
312  SendMessage(msg);
313  }
virtual void SendMessage(const Variant &msg)=0

+ Here is the call graph for this function:

void CPN::RemoteContextClient::Terminate ( )
virtual

Signal to the Context that the network is terminating. After this call most methods will throw a ShutdownException.

Implements CPN::Context.

Definition at line 504 of file RemoteContextClient.cc.

References InternalTerminate(), lock, CPN::RCTXMT_TERMINATE, SendMessage(), and shutdown.

Referenced by CPN::RemoteContext::EntryPoint().

504  {
506  if (!shutdown) {
508  Variant msg(Variant::MapType);
509  msg["type"] = RCTXMT_TERMINATE;
510  SendMessage(msg);
511  }
512  }
virtual void SendMessage(const Variant &msg)=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void * CPN::RemoteContextClient::TerminateThread ( )
private

Definition at line 514 of file RemoteContextClient.cc.

References kernels, and lock.

Referenced by InternalTerminate().

514  {
515  KernelMap mapcopy;
516  {
518  mapcopy = kernels;
519  }
520  KernelMap::iterator itr, end;
521  itr = mapcopy.begin();
522  end = mapcopy.end();
523  while (itr != end) {
524  itr->second->NotifyTerminate();
525  ++itr;
526  }
527  return 0;
528  }
std::map< CPN::Key_t, CPN::KernelBase * > KernelMap

+ Here is the caller graph for this function:

void CPN::RemoteContextClient::WaitForAllNodeEnd ( )
virtual

Convenience method which waits until there are no nodes running. If no node have started then this will return immediately.

Exceptions
ShutdownException

Implements CPN::Context.

Definition at line 391 of file RemoteContextClient.cc.

References ASSERT, lock, NewGenericWaiter(), CPN::RCTXMT_GET_NUM_NODE_LIVE, RemoteCall(), and shutdown.

391  {
393  if (shutdown) { return; }
395  Variant msg(Variant::MapType);
396  msg["type"] = RCTXMT_GET_NUM_NODE_LIVE;
397  Variant reply;
398  try {
399  reply = RemoteCall(msg);
400  } catch (const ShutdownException &e) {
401  return;
402  }
403  ASSERT(reply.Get("success", false).IsTrue(), "msg: %s", libvariant::SerializeJSON(reply).c_str());
404  if (reply["numlivenodes"].AsUnsigned() == 0) {
405  return;
406  }
407  while (true) {
408  if (genwait->messages.empty()) {
409  genwait->cond.Wait(lock);
410  if (shutdown) { return; }
411  } else {
412  Variant msg = genwait->messages.front();
413  genwait->messages.pop_front();
414  if (msg.Get("numlivenodes", -1).AsUnsigned() == 0) {
415  return;
416  }
417  }
418  }
419  }
Variant RemoteCall(Variant msg)
GenericWaiterPtr NewGenericWaiter()
shared_ptr< GenericWaiter > GenericWaiterPtr
#define ASSERT(exp,...)

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::WaitForKernelStart ( const std::string &  kernel)
virtual

Does not return until the given kernel has started.

Parameters
kernelthe name of the kernel (the key may not be known yet)
Exceptions
ShutdownException

Implements CPN::Context.

Definition at line 135 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, NewGenericWaiter(), CPN::RCTXMT_GET_KERNEL_INFO, and RemoteCall().

135  {
139  Variant msg(Variant::MapType);
140  msg["type"] = RCTXMT_GET_KERNEL_INFO;
141  msg["name"] = kernel;
142  Variant reply = RemoteCall(msg);
143  if (reply.Get("success", false).IsTrue()) {
144  Variant kernelinfo = reply["kernelinfo"];
145  if (kernelinfo.Get("live", false).IsTrue()) {
146  return kernelinfo["key"].AsNumber<Key_t>();
147  }
148  }
149  while (true) {
150  if (genwait->messages.empty()) {
151  genwait->cond.Wait(lock);
153  } else {
154  Variant msg = genwait->messages.front();
155  genwait->messages.pop_front();
156  if (msg.Contains("kernelinfo")) {
157  Variant kernelinfo = msg["kernelinfo"];
158  if (kernelinfo["name"].AsString() == kernel && kernelinfo["live"].IsTrue()) {
159  return kernelinfo["key"].AsNumber<Key_t>();
160  }
161  }
162  }
163  }
164  }
Variant RemoteCall(Variant msg)
GenericWaiterPtr NewGenericWaiter()
uint64_t Key_t
Definition: common.h:79
shared_ptr< GenericWaiter > GenericWaiterPtr

+ Here is the call graph for this function:

void CPN::RemoteContextClient::WaitForNodeEnd ( const std::string &  nodename)
virtual

Waits for the given node to signal end.

Parameters
nodenamethe name of the node
Exceptions
ShutdownException

Implements CPN::Context.

Definition at line 355 of file RemoteContextClient.cc.

References lock, NewGenericWaiter(), CPN::RCTXMT_GET_NODE_INFO, RemoteCall(), and shutdown.

355  {
357  if (shutdown) { return; }
359 
360  Variant msg(Variant::MapType);
361  msg["type"] = RCTXMT_GET_NODE_INFO;
362  msg["name"] = nodename;
363  Variant reply;
364  try {
365  reply = RemoteCall(msg);
366  } catch (const ShutdownException &e) {
367  return;
368  }
369  if (reply.Get("success", false).IsTrue()) {
370  if (reply["nodeinfo"]["dead"].IsTrue()) {
371  return;
372  }
373  }
374  while (true) {
375  if (genwait->messages.empty()) {
376  genwait->cond.Wait(lock);
377  if (shutdown) { return; }
378  } else {
379  Variant msg = genwait->messages.front();
380  genwait->messages.pop_front();
381  if (msg.Contains("nodeinfo")) {
382  Variant nodeinfo = msg["nodeinfo"];
383  if (nodeinfo["dead"].IsTrue() && nodeinfo["name"].AsString() == nodename) {
384  return;
385  }
386  }
387  }
388  }
389  }
Variant RemoteCall(Variant msg)
GenericWaiterPtr NewGenericWaiter()
shared_ptr< GenericWaiter > GenericWaiterPtr

+ Here is the call graph for this function:

Key_t CPN::RemoteContextClient::WaitForNodeStart ( const std::string &  nodename)
virtual

Waits until the node starts and returns the key, if the node is already started returns the key.

Parameters
nodenamethe name of the node to wait for
Returns
the key for the node
Exceptions
ShutdownException

Implements CPN::Context.

Definition at line 323 of file RemoteContextClient.cc.

References InternalCheckTerminated(), lock, NewGenericWaiter(), CPN::RCTXMT_GET_NODE_INFO, and RemoteCall().

323  {
327  Variant msg(Variant::MapType);
328  msg["type"] = RCTXMT_GET_NODE_INFO;
329  msg["name"] = nodename;
330  Variant reply = RemoteCall(msg);
331 
332  if (reply.Get("success", false).IsTrue()) {
333  Variant nodeinfo = reply["nodeinfo"];
334  if (nodeinfo["started"].IsTrue()) {
335  return nodeinfo["key"].AsNumber<Key_t>();
336  }
337  }
338  while (true) {
339  if (genwait->messages.empty()) {
340  genwait->cond.Wait(lock);
342  } else {
343  Variant msg = genwait->messages.front();
344  genwait->messages.pop_front();
345  if (msg.Contains("nodeinfo")) {
346  Variant nodeinfo = msg["nodeinfo"];
347  if (nodeinfo["started"].IsTrue() && nodeinfo["name"].AsString() == nodename) {
348  return nodeinfo["key"].AsNumber<Key_t>();
349  }
350  }
351  }
352  }
353  }
Variant RemoteCall(Variant msg)
GenericWaiterPtr NewGenericWaiter()
uint64_t Key_t
Definition: common.h:79
shared_ptr< GenericWaiter > GenericWaiterPtr

+ Here is the call graph for this function:

Member Data Documentation

WaiterMap CPN::RemoteContextClient::callwaiters
private

Definition at line 155 of file RemoteContextClient.h.

Referenced by AddWaiter(), DispatchMessage(), and InternalTerminate().

KernelMap CPN::RemoteContextClient::kernels
private
PthreadMutex CPN::RemoteContextClient::lock
mutableprotected
int CPN::RemoteContextClient::loglevel
private

Definition at line 162 of file RemoteContextClient.h.

Referenced by Log(), and LogLevel().

bool CPN::RemoteContextClient::shutdown
private
auto_ptr<Pthread> CPN::RemoteContextClient::terminateThread
private

Definition at line 153 of file RemoteContextClient.h.

Referenced by InternalTerminate(), and ~RemoteContextClient().

unsigned CPN::RemoteContextClient::trancounter
private

Definition at line 160 of file RemoteContextClient.h.

Referenced by NewTranID().

WaiterList CPN::RemoteContextClient::waiters
private

Definition at line 157 of file RemoteContextClient.h.

Referenced by DispatchMessage(), InternalTerminate(), and NewGenericWaiter().


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