HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_Service Class Reference

#include <PDG_Service.h>

+ Inheritance diagram for PDG_Service:

Classes

struct  ClientInfo
 Service client array entry. More...
 

Public Types

enum  ServiceAcquireResult {
  eServiceAcquireSuccess, eServiceAcquireSuccessLocked, eServiceAcquireBusy, eServiceAcquireLocked,
  eServiceAcquireInvalidLock
}
 Enumeration of return codes from acquireClient. More...
 
- Public Types inherited from PDGT_TypeInstance< EnumType >
using BaseType = PDGT_BaseType< EnumType >
 

Public Member Functions

 PDG_Service (const PDG_BaseType *type, const PDGT_ValueArgs &extra_args, const UT_StringHolder &service_command, bool internal_service)
 
 ~PDG_Service () override
 
void setName (const UT_StringHolder &name)
 
const UT_StringHoldername () const
 
bool isInternal () const
 
void setPersistent (bool persistent)
 
bool isPersistent () const
 
bool hasErrors () const
 Returns true if the service has errors when starting. More...
 
void setAutoStart (bool auto_start)
 
bool isAutoStart () const
 
void setData (PY_PyObject *new_data)
 
PY_PyObjectdata ()
 
void setMqUrl (const UT_StringHolder &url)
 
const UT_StringHoldermqUrl () const
 
void setMqLogLevel (int log_level)
 
int mqLogLevel () const
 
void setMqPort (int mq_port)
 Sets/gets the port used by the MQ relay. More...
 
int mqPort () const
 
void setClientLogDir (const UT_StringHolder &log_dir)
 
const UT_StringHolderclientLogDir () const
 
void setMqLogDir (const UT_StringHolder &log_dir)
 Sets/gets the directory that the MQ relay writes its logs to. More...
 
const UT_StringHoldermqLogDir () const
 
void setClientLogType (PDG_ServiceLogType log_type)
 Sets how the service itself should log output. More...
 
PDG_ServiceLogType clientLogType () const
 
void setEnvVarNames (const UT_StringArray &env_var_names)
 
const UT_StringArrayenvVarNames () const
 
void setEnvVarValues (const UT_StringArray &env_var_values)
 
const UT_StringArrayenvVarValues () const
 
void setScheduler (const UT_StringHolder &name, const UT_StringHolder &context_name)
 
void clearScheduler ()
 
const UT_StringHolderschedulerName () const
 
const UT_StringHolderschedulerContextName () const
 
void setOwner (PDG_ServiceOwner owner)
 
PDG_ServiceOwner owner () const
 
void setState (PDG_ServiceState state)
 Sets/gets the current state of the service. More...
 
PDG_ServiceState state () const
 
void setCommand (const UT_StringHolder &command)
 
const UT_StringHoldercommand () const
 
void setPoolSize (int pool_size)
 
int poolSize () const
 
void setPort (int port)
 Sets/gets the connection port for the service itself. More...
 
int port () const
 
void setConnectionTimeout (int ms)
 Sets the service connection timeout in milliseconds. More...
 
int connectionTimeout () const
 
void setMemoryResetType (PDG_ServiceResetType memory_reset_type)
 Sets the memory limit and reset type for the service. More...
 
void setMemoryLimit (exint memory_limit)
 
PDG_ServiceResetType memoryResetType () const
 
exint memoryLimit () const
 
bool isStartingOrRunning () const
 Returns true if the service is start or is already running. More...
 
bool isStoppingOrStopped () const
 Returns true if the service is stopping, or has already stopped. More...
 
PDG_SchedulerserviceScheduler (UT_WorkBuffer &errors) const
 
UT_StringArray clientNames () const
 Queries the list of all active service client names. More...
 
UT_StringHolder clientName (int client_num) const
 
ClientInfoclient (const UT_StringHolder &name)
 Returns the service client info for a particular client. More...
 
ClientInfoaddPendingClient (const UT_StringHolder &server_address, int server_port, int client_num)
 
PDG_ServiceStartResult startService (UT_WorkBuffer &errors, bool background)
 
