CPN
Computational Process Networks
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
CPN::Context Class Referenceabstract

The CPN::Context abstraction that holds all the global state for the process network. More...

#include <Context.h>

+ Inheritance diagram for CPN::Context:
+ Collaboration diagram for CPN::Context:

Public Member Functions

virtual ~Context ()
 
virtual Key_t SetupKernel (const std::string &name, const std::string &hostname, const std::string &servname, KernelBase *kernel)=0
 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 Key_t SetupKernel (const std::string &name, KernelBase *kernel)=0
 Called by the kernel when it is not in remote mode. More...
 
virtual Key_t GetKernelKey (const std::string &kernel)=0
 
virtual std::string GetKernelName (Key_t kernelkey)=0
 
virtual void GetKernelConnectionInfo (Key_t kernelkey, std::string &hostname, std::string &servname)=0
 obtain the connection information for the given kernel More...
 
virtual void SignalKernelEnd (Key_t kernelkey)=0
 Signal to the Context that the given kernel is dead. More...
 
virtual Key_t WaitForKernelStart (const std::string &kernel)=0
 Does not return until the given kernel has started. More...
 
virtual void SignalKernelStart (Key_t kernelkey)=0
 Signal to the context that the given kernel has started. More...
 
virtual void SendCreateWriter (Key_t kernelkey, const SimpleQueueAttr &attr)=0
 Tell a given kernel that it needs to create a queue write end. More...
 
virtual void SendCreateReader (Key_t kernelkey, const SimpleQueueAttr &attr)=0
 Tell a given kernel that it needs to create a queue read end. More...
 
virtual void SendCreateQueue (Key_t kernelkey, const SimpleQueueAttr &attr)=0
 Tell a given kernel that it needs to create a queue. More...
 
virtual void SendCreateNode (Key_t kernelkey, const NodeAttr &attr)=0
 Tell a given kernel that it needs to create a node. More...
 
virtual Key_t CreateNodeKey (Key_t kernelkey, const std::string &nodename)=0
 Tell the context to allocate a new node key and data structure for a node with nodename which is on kernelkey. More...
 
virtual Key_t GetNodeKey (const std::string &nodename)=0
 
virtual std::string GetNodeName (Key_t nodekey)=0
 
virtual Key_t GetNodeKernel (Key_t nodekey)=0
 
virtual void SignalNodeStart (Key_t nodekey)=0
 Called by the node startup routine to indicate that the node has started. More...
 
virtual void SignalNodeEnd (Key_t nodekey)=0
 Called by the node cleanup routine to indicate that the node has ended. More...
 
virtual Key_t WaitForNodeStart (const std::string &nodename)=0
 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)=0
 Waits for the given node to signal end. More...
 
virtual void WaitForAllNodeEnd ()=0
 Convenience method which waits until there are no nodes running. If no node have started then this will return immediately. More...
 
virtual Key_t GetCreateReaderKey (Key_t nodekey, const std::string &portname)=0
 Get the key associated with the given endpoint for the given node. Creates the information if it does not exist. More...
 
virtual Key_t GetReaderNode (Key_t portkey)=0
 
virtual Key_t GetReaderKernel (Key_t portkey)=0
 
virtual std::string GetReaderName (Key_t portkey)=0
 
virtual Key_t GetCreateWriterKey (Key_t nodekey, const std::string &portname)=0
 
virtual Key_t GetWriterNode (Key_t portkey)=0
 
virtual Key_t GetWriterKernel (Key_t portkey)=0
 
virtual std::string GetWriterName (Key_t portkey)=0
 
virtual void ConnectEndpoints (Key_t writerkey, Key_t readerkey, const std::string &qname)=0
 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 Key_t GetReadersWriter (Key_t readerkey)=0
 
virtual Key_t GetWritersReader (Key_t writerkey)=0
 
virtual void Terminate ()=0
 Signal to the Context that the network is terminating. After this call most methods will throw a ShutdownException. More...
 
virtual bool IsTerminated ()=0
 
void CheckTerminated ()
 Convenience method that checks IsTerminated and if so throws a ShutdownException. More...
 
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...
 
virtual unsigned CalculateGrowSize (unsigned currentsize, unsigned request)
 Calculate the new queue size when a queue needs to grow. More...
 
virtual int LogLevel () const =0
 
virtual int LogLevel (int level)=0
 
virtual void Log (int level, const std::string &msg)=0
 Log a message to this outputer. More...
 

Static Public Member Functions

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

Protected Member Functions

 Context ()
 

Detailed Description

The CPN::Context abstraction that holds all the global state for the process network.

All methods may through a CPN::ShutdownException.

Note that all key values should be unique across all objects. That is to say that even though a node and a kernel are of different types none of there keys should ever be equal.

