NVIDIA Morpheus (24.06)
(Latest Version)

Class ControlMessage

class ControlMessage

Class representing a control message for coordinating data processing tasks.

This class contains configuration information, task definitions, and metadata, as well as a pointer to an associated message payload. It provides methods for accessing and modifying these elements of the control message.

Public Functions

ControlMessage()

explicit ControlMessage(const morpheus::utilities::json_t &config)

ControlMessage(const ControlMessage &other)

void config(const morpheus::utilities::json_t &config)

Set the configuration object for the control message.

Parameters

config – A morpheus::utilities::json_t object containing configuration information.

const morpheus::utilities::json_t &config() const

Get the configuration object for the control message.

Returns

A const reference to the morpheus::utilities::json_t object containing configuration information.

void add_task(const std::string &task_type, const morpheus::utilities::json_t &task)

Add a task of the given type to the control message.

Parameters
bool has_task(const std::string &task_type) const

Check if a task of the given type exists in the control message.

Parameters

task_type – A string indicating the type of the task.

Returns

True if a task of the given type exists, false otherwise.

morpheus::utilities::json_t remove_task(const std::string &task_type)

Remove and return a task of the given type from the control message.

Parameters

task_type – A string indicating the type of the task.

Returns

A morpheus::utilities::json_t object describing the task.

const morpheus::utilities::json_t &get_tasks() const

Get the tasks for the control message.

void set_metadata(const std::string &key, const morpheus::utilities::json_t &value)

Add a key-value pair to the metadata for the control message.

Parameters
bool has_metadata(const std::string &key) const

Check if a metadata key exists in the control message.

Parameters

key – A string indicating the metadata key.

Returns

True if the metadata key exists, false otherwise.

morpheus::utilities::json_t get_metadata() const

Get the metadata for the control message.

morpheus::utilities::json_t get_metadata(const std::string &key, bool fail_on_nonexist = false) const

Get the metadata value for the given key from the control message. If the key does not exist, the behavior depends on the fail_on_nonexist parameter.

Parameters
  • key – A string indicating the metadata key.

  • fail_on_nonexist – If true, throws an exception when the key does not exist. If false, returns std::nullopt for non-existing keys.

Returns

An optional morpheus::utilities::json_t object describing the metadata value if it exists.

std::vector<std::string> list_metadata() const

Lists all metadata keys currently stored in the control message.

This method retrieves a list of all metadata keys present in the control message. Metadata within a control message typically includes supplementary information such as configuration settings, operational parameters, or annotations that are not directly part of the message payload but are crucial for processing or understanding the message.

Returns

A std::vector<std::string> containing the keys of all metadata entries in the control message. If no metadata has been set, the returned vector will be empty.

std::shared_ptr<MessageMeta> payload()

Retrieves the current payload object of the control message.

This method returns a shared pointer to the current payload object associated with this control message. The payload object encapsulates metadata or data specific to this message instance.

Get the payload object for the control message.

Parameters

payload – A shared pointer to the message payload.

Returns

A shared pointer to the MessageMeta instance representing the message payload.

void payload(const std::shared_ptr<MessageMeta> &payload)

Assigns a new payload object to the control message.

Sets the payload of the control message to the provided MessageMeta instance. The payload contains data or metadata pertinent to the message. Using a shared pointer ensures that the payload is managed efficiently with automatic reference counting.

Parameters

payload – A shared pointer to the MessageMeta instance to be set as the new payload.

std::shared_ptr<TensorMemory> tensors()

Retrieves the tensor memory associated with the control message.

This method returns a shared pointer to the TensorMemory object linked with the control message, if any. TensorMemory typically contains or references tensors or other large data blobs relevant to the message’s purpose.

Returns

A shared pointer to the TensorMemory instance associated with the message, or nullptr if no tensor memory is set.

void tensors(const std::shared_ptr<TensorMemory> &tensor_memory)

Associates tensor memory with the control message.

Sets the tensor memory for the control message to the provided TensorMemory instance. This tensor memory can contain tensors or large data blobs pertinent to the message. Utilizing a shared pointer facilitates efficient memory management through automatic reference counting.

Parameters

tensor_memory – A shared pointer to the TensorMemory instance to be associated with the control message.

ControlMessageType task_type()

Get the type of task associated with the control message.

Returns

An enum value indicating the task type.

void task_type(ControlMessageType task_type)

Set the task type for the control message.

Parameters

task_type

Returns

void set_timestamp(const std::string &key, time_point_t timestamp_ns)

Sets a timestamp for a specific key.

This method stores a timestamp associated with a unique identifier, If the key already exists, its timestamp will be updated to the new value.

Parameters
  • key – The specific key for which the timestamp is to be set.

  • timestamp – The timestamp to be associated with the key.

std::optional<time_point_t> get_timestamp(const std::string &key, bool fail_if_nonexist = false)

Retrieves the timestamp for a specific key.

Attempts to find and return the timestamp associated with the specified key. If the key does not exist, the method’s behavior is determined by the fail_if_nonexist flag.

Parameters
  • key – The specific key for which the timestamp is requested.

  • fail_if_nonexist – If true, the method throws an exception if the timestamp doesn’t exist. If false, returns std::nullopt for non-existing timestamps.

Returns

An optional containing the timestamp if found, or std::nullopt otherwise.

std::map<std::string, time_point_t> filter_timestamp(const std::string &regex_filter)

Retrieves timestamps for all keys that match a regex pattern.

Searches for the specified for keys that match the provided regex filter and returns a map of these keys and their associated timestamps.

Parameters

regex_filter – A regular expression pattern that keys must match to be included in the result.

Returns

A map containing the matching key and their timestamps. The map will be empty if no matches are found.

Previous Template Class AddScoresStageBase
Next Class DataLoader
© Copyright 2024, NVIDIA. Last updated on Jul 8, 2024.