bool resetClient (UT_WorkBuffer &errors, const UT_StringHolder &client_name=UT_StringHolder::theEmptyString)
 
bool restartClient (UT_WorkBuffer &errors, const UT_StringHolder &client_name)
 
bool stopClient (UT_WorkBuffer &errors, const UT_StringHolder &client_name)
 
bool stopService (UT_WorkBuffer &errors, bool ignore_stopped)
 
bool cleanupService (UT_WorkBuffer &errors, bool stop_mq_server, bool wait_for_clients)
 
PDGN::PDGN_Message * executeWorkItem (UT_WorkBuffer &errors, const UT_StringHolder &client_name, const PDG_WorkItem *work_item)
 
PDGN::PDGN_Message * executeWorkItem (UT_WorkBuffer &errors, const UT_StringHolder &client_name, const PDG_WorkItem *work_item, const UT_WorkBuffer &script_buffer)
 
void startPollingClient ()
 
void stopPollingClient ()
 
const UT_StringHolderpollingClientName () const
 Returns the name of the polling client, if one exists. More...
 
bool hasPollingClient () const
 Returns true if the service has an active polling client. More...
 
PDGN::PDGN_PollingClientNNG * getPollingClient () const
 
void waitForClients ()
 
void incrementStartingClientsCount ()
 Increments the number of actively starting client. More...
 
UT_StringHolder getCommand (const char *server_address, int server_port, int client_num) const
 
void getCommand (UT_StringArray &command_tokens, const char *server_address, int server_port, int client_num) const
 
bool ping (int client_num, UT_WorkBuffer &errors) const
 
ServiceAcquireResult acquireClient (UT_StringHolder &client_name, PDG_WorkItemID item_lock)
 Acquires a client, which reserves it for the caller. More...
 
bool releaseClient (UT_WorkBuffer &errors, const UT_StringHolder &client_name, PDG_ServiceResetWhen reset_when, PDG_ServiceResetType reset_type, int64 memory_usage)
 Releases a client that was previously acquired, but does not unlock it. More...
 
bool unlockClient (PDG_WorkItemID item_lock, PDG_ServiceResetType reset_type, UT_WorkBuffer &errors)
 Unlocks a service client. More...
 
- Public Member Functions inherited from PDGT_TypeInstance< EnumType >
 PDGT_TypeInstance ()
 
 PDGT_TypeInstance (const PDGT_BaseType< EnumType > *base_type, const PDGT_ValueArgs &extra_args)
 
virtual ~PDGT_TypeInstance ()
 
virtual int64 getMemoryUsage (bool inclusive) const
 
virtual bool reloadInstance (UT_WorkBuffer &errors)
 
const BaseTypetype () const
 
const UT_StringHoldertypeName () const
 
const PDGT_ValueArgsextraArgs () const
 
bool compareType (const BaseType *other_type, bool deep=true) const
 
void setReloading (bool is_reloading)
 
bool isReloading () const
 

Static Public Attributes

static const UT_StringHolder theDataVersion
 Service data format version. More...
 

Additional Inherited Members

- Protected Attributes inherited from PDGT_TypeInstance< EnumType >
const BaseTypemyBaseType
 
PDGT_ValueArgs myExtraArgs
 
bool myReloading
 

Detailed Description

Definition at line 40 of file PDG_Service.h.

Member Enumeration Documentation

Enumeration of return codes from acquireClient.

Enumerator
eServiceAcquireSuccess 

A service client was successfully acquired.

eServiceAcquireSuccessLocked 

A service client was successfully acquired and locked.

eServiceAcquireBusy 

All service workers are already busy.

eServiceAcquireLocked 

The service worker is aleady in use by a different task with the same service lock id

eServiceAcquireInvalidLock 

The service lock is invalid – should never occur in practice.

Definition at line 47 of file PDG_Service.h.

Constructor & Destructor Documentation

PDG_Service::PDG_Service ( const PDG_BaseType type,
const PDGT_ValueArgs extra_args,
const UT_StringHolder service_command,
bool  internal_service 
)

Constructs a new service instance with a default pool size of 1, and no connection information.

PDG_Service::~PDG_Service ( )
override