Note that the only function here that should be called outside of the library (i.e. by the user of the library) are the log level functions the Get functions and the Wait functions and the Terminate functions.

Definition at line 47 of file Context.h.

Constructor & Destructor Documentation

CPN::Context::~Context ( )
virtual

Definition at line 37 of file Context.cc.

37  {
38  }
CPN::Context::Context ( )
protected

Definition at line 33 of file Context.cc.

34  {
35  }

Member Function Documentation

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

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

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

Exceptions
ShutdownException

Definition at line 44 of file Context.cc.

References IsTerminated().

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

+ Here is the call graph for this function:

virtual void CPN::Context::ConnectEndpoints ( Key_t  writerkey,
Key_t  readerkey,
const std::string &  qname 
)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual Key_t CPN::Context::CreateNodeKey ( Key_t  kernelkey,
const std::string &  nodename 
)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual Key_t CPN::Context::GetCreateReaderKey ( Key_t  nodekey,
const std::string &  portname 
)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual Key_t CPN::Context::GetCreateWriterKey ( Key_t  nodekey,
const std::string &  portname 
)
pure virtual
virtual void CPN::Context::GetKernelConnectionInfo ( Key_t  kernelkey,
std::string &  hostname,
std::string &  servname 
)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual Key_t CPN::Context::GetWriterKernel ( Key_t  portkey)
pure virtual
virtual std::string CPN::Context::GetWriterName ( Key_t  portkey)
pure virtual
virtual Key_t CPN::Context::GetWriterNode ( Key_t  portkey)
pure virtual
virtual Key_t CPN::Context::GetWritersReader ( Key_t  writerkey)
pure virtual
Parameters
writerkeya unique writer key
Returns
the reader key associated with this writer
Exceptions
ShutdownException
std::invalid_argument

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

Referenced by CheckTerminated().

+ Here is the caller graph for this function:

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

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:

virtual void LoggerOutput::Log ( int  level,
const std::string &  msg 
)
pure virtualinherited

Log a message to this outputer.

Parameters
levelthe level of this message
msgthe message

Implemented in LoggerStdOutput, Logger, CPN::LocalContext, and CPN::RemoteContextClient.

Referenced by Logger::Log().

+ Here is the caller graph for this function:

virtual int LoggerOutput::LogLevel ( ) const
pure virtualinherited
Returns
the current log level

Implemented in LoggerStdOutput, CPN::LocalContext, Logger, and CPN::RemoteContextClient.

Referenced by Logger::Logger().

+ Here is the caller graph for this function:

virtual int LoggerOutput::LogLevel ( int  level)
pure virtualinherited
Parameters
levelthe new log level
Returns
the new log level

Implemented in LoggerStdOutput, CPN::LocalContext, Logger, and CPN::RemoteContextClient.

bool CPN::Context::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 in CPN::RemoteContextClient.

Definition at line 40 of file Context.cc.

40  {
41  return false;
42  }
virtual void CPN::Context::SendCreateNode ( Key_t  kernelkey,
const NodeAttr attr 
)
pure virtual

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

Parameters
kernelkeythe id of the kernel
attrthe node attribute
Exceptions
ShutdownException

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

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

Parameters
kernelkeythe id of the kernel
attrthe queue attribute
Exceptions
ShutdownException

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual void CPN::Context::SendCreateReader ( Key_t  kernelkey,
const SimpleQueueAttr attr 
)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual void CPN::Context::SendCreateWriter ( Key_t  kernelkey,
const SimpleQueueAttr attr 
)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual Key_t CPN::Context::SetupKernel ( const std::string &  name,
const std::string &  hostname,
const std::string &  servname,
KernelBase kernel 
)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual Key_t CPN::Context::SetupKernel ( const std::string &  name,
KernelBase kernel 
)
pure virtual

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual void CPN::Context::SignalKernelEnd ( Key_t  kernelkey)
pure virtual

Signal to the Context that the given kernel is dead.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual void CPN::Context::SignalKernelStart ( Key_t  kernelkey)
pure virtual

Signal to the context that the given kernel has started.

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual void CPN::Context::SignalNodeEnd ( Key_t  nodekey)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual void CPN::Context::SignalNodeStart ( Key_t  nodekey)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual void CPN::Context::Terminate ( )
pure virtual

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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual void CPN::Context::WaitForAllNodeEnd ( )
pure virtual

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

Exceptions
ShutdownException

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual Key_t CPN::Context::WaitForKernelStart ( const std::string &  kernel)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

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

Waits for the given node to signal end.

Parameters
nodenamethe name of the node
Exceptions
ShutdownException

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.

virtual Key_t CPN::Context::WaitForNodeStart ( const std::string &  nodename)
pure 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

Implemented in CPN::LocalContext, and CPN::RemoteContextClient.


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