Navigation
API > API/Runtime > API/Runtime/MessagingCommon
Implements a message endpoint for sending and receiving messages on a message bus.
This class provides a convenient implementation of the IMessageReceiver and IMessageSender interfaces, which allow consumers to send and receive messages on a message bus. The endpoint allows for receiving messages asynchronously as they arrive, as well as synchronously through an inbox that can be polled.
By default, messages are received synchronously on the thread that the endpoint was created on. If the message consumer is thread-safe, a more efficient message dispatch can be enabled by calling the SetRecipientThread() method with ENamedThreads::AnyThread.
Endpoints that are destroyed or receive messages on non-Game threads should use the static function FMessageEndpoint::SafeRelease() to dispose of the endpoint. This will ensure that there are no race conditions between endpoint destruction and the receiving of messages.
The underlying message bus will take ownership of all sent and published message objects. The memory held by the messages must therefore NOT be freed by the caller.
| Name | FMessageEndpoint |
| Type | class |
| Header File | /Engine/Source/Runtime/MessagingCommon/Public/MessageEndpoint.h |
| Include Path | #include "MessageEndpoint.h" |
Syntax
class FMessageEndpoint :
public TSharedFromThis< FMessageEndpoint, ESPMode::ThreadSafe > ,
public IMessageReceiver,
public IMessageSender,
public IBusListener
Inheritance Hierarchy
- FSharedFromThisBase → TSharedFromThis → FMessageEndpoint
Implements Interfaces
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FMessageEndpoint
(
const FName& InName, |
Creates and initializes a new instance. | MessageEndpoint.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~FMessageEndpoint() |
Destructor. | MessageEndpoint.h |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| Builder | struct FMessageEndpointBuilder | Type definition for the endpoint builder. | MessageEndpoint.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Address | const FMessageAddress | Holds the endpoint's identifier. | MessageEndpoint.h | |
| BusPtr | TWeakPtr< IMessageBus, ESPMode::ThreadSafe > | Holds a weak pointer to the message bus. | MessageEndpoint.h | |
| Enabled | bool | Hold a flag indicating whether this endpoint is active. | MessageEndpoint.h | |
| ErrorDelegate | FOnMessageEndpointError | Holds a delegate that is invoked in case of messaging errors. | MessageEndpoint.h | |
| Handlers | TArray< TSharedPtr< IMessageHandler, ESPMode::ThreadSafe > > | Holds the registered message handlers. | MessageEndpoint.h | |
| HandlersCS | FCriticalSection | Sigfnifies that the handler array is being accessed and other threads should wait or skip | MessageEndpoint.h | |
| Id | const FGuid | Holds the endpoint's unique identifier (for debugging purposes). | MessageEndpoint.h | |
| Inbox | TQueue< TSharedPtr< IMessageContext, ESPMode::ThreadSafe >, EQueueMode::Mpsc > | Holds the endpoint's message inbox. | MessageEndpoint.h | |
| InboxEnabled | bool | Holds a flag indicating whether the inbox is enabled. | MessageEndpoint.h | |
| Name | const FName | Holds the endpoint's name (for debugging purposes). | MessageEndpoint.h | |
| NotificationDelegate | FOnBusNotification | Holds a delegate that is invoked on disconnection events. | MessageEndpoint.h | |
| RecipientThread | ENamedThreads::Type | Holds the name of the thread on which to receive messages. | MessageEndpoint.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void Defer
(
const TSharedRef< IMessageContext, ESPMode::ThreadSafe >& Context, |
Defers processing of the given message by the specified time delay. | MessageEndpoint.h | |
void Disable () |
Disables this endpoint. | MessageEndpoint.h | |
void DisableInbox () |
Disables the inbox for unhandled messages.The inbox is disabled by default. | MessageEndpoint.h | |
void Enable () |
Enables this endpoint. | MessageEndpoint.h | |
void EnableInbox () |
Enables the inbox for unhandled messages. | MessageEndpoint.h | |
void Forward
(
const TSharedRef< IMessageContext, ESPMode::ThreadSafe >& Context, |
Forwards a previously received message. | MessageEndpoint.h | |
void Forward
(
const TSharedRef< IMessageContext, ESPMode::ThreadSafe >& Context, |
Forwards a previously received message to the specified recipient after a given delay. | MessageEndpoint.h | |
void Forward
(
const TSharedRef< IMessageContext, ESPMode::ThreadSafe >& Context, |
Immediately forwards a previously received message to the specified recipient. | MessageEndpoint.h | |
void Forward
(
const TSharedRef< IMessageContext, ESPMode::ThreadSafe >& Context, |
Immediately forwards a previously received message to the specified list of recipients. | MessageEndpoint.h | |
const FMessageAddress & GetAddress() |
Gets the endpoint's message address. | MessageEndpoint.h | |
virtual FName GetDebugName() |
MessageEndpoint.h | ||
virtual ENamedThreads::Type GetListenerThread() |
MessageEndpoint.h | ||
virtual const FGuid & GetRecipientId() |
MessageEndpoint.h | ||
virtual ENamedThreads::Type GetRecipientThread() |
MessageEndpoint.h | ||
virtual FMessageAddress GetSenderAddress() |
MessageEndpoint.h | ||
bool IsConnected () |
Checks whether this endpoint is connected to the bus. | MessageEndpoint.h | |
bool IsEnabled () |
Checks whether this endpoint is enabled. | MessageEndpoint.h | |
bool IsInboxEmpty () |
Checks whether the inbox is empty. | MessageEndpoint.h | |
bool IsInboxEnabled () |
Checks whether the inbox is enabled. | MessageEndpoint.h | |
virtual bool IsLocal() |
MessageEndpoint.h | ||
virtual void NotifyMessageError
(
const TSharedRef< IMessageContext, ESPMode::ThreadSafe >& Context, |
MessageEndpoint.h | ||
virtual void NotifyRegistration
(
const FMessageAddress& InAddress, |
MessageEndpoint.h | ||
void ProcessInbox () |
Calls the matching message handlers for all messages queued up in the inbox. | MessageEndpoint.h | |
| Publishes a message to all subscribed recipients within the specified scope. | MessageEndpoint.h | ||
| Publishes a message to all subscribed recipients within the specified scope. | MessageEndpoint.h | ||
void Publish
(
void* Message, |
Publishes a message to all subscribed recipients within the specified scope. | MessageEndpoint.h | |
| Publishes a message to all subscribed recipients within the specified scope. | MessageEndpoint.h | ||
| Immediately pa message to all subscribed recipients within the specified scope. | MessageEndpoint.h | ||
| Publishes a message to all subscribed recipients within the specified scope after a given delay. | MessageEndpoint.h | ||
| Publishes a message to all subscribed recipients after a given delay. | MessageEndpoint.h | ||
void Publish
(
MessageType* Message |
Immediately publishes a message to all subscribed recipients. | MessageEndpoint.h | |
void Publish
(
MessageType* Message, |
Immediately pa message to all subscribed recipients within the specified scope. | MessageEndpoint.h | |
| Immediately publishes a message to all subscribed recipients. | MessageEndpoint.h | ||
bool ReceiveFromInbox
(
TSharedPtr< IMessageContext, ESPMode::ThreadSafe >& OutContext |
Receives a single message from the endpoint's inbox. | MessageEndpoint.h | |
virtual void ReceiveMessage
(
const TSharedRef< IMessageContext, ESPMode::ThreadSafe >& Context |
MessageEndpoint.h | ||
void Send
(
void* Message, |
Sends a message to the specified list of recipients. | MessageEndpoint.h | |
void Send
(
MessageType* Message, |
Sends a message to the specified list of recipients. Allows to specify message flags | MessageEndpoint.h | |
void Send
(
void* Message, |
Sends a message to the specified list of recipients. Allows to specify message flags | MessageEndpoint.h | |
void Send
(
MessageType* Message, |
Sends a message to the specified list of recipients. Allows to specify message flags | MessageEndpoint.h | |
void Send
(
MessageType* Message, |
Sends a message with fields, attachment and expiration to the specified recipient after a given delay. | MessageEndpoint.h | |
void Send
(
void* Message, |
Sends a message to the specified list of recipients. | MessageEndpoint.h | |
void Send
(
MessageType* Message, |
Sends a message to the specified list of recipients. | MessageEndpoint.h | |
void Send
(
MessageType* Message, |
Sends a message with fields and attachment to the specified list of recipients after a given delay. | MessageEndpoint.h | |
void Send
(
MessageType* Message, |
Sends a message with fields, attachment and expiration to the specified recipient after a given delay. | MessageEndpoint.h | |
| Sends a message to the specified list of recipients after a given delay after a given delay. | MessageEndpoint.h | ||
void Send
(
MessageType* Message, |
Sends a message with fields and attachment to the specified recipient. | MessageEndpoint.h | |
| Sends a message to the specified recipient after a given delay. | MessageEndpoint.h | ||
| Immediately sends a message to the specified recipient. | MessageEndpoint.h | ||
| Immediately sends a message to the specified list of recipients. | MessageEndpoint.h | ||
void Send
(
MessageType* Message, |
Immediately sends a message to the specified recipient. | MessageEndpoint.h | |
| Sends a message with fields and expiration to the specified recipient after a given delay. | MessageEndpoint.h | ||
void SetRecipientThread
(
const ENamedThreads::Type& NamedThread |
Sets the name of the thread to receive messages on. | MessageEndpoint.h | |
void Subscribe () |
Template method to subscribe the message endpoint to the specified type of messages with the default message scope. | MessageEndpoint.h | |
void Subscribe
(
const FMessageScopeRange& ScopeRange |
Template method to subscribe the message endpoint to the specified type and scope of messages. | MessageEndpoint.h | |
| Subscribes a message handler. | MessageEndpoint.h | ||
void Subscribe
(
const FTopLevelAssetPath& MessageType, |
Subscribes a message handler. | MessageEndpoint.h | |
void Unsubscribe
(
const FName& MessageType |
Unsubscribes this endpoint from the specified message type. | MessageEndpoint.h | |
void Unsubscribe () |
Unsubscribes this endpoint from all message types. | MessageEndpoint.h | |
void Unsubscribe () |
Template method to unsubscribe the endpoint from the specified message type. | MessageEndpoint.h | |
void Unsubscribe
(
const FTopLevelAssetPath& MessageType |
Unsubscribes this endpoint from the specified message type. | MessageEndpoint.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void ClearHandlers () |
Clears all handlers in a way that guarantees it won't overlap with message processing. | MessageEndpoint.h | |
TSharedPtr< IMessageBus, ESPMode::ThreadSafe > GetBusIfEnabled() |
Gets a shared pointer to the message bus if this endpoint is enabled. | MessageEndpoint.h | |
void ProcessMessage
(
const TSharedRef< IMessageContext, ESPMode::ThreadSafe >& Context |
Forwards the given message context to matching message handlers. | MessageEndpoint.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static T * MakeMessage
(
InArgTypes&&... Args |
Creates a message of the specified template type. | MessageEndpoint.h | |
static void SafeRelease
(
TSharedPtr< FMessageEndpoint, ESPMode::ThreadSafe >& Endpoint |
Safely releases a message endpoint that is receiving messages on AnyThread. | MessageEndpoint.h |