Member Function Documentation

ServiceAcquireResult PDG_Service::acquireClient ( UT_StringHolder client_name,
PDG_WorkItemID  item_lock 
)

Acquires a client, which reserves it for the caller.

ClientInfo* PDG_Service::addPendingClient ( const UT_StringHolder server_address,
int  server_port,
int  client_num 
)

Adds a pending service client, which can be waiting on using waitForClients

bool PDG_Service::cleanupService ( UT_WorkBuffer errors,
bool  stop_mq_server,
bool  wait_for_clients 
)

Cleans up the clients in the service. This method is public so that schedulers can call it on services they manage.

void PDG_Service::clearScheduler ( )

Clears the scheduler information associated with a scheduler service

ClientInfo* PDG_Service::client ( const UT_StringHolder name)

Returns the service client info for a particular client.

const UT_StringHolder& PDG_Service::clientLogDir ( ) const
inline

Definition at line 201 of file PDG_Service.h.

PDG_ServiceLogType PDG_Service::clientLogType ( ) const
inline

Definition at line 213 of file PDG_Service.h.

UT_StringHolder PDG_Service::clientName ( int  client_num) const

Queries the name of a particular service client, using its client number

UT_StringArray PDG_Service::clientNames ( ) const

Queries the list of all active service client names.

const UT_StringHolder& PDG_Service::command ( ) const
inline

Definition at line 269 of file PDG_Service.h.

int PDG_Service::connectionTimeout ( ) const
inline

Definition at line 288 of file PDG_Service.h.

PY_PyObject* PDG_Service::data ( )
inline

Definition at line 174 of file PDG_Service.h.

const UT_StringArray& PDG_Service::envVarNames ( ) const
inline

Definition at line 221 of file PDG_Service.h.

const UT_StringArray& PDG_Service::envVarValues ( ) const
inline

Definition at line 229 of file PDG_Service.h.

PDGN::PDGN_Message* PDG_Service::executeWorkItem ( UT_WorkBuffer errors,
const UT_StringHolder client_name,
const PDG_WorkItem work_item 
)

Submits a work item to a service client asynchronously, and returns the pending message handle for the job.

PDGN::PDGN_Message* PDG_Service::executeWorkItem ( UT_WorkBuffer errors,
const UT_StringHolder client_name,
const PDG_WorkItem work_item,
const UT_WorkBuffer script_buffer 
)

Submits a work item to a service client asychronously, and returns the pending messae handle for the job. This variant of the method allows the caller to supply a custom script that will run instead of the standard job script or script data associated with the work item.

UT_StringHolder PDG_Service::getCommand ( const char *  server_address,
int  server_port,
int  client_num 
) const

Returns the command for the service client with the specified client number, as a string.

void PDG_Service::getCommand ( UT_StringArray command_tokens,
const char *  server_address,
int  server_port,
int  client_num 
) const

Returns the command for the service client with the specified client number, as an array of arguments

PDGN::PDGN_PollingClientNNG* PDG_Service::getPollingClient ( ) const
inline

Definition at line 412 of file PDG_Service.h.

bool PDG_Service::hasErrors ( ) const
inline

Returns true if the service has errors when starting.

Definition at line 161 of file PDG_Service.h.

bool PDG_Service::hasPollingClient ( ) const
inline

Returns true if the service has an active polling client.

Definition at line 407 of file PDG_Service.h.

void PDG_Service::incrementStartingClientsCount ( )

Increments the number of actively starting client.

bool PDG_Service::isAutoStart ( ) const
inline

Definition at line 168 of file PDG_Service.h.

bool PDG_Service::isInternal ( ) const
inline

Returns true if the service is internal to PDG. Internal services cannot be directly managed by users.

Definition at line 148 of file PDG_Service.h.

bool PDG_Service::isPersistent ( ) const
inline

Definition at line 157 of file PDG_Service.h.

bool PDG_Service::isStartingOrRunning ( ) const

Returns true if the service is start or is already running.

bool PDG_Service::isStoppingOrStopped ( ) const

Returns true if the service is stopping, or has already stopped.

exint PDG_Service::memoryLimit ( ) const
inline

Definition at line 304 of file PDG_Service.h.

PDG_ServiceResetType PDG_Service::memoryResetType ( ) const
inline

Definition at line 302 of file PDG_Service.h.

const UT_StringHolder& PDG_Service::mqLogDir ( ) const
inline

Definition at line 207 of file PDG_Service.h.

int PDG_Service::mqLogLevel ( ) const
inline

Definition at line 188 of file PDG_Service.h.

int PDG_Service::mqPort ( ) const
inline

Definition at line 194 of file PDG_Service.h.

const UT_StringHolder& PDG_Service::mqUrl ( ) const
inline

Definition at line 181 of file PDG_Service.h.

const UT_StringHolder& PDG_Service::name ( void  ) const
inline

Definition at line 143 of file PDG_Service.h.

PDG_ServiceOwner PDG_Service::owner ( ) const
inline

Definition at line 256 of file PDG_Service.h.

bool PDG_Service::ping ( int  client_num,
UT_WorkBuffer errors 
) const

Pings the specified client, and returns true if the client was reachable

const UT_StringHolder& PDG_Service::pollingClientName ( ) const

Returns the name of the polling client, if one exists.

int PDG_Service::poolSize ( ) const
inline

Definition at line 276 of file PDG_Service.h.

int PDG_Service::port ( ) const
inline

Definition at line 282 of file PDG_Service.h.

bool PDG_Service::releaseClient ( UT_WorkBuffer errors,
const UT_StringHolder client_name,
PDG_ServiceResetWhen  reset_when,
PDG_ServiceResetType  reset_type,
int64  memory_usage 
)

Releases a client that was previously acquired, but does not unlock it.

bool PDG_Service::resetClient ( UT_WorkBuffer errors,
const UT_StringHolder client_name = UT_StringHolder::theEmptyString 
)

Resets a specific service client, or all clients if empty string is passed in as the client_name

bool PDG_Service::restartClient ( UT_WorkBuffer errors,
const UT_StringHolder client_name 
)

Restarts a service client. If client_name is empty string all clients are restarted.

const UT_StringHolder& PDG_Service::schedulerContextName ( ) const
inline

Returns the name of the graph that owns the scheduler that created the service, if it's a scheduler service

Definition at line 249 of file PDG_Service.h.

const UT_StringHolder& PDG_Service::schedulerName ( ) const
inline

Returns the name of the scheduler associated with the service, if it's a scheduler service

Definition at line 244 of file PDG_Service.h.

PDG_Scheduler* PDG_Service::serviceScheduler ( UT_WorkBuffer errors) const

Queries and returns the scheduler associated with the service, if the service is a scheduler service

void PDG_Service::setAutoStart ( bool  auto_start)
inline

Sets/gets the autostart flag, which indicates that the service will start automatically when work items need to use it.

Definition at line 166 of file PDG_Service.h.

void PDG_Service::setClientLogDir ( const UT_StringHolder log_dir)
inline

Sets/gets the directory that service clients should write their log files to.

Definition at line 199 of file PDG_Service.h.

void PDG_Service::setClientLogType ( PDG_ServiceLogType  log_type)
inline

Sets how the service itself should log output.

Definition at line 211 of file PDG_Service.h.

void PDG_Service::setCommand ( const UT_StringHolder command)
inline

Sets/gets the command line string that should be used to start clients running in the service pool

Definition at line 267 of file PDG_Service.h.

void PDG_Service::setConnectionTimeout ( int  ms)
inline

Sets the service connection timeout in milliseconds.

Definition at line 286 of file PDG_Service.h.

void PDG_Service::setData ( PY_PyObject new_data)

Sets/gets an opaque Python data object that can be stored on the service.

void PDG_Service::setEnvVarNames ( const UT_StringArray env_var_names)
inline

Sets/gets the names for the environment variables to be set in this job's environment. This only applies if the service does not have a scheduler.

Definition at line 219 of file PDG_Service.h.

void PDG_Service::setEnvVarValues ( const UT_StringArray env_var_values)
inline

Sets/gets the values for the environment variables to be set in this job's environment. This only applies if the service does not have a scheduler.

Definition at line 227 of file PDG_Service.h.

void PDG_Service::setMemoryLimit ( exint  memory_limit)
inline

Definition at line 297 of file PDG_Service.h.

void PDG_Service::setMemoryResetType ( PDG_ServiceResetType  memory_reset_type)
inline

Sets the memory limit and reset type for the service.

Definition at line 292 of file PDG_Service.h.

void PDG_Service::setMqLogDir ( const UT_StringHolder log_dir)
inline

Sets/gets the directory that the MQ relay writes its logs to.

Definition at line 205 of file PDG_Service.h.

void PDG_Service::setMqLogLevel ( int  log_level)
inline

Sets/gets the log level for the MQ process that relays messages between clients and the PDG graph

Definition at line 186 of file PDG_Service.h.

void PDG_Service::setMqPort ( int  mq_port)
inline

Sets/gets the port used by the MQ relay.

Definition at line 192 of file PDG_Service.h.

void PDG_Service::setMqUrl ( const UT_StringHolder url)
inline

Sets/gets the MQ url that the service should use to relay messages between service clients and the PDG graph

Definition at line 179 of file PDG_Service.h.

void PDG_Service::setName ( const UT_StringHolder name)
inline

Sets/gets the unique name for the service. The name of the service is unique to the PDG_ServiceManager that created it.

Definition at line 141 of file PDG_Service.h.

void PDG_Service::setOwner ( PDG_ServiceOwner  owner)
inline

Sets/gets the service owner type – either a session service or a scheduler service

Definition at line 254 of file PDG_Service.h.

void PDG_Service::setPersistent ( bool  persistent)
inline

Sets/gets the persistent flag, which determines whether a service should be persisted to the pdgservice JSON configuration file. A service that isn't persistent will be lost when the Houdini session is closed.

Definition at line 155 of file PDG_Service.h.

void PDG_Service::setPoolSize ( int  pool_size)
inline

Sets/gets the pool size for the service, which determines the number of concurrent client processes that service executes

Definition at line 274 of file PDG_Service.h.

void PDG_Service::setPort ( int  port)
inline

Sets/gets the connection port for the service itself.

Definition at line 280 of file PDG_Service.h.

void PDG_Service::setScheduler ( const UT_StringHolder name,
const UT_StringHolder context_name 
)

For scheduler services, sets the name of the scheduler and graph that created the service.

void PDG_Service::setState ( PDG_ServiceState  state)
inline

Sets/gets the current state of the service.

Definition at line 260 of file PDG_Service.h.

void PDG_Service::startPollingClient ( )

Starts a background thread that polls the ready listener until all service clients have connected

PDG_ServiceStartResult PDG_Service::startService ( UT_WorkBuffer errors,
bool  background 
)

Stats a service pool. If background is true the service processes are start asynchronously, and control immediately returns after calling this function. It's up to the caller to ensure that the service has started before using it. Returns either success, failure, or already- running.

PDG_ServiceState PDG_Service::state ( ) const
inline

Definition at line 262 of file PDG_Service.h.

bool PDG_Service::stopClient ( UT_WorkBuffer errors,
const UT_StringHolder client_name 
)

Stops a service client and kills the process associated with it. The client can be started again at a later point using restartClient. If client_name is empty string all clients are stoppped.

void PDG_Service::stopPollingClient ( )

This will force stop the ready listener. If you want to wait for it to complete, you should call waitForClients() instead.

bool PDG_Service::stopService ( UT_WorkBuffer errors,
bool  ignore_stopped 
)

Stops the service if it's running, and returns a boolean to indiate the status.

bool PDG_Service::unlockClient ( PDG_WorkItemID  item_lock,
PDG_ServiceResetType  reset_type,
UT_WorkBuffer errors 
)

Unlocks a service client.

void PDG_Service::waitForClients ( )

Waits for all pending service clients to connect, and then terminates the ready listener

Member Data Documentation

const UT_StringHolder PDG_Service::theDataVersion
static

Service data format version.

Definition at line 44 of file PDG_Service.h.


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