CPN
Computational Process Networks
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
CPN::RemoteContext Class Reference

#include <RemoteContext.h>

+ Inheritance diagram for CPN::RemoteContext:
+ Collaboration diagram for CPN::RemoteContext:

Public Member Functions

 RemoteContext (const SocketAddress &addr)
 
 RemoteContext (const SockAddrList &addrs)
 
 RemoteContext (int fd)
 
 ~RemoteContext ()
 
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

void SendMessage (const Variant &msg)
 
void * EntryPoint ()
 

Protected Attributes

PthreadMutex lock
 

Private Member Functions

void EndWrite ()
 
bool IsEndWrite ()
 

Private Attributes

std::auto_ptr< Pthreadthread
 
SocketHandle sock
 
bool endwrite
 

Detailed Description

An implementation for the RemoteContextClient that is paired with RemoteContextDaemon.

Definition at line 37 of file RemoteContext.h.

Constructor & Destructor Documentation

CPN::RemoteContext::RemoteContext ( const SocketAddress addr)

Definition at line 33 of file RemoteContext.cc.

References SocketHandle::Connect(), CreatePthreadFunctional(), EntryPoint(), SocketHandle::SetNoDelay(), sock, and thread.

34  : endwrite(false)
35  {
37  sock.Connect(addr);
38  sock.SetNoDelay(true);
39  thread->Start();
40  }
SocketHandle sock
Definition: RemoteContext.h:50
std::auto_ptr< Pthread > thread
Definition: RemoteContext.h:49
void SetNoDelay(bool nodelay)
PthreadFunctional * CreatePthreadFunctional(T *obj, void *(T::*meth)(void))
void Connect(const SocketAddress &addr)
Create a new socket and try to connect to the given address.
Definition: SocketHandle.cc:48

+ Here is the call graph for this function:

CPN::RemoteContext::RemoteContext ( const SockAddrList addrs)

Definition at line 42 of file RemoteContext.cc.

References SocketHandle::Connect(), CreatePthreadFunctional(), EntryPoint(), SocketHandle::SetNoDelay(), sock, and thread.

43  : endwrite(false)
44  {
46  sock.Connect(addrs);
47  sock.SetNoDelay(true);
48  thread->Start();
49  }
SocketHandle sock
Definition: RemoteContext.h:50
std::auto_ptr< Pthread > thread
Definition: RemoteContext.h:49
void SetNoDelay(bool nodelay)
PthreadFunctional * CreatePthreadFunctional(T *obj, void *(T::*meth)(void))
void Connect(const SocketAddress &addr)
Create a new socket and try to connect to the given address.
Definition: SocketHandle.cc:48

+ Here is the call graph for this function:

CPN::RemoteContext::RemoteContext ( int  fd)

Definition at line 51 of file RemoteContext.cc.

References CreatePthreadFunctional(), EntryPoint(), SocketHandle::SetNoDelay(), sock, and thread.

52  : sock(fd)
53  {
55  sock.SetNoDelay(true);
56  thread->Start();
57  }
SocketHandle sock
Definition: RemoteContext.h:50
std::auto_ptr< Pthread > thread
Definition: RemoteContext.h:49
void SetNoDelay(bool nodelay)
PthreadFunctional * CreatePthreadFunctional(T *obj, void *(T::*meth)(void))

+ Here is the call graph for this function:

CPN::RemoteContext::~RemoteContext ( )

Definition at line 59 of file RemoteContext.cc.

References EndWrite(), and thread.

59  {
60  EndWrite();
61  thread->Join();
62  }
std::auto_ptr< Pthread > thread
Definition: RemoteContext.h:49

+ Here is the call graph for this function:

Member Function Documentation

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 
)
virtualinherited

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_CONNECT_ENDPOINTS, and CPN::RemoteContextClient::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 
)
virtualinherited

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_CREATE_NODE_KEY, and CPN::RemoteContextClient::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)
inherited

Handle a message from the RemoteContextServer.

Parameters
msgthe message

Definition at line 580 of file RemoteContextClient.cc.

References ASSERT, CPN::RemoteContextClient::callwaiters, CPN::RemoteContextClient::InternalTerminate(), CPN::RemoteContextClient::kernels, CPN::RemoteContextClient::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 CPN::RemoteContextClient::waiters.

Referenced by 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:

void CPN::RemoteContext::EndWrite ( )
private

Definition at line 114 of file RemoteContext.cc.

References endwrite, CPN::RemoteContextClient::lock, SocketHandle::ShutdownWrite(), and sock.

Referenced by ~RemoteContext().

114  {
116  endwrite = true;
118  }
SocketHandle sock
Definition: RemoteContext.h:50
void ShutdownWrite()
Shutdown the write end of this socket. Any future attempt to write to this socket will fail...

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void * CPN::RemoteContext::EntryPoint ( )
protected

Definition at line 76 of file RemoteContext.cc.

References FileHandle::Close(), CPN::RemoteContextClient::DispatchMessage(), FileHandle::Eof(), ErrnoException::Error(), FileHandle::Good(), FileHandle::Poll(), FileHandle::Readable(), SocketHandle::Recv(), sock, CPN::RemoteContextClient::Terminate(), and ErrnoException::what().

Referenced by RemoteContext().

76  {
77  std::vector<char> buf(4*1024);
78  unsigned num = 0;
79  try {
80  sock.Readable(false);
81  sock.Poll(-1);
82  while (sock.Good()) {
83  if (buf.size() - num <= 0) {
84  buf.resize(buf.size()*2);
85  }
86  unsigned numread = sock.Recv(&buf[num], buf.size() - num, false);
87  if (numread == 0) {
88  if (sock.Eof()) {
89  Terminate();
90  return 0;
91  }
92  sock.Poll(-1);
93  } else {
94  num += numread;
95  char *end = (char*)memchr(&buf[0], 0, num);
96  while (end != 0) {
97  Variant v = libvariant::DeserializeJSON(&buf[0]);
98  DispatchMessage(v);
99  end += 1;
100  num -= (end - &buf[0]);
101  memmove(&buf[0], end, num);
102  end = (char*)memchr(&buf[0], 0, num);
103  }
104  }
105  }
106  } catch (const ErrnoException &e) {
107  fprintf(stderr, "RemoteContext: Uncaught errno exception (%d): %s\n", e.Error(), e.what());
108  Terminate();
109  }
110  sock.Close();
111  return 0;
112  }
SocketHandle sock
Definition: RemoteContext.h:50
unsigned Recv(void *ptr, unsigned len, bool block)
void DispatchMessage(const Variant &msg)
virtual void Terminate()
Signal to the Context that the network is terminating. After this call most methods will throw a Shut...
static int Poll(IteratorRef< FileHandle * > begin, IteratorRef< FileHandle * > end, double timeout)
poll a list of FileHandles for any activity and call the appropriate On method.
Definition: FileHandle.cc:34
void Close()
Close the file and reset the internal state.
Definition: FileHandle.cc:146
bool Readable(bool r)
Set that the file is currently readable or not.
Definition: FileHandle.h:86
virtual const char * what() const
bool Good() const
Convenience method for testing if the file this FileHandle has is open and not at end of file...
Definition: FileHandle.h:125
bool Eof() const
Definition: FileHandle.h:115
int Error() const

+ 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 
)
virtualinherited

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 CPN::RemoteContextClient::GetCreateEndpointKey(), CPN::RemoteContextClient::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 
)
virtualinherited
See Also
GetCreateReaderKey

Implements CPN::Context.

Definition at line 458 of file RemoteContextClient.cc.

References CPN::RemoteContextClient::GetCreateEndpointKey(), CPN::RemoteContextClient::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:

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

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_GET_KERNEL_INFO, and CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_GET_KERNEL_INFO, and CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_GET_KERNEL_INFO, and CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_GET_NODE_INFO, and CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_GET_NODE_INFO, and CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_GET_NODE_INFO, and CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::GetEndpointInfo(), CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::GetEndpointInfo(), CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::GetEndpointInfo(), CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::GetEndpointInfo(), CPN::RemoteContextClient::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)
virtualinherited
See Also
GetReaderKernel

Implements CPN::Context.

Definition at line 469 of file RemoteContextClient.cc.

References CPN::RemoteContextClient::GetEndpointInfo(), CPN::RemoteContextClient::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)
virtualinherited
See Also
GetReaderName

Implements CPN::Context.

Definition at line 475 of file RemoteContextClient.cc.

References CPN::RemoteContextClient::GetEndpointInfo(), CPN::RemoteContextClient::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)
virtualinherited
See Also
GetReaderNode

Implements CPN::Context.

Definition at line 463 of file RemoteContextClient.cc.

References CPN::RemoteContextClient::GetEndpointInfo(), CPN::RemoteContextClient::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)
virtualinherited
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 CPN::RemoteContextClient::GetEndpointInfo(), CPN::RemoteContextClient::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:

bool CPN::RemoteContext::IsEndWrite ( )
private

Definition at line 120 of file RemoteContext.cc.

References endwrite, and CPN::RemoteContextClient::lock.

120  {
122  return endwrite;
123  }
bool CPN::RemoteContextClient::IsTerminated ( )
virtualinherited
Returns
true if Terminate has been called

Implements CPN::Context.

Definition at line 551 of file RemoteContextClient.cc.

References CPN::RemoteContextClient::lock, and CPN::RemoteContextClient::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 
)
virtualinherited

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 CPN::RemoteContextClient::lock, CPN::RemoteContextClient::loglevel, CPN::RCTXMT_LOG, and CPN::RemoteContextClient::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
virtualinherited
Returns
the current log level

Implements LoggerOutput.

Definition at line 46 of file RemoteContextClient.cc.

References CPN::RemoteContextClient::lock, and CPN::RemoteContextClient::loglevel.

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

Implements LoggerOutput.

Definition at line 51 of file RemoteContextClient.cc.

References CPN::RemoteContextClient::lock, and CPN::RemoteContextClient::loglevel.

bool CPN::RemoteContextClient::RequireRemote ( )
virtualinherited

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 
)
virtualinherited

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(), CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_CREATE_NODE, and CPN::RemoteContextClient::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 
)
virtualinherited

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_CREATE_QUEUE, and CPN::RemoteContextClient::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 
)
virtualinherited

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_CREATE_READER, and CPN::RemoteContextClient::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 
)
virtualinherited

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_CREATE_WRITER, and CPN::RemoteContextClient::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:

void CPN::RemoteContext::SendMessage ( const Variant &  msg)
protectedvirtual

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

Parameters
msgthe message

Implements CPN::RemoteContextClient.

Definition at line 64 of file RemoteContext.cc.

References FileHandle::Closed(), endwrite, sock, and FileHandle::Write().

64  {
65  // We have the lock
66  if (!sock.Closed() && !endwrite) {
67  std::string message = libvariant::SerializeJSON(msg);
68  //printf("<<< %s\n", message.c_str());
69  unsigned numwritten = 0;
70  while (numwritten < message.size() + 1) {
71  numwritten += sock.Write(message.c_str() + numwritten, (message.size() + 1) - numwritten);
72  }
73  }
74  }
SocketHandle sock
Definition: RemoteContext.h:50
bool Closed() const
Definition: FileHandle.h:128
unsigned Write(const void *ptr, unsigned len)
Write data to the file descriptor.
Definition: FileHandle.cc:225

+ Here is the call graph for this function:

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

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::kernels, CPN::RemoteContextClient::lock, CPN::RCTXMT_SETUP_KERNEL, and CPN::RemoteContextClient::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 
)
inlinevirtualinherited

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)
virtualinherited

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 CPN::RemoteContextClient::kernels, CPN::RemoteContextClient::lock, CPN::RCTXMT_SIGNAL_KERNEL_END, and CPN::RemoteContextClient::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)
virtualinherited

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_SIGNAL_KERNEL_START, and CPN::RemoteContextClient::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)
virtualinherited

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 CPN::RemoteContextClient::lock, CPN::RCTXMT_SIGNAL_NODE_END, and CPN::RemoteContextClient::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)
virtualinherited

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RCTXMT_SIGNAL_NODE_START, and CPN::RemoteContextClient::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 ( )
virtualinherited

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 CPN::RemoteContextClient::InternalTerminate(), CPN::RemoteContextClient::lock, CPN::RCTXMT_TERMINATE, CPN::RemoteContextClient::SendMessage(), and CPN::RemoteContextClient::shutdown.

Referenced by 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::WaitForAllNodeEnd ( )
virtualinherited

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, CPN::RemoteContextClient::lock, CPN::RemoteContextClient::NewGenericWaiter(), CPN::RCTXMT_GET_NUM_NODE_LIVE, CPN::RemoteContextClient::RemoteCall(), and CPN::RemoteContextClient::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)
virtualinherited

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RemoteContextClient::NewGenericWaiter(), CPN::RCTXMT_GET_KERNEL_INFO, and CPN::RemoteContextClient::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)
virtualinherited

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 CPN::RemoteContextClient::lock, CPN::RemoteContextClient::NewGenericWaiter(), CPN::RCTXMT_GET_NODE_INFO, CPN::RemoteContextClient::RemoteCall(), and CPN::RemoteContextClient::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)
virtualinherited

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 CPN::RemoteContextClient::InternalCheckTerminated(), CPN::RemoteContextClient::lock, CPN::RemoteContextClient::NewGenericWaiter(), CPN::RCTXMT_GET_NODE_INFO, and CPN::RemoteContextClient::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

bool CPN::RemoteContext::endwrite
private

Definition at line 51 of file RemoteContext.h.

Referenced by EndWrite(), IsEndWrite(), and SendMessage().

PthreadMutex CPN::RemoteContextClient::lock
mutableprotectedinherited

Definition at line 116 of file RemoteContextClient.h.

Referenced by CPN::RemoteContextClient::ConnectEndpoints(), CPN::RemoteContextClient::CreateNodeKey(), CPN::RemoteContextClient::DispatchMessage(), EndWrite(), CPN::RemoteContextClient::GetCreateReaderKey(), CPN::RemoteContextClient::GetCreateWriterKey(), CPN::RemoteContextClient::GetKernelConnectionInfo(), CPN::RemoteContextClient::GetKernelKey(), CPN::RemoteContextClient::GetKernelName(), CPN::RemoteContextClient::GetNodeKernel(), CPN::RemoteContextClient::GetNodeKey(), CPN::RemoteContextClient::GetNodeName(), CPN::RemoteContextClient::GetReaderKernel(), CPN::RemoteContextClient::GetReaderName(), CPN::RemoteContextClient::GetReaderNode(), CPN::RemoteContextClient::GetReadersWriter(), CPN::RemoteContextClient::GetWriterKernel(), CPN::RemoteContextClient::GetWriterName(), CPN::RemoteContextClient::GetWriterNode(), CPN::RemoteContextClient::GetWritersReader(), IsEndWrite(), CPN::RemoteContextClient::IsTerminated(), CPN::RemoteContextClient::Log(), CPN::RemoteContextClient::LogLevel(), CPN::RemoteContextClient::RemoteCall(), CPN::RemoteContextClient::SendCreateNode(), CPN::RemoteContextClient::SendCreateQueue(), CPN::RemoteContextClient::SendCreateReader(), CPN::RemoteContextClient::SendCreateWriter(), CPN::RemoteContextClient::SetupKernel(), CPN::RemoteContextClient::SignalKernelEnd(), CPN::RemoteContextClient::SignalKernelStart(), CPN::RemoteContextClient::SignalNodeEnd(), CPN::RemoteContextClient::SignalNodeStart(), CPN::RemoteContextClient::Terminate(), CPN::RemoteContextClient::TerminateThread(), CPN::RemoteContextClient::WaitForAllNodeEnd(), CPN::RemoteContextClient::WaitForKernelStart(), CPN::RemoteContextClient::WaitForNodeEnd(), and CPN::RemoteContextClient::WaitForNodeStart().

SocketHandle CPN::RemoteContext::sock
private

Definition at line 50 of file RemoteContext.h.

Referenced by EndWrite(), EntryPoint(), RemoteContext(), and SendMessage().

std::auto_ptr<Pthread> CPN::RemoteContext::thread
private

Definition at line 49 of file RemoteContext.h.

Referenced by RemoteContext(), and ~RemoteContext().


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