FMessageEndpoint

Implements a message endpoint for sending and receiving messages on a message bus.

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

MessagingCommon

Header

/Engine/Source/Runtime/MessagingCommon/Public/MessageEndpoint.h

Include

#include "MessageEndpoint.h"

Syntax

class FMessageEndpoint :
    public TSharedFromThis< FMessageEndpoint, ESPMode::ThreadSafe >,
    public IMessageReceiver,
    public IMessageSender,
    public IBusListener

Remarks

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.

Constructors

Name Description

Public function

FMessageEndpoint

(
    const FName& InName,
    const TSharedRef< IMessageBus, ESPM...,
    const TArray< TSharedPtr< IMessageH...,
    const FOnBusNotification InNotifica...
)

Creates and initializes a new instance.

Destructors

Name Description

Public function

~FMessageEndpoint()

Destructor.

Functions

Name Description

Protected function

void

 

ClearHandlers()

Clears all handlers in a way that guarantees it won't overlap with message processing.

Public function

void

 

Defer

(
    const TSharedRef< IMessageContext, ...,
    const FTimespan& Delay
)

Defers processing of the given message by the specified time delay.

Public function

void

 

Disable()

Disables this endpoint.

Public function

void

 

DisableInbox()

Disables the inbox for unhandled messages.

The inbox is disabled by default.

Public function

void

 

Enable()

Enables this endpoint.

Public function

void

 

EnableInbox()

Enables the inbox for unhandled messages.

Public function

void

 

Forward

(
    const TSharedRef< IMessageContext, ...,
    const TArray< FMessageAddress >& R...,
    const FTimespan& Delay
)

Forwards a previously received message.

Public function

void

 

Forward

(
    const TSharedRef< IMessageContext, ...,
    const TArray< FMessageAddress >& R...
)

Immediately forwards a previously received message to the specified list of recipients.

Public function

void

 

Forward

(
    const TSharedRef< IMessageContext, ...,
    const FMessageAddress& Recipient
)

Immediately forwards a previously received message to the specified recipient.

Public function

void

 

Forward

(
    const TSharedRef< IMessageContext, ...,
    const FMessageAddress& Recipient,
    const FTimespan& Delay
)

Forwards a previously received message to the specified recipient after a given delay.

Public function Const

const FMessa...

 

GetAddress()

Gets the endpoint's message address.

Protected function Const

TSharedPtr< ...

 

GetBusIfEnabled()

Gets a shared pointer to the message bus if this endpoint is enabled.

Public function Const

bool

 

IsConnected()

Checks whether this endpoint is connected to the bus.

Public function Const

bool

 

IsEnabled()

Checks whether this endpoint is enabled.

Public function Const

bool

 

IsInboxEmpty()

Checks whether the inbox is empty.

Public function Const

bool

 

IsInboxEnabled()

Checks whether the inbox is enabled.

Public function

void

 

ProcessInbox()

Calls the matching message handlers for all messages queued up in the inbox.

Protected function

void

 

ProcessMessage

(
    const TSharedRef< IMessageContext, ...
)

Forwards the given message context to matching message handlers.

Public function

void

 

Publish

(
    MessageType* Message,
    EMessageScope Scope,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Publishes a message to all subscribed recipients within the specified scope.

Public function

void

 

Publish

(
    MessageType* Message,
    const TMap< FName, FString > Annota...,
    EMessageScope Scope,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Publishes a message to all subscribed recipients within the specified scope.

Public function

void

 

Publish

(
    void* Message,
    UScriptStruct* TypeInfo,
    EMessageScope Scope,
    const TMap< FName, FString > Annota...,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Publishes a message to all subscribed recipients within the specified scope.

Public function

void

 

Publish

(
    MessageType* Message,
    const TMap< FName, FString > Annota...,
    EMessageScope Scope
)

Immediately pa message to all subscribed recipients within the specified scope.

Public function

void

 

Publish

(
    void* Message,
    UScriptStruct* TypeInfo,
    EMessageScope Scope,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Publishes a message to all subscribed recipients within the specified scope.

Public function

void

 

Publish

(
    MessageType* Message,
    const FTimespan& Delay
)

Publishes a message to all subscribed recipients after a given delay.

Public function

void

 

Publish

(
    MessageType* Message,
    EMessageScope Scope,
    const FTimespan& Delay
)

Publishes a message to all subscribed recipients within the specified scope after a given delay.

Public function

void

 

Publish

(
    MessageType* Message,
    EMessageScope Scope
)

Immediately pa message to all subscribed recipients within the specified scope.

Public function

void

 

Publish

(
    MessageType* Message
)

Immediately publishes a message to all subscribed recipients.

Public function

void

 

Publish

(
    MessageType* Message,
    const TMap< FName, FString > Annota...
)

Immediately publishes a message to all subscribed recipients.

Public function

bool

 

ReceiveFromInbox

Receives a single message from the endpoint's inbox.

Public function Static

void

 

SafeRelease

Safely releases a message endpoint that is receiving messages on AnyThread.

Public function

void

 

Send

(
    void* Message,
    UScriptStruct* TypeInfo,
    EMessageFlags Flags,
    const TMap< FName, FString > Annota...,
    const TSharedPtr< IMessageAttachmen...,
    const TArray< FMessageAddress >& R...,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Sends a message to the specified list of recipients.

Public function

void

 

Send

(
    MessageType* Message,
    EMessageFlags Flags,
    const TMap< FName, FString > Annota...,
    const TSharedPtr< IMessageAttachmen...,
    const TArray< FMessageAddress >& R...,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Sends a message to the specified list of recipients. Allows to specify message flags

Public function

void

 

Send

(
    void* Message,
    UScriptStruct* TypeInfo,
    EMessageFlags Flags,
    const TSharedPtr< IMessageAttachmen...,
    const TArray< FMessageAddress >& R...,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Sends a message to the specified list of recipients. Allows to specify message flags

Public function

void

 

Send

(
    MessageType* Message,
    EMessageFlags Flags,
    const TSharedPtr< IMessageAttachmen...,
    const TArray< FMessageAddress >& R...,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Sends a message to the specified list of recipients. Allows to specify message flags

Public function

void

 

Send

(
    MessageType* Message,
    const TMap< FName, FString > Annota...,
    const TSharedPtr< IMessageAttachmen...,
    const FMessageAddress& Recipient,
    const FDateTime& Expiration,
    const FTimespan& Delay
)

Sends a message with fields, attachment and expiration to the specified recipient after a given delay.

Public function

void

 

Send

(
    MessageType* Message,
    const TSharedPtr< IMessageAttachmen...,
    const TArray< FMessageAddress >& R...,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Sends a message to the specified list of recipients.

Public function

void

 

Send

(
    MessageType* Message,
    const TSharedPtr< IMessageAttachmen...,
    const FMessageAddress& Recipient,
    const FDateTime& Expiration,
    const FTimespan& Delay
)

Sends a message with fields, attachment and expiration to the specified recipient after a given delay.

Public function

void

 

Send

(
    MessageType* Message,
    const TSharedPtr< IMessageAttachmen...,
    const TArray< FMessageAddress >& R...,
    const FTimespan& Delay
)

Sends a message with fields and attachment to the specified list of recipients after a given delay.

Public function

void

 

Send

(
    MessageType* Message,
    const TArray< FMessageAddress >& R...,
    const FTimespan& Delay
)

Sends a message to the specified list of recipients after a given delay after a given delay.

Public function

void

 

Send

(
    MessageType* Message,
    const TSharedPtr< IMessageAttachmen...,
    const FMessageAddress& Recipient
)

Sends a message with fields and attachment to the specified recipient.

Public function

void

 

Send

(
    MessageType* Message,
    const FMessageAddress& Recipient,
    const FTimespan& Delay
)

Sends a message to the specified recipient after a given delay.

Public function

void

 

Send

(
    MessageType* Message,
    const TMap< FName, FString > Annota...,
    const FMessageAddress& Recipient
)

Immediately sends a message to the specified recipient.

Public function

void

 

Send

(
    MessageType* Message,
    const TArray< FMessageAddress >& R...
)

Immediately sends a message to the specified list of recipients.

Public function

void

 

Send

(
    MessageType* Message,
    const FMessageAddress& Recipient
)

Immediately sends a message to the specified recipient.

Public function

void

 

Send

(
    MessageType* Message,
    const FMessageAddress& Recipient,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

Sends a message with fields and expiration to the specified recipient after a given delay.

Public function

void

 

SetRecipientThread

(
    const ENamedThreads::Type& NamedTh...
)

Sets the name of the thread to receive messages on.

Public function

void

 

Subscribe()

Template method to subscribe the message endpoint to the specified type of messages with the default message scope.

Public function

void

 

Subscribe

(
    const FMessageScopeRange& ScopeRan...
)

Template method to subscribe the message endpoint to the specified type and scope of messages.

Public function

void

 

Subscribe

(
    const FName& MessageType,
    const FMessageScopeRange& ScopeRan...
)

Subscribes a message handler.

Public function

void

 

Unsubscribe()

Template method to unsubscribe the endpoint from the specified message type.

Public function

void

 

Unsubscribe()

Unsubscribes this endpoint from all message types.

Public function

void

 

Unsubscribe

(
    const FName& TopicPattern
)

Unsubscribes this endpoint from the specified message type.

Overridden from IMessageReceiver

Name Description

Public function Virtual Const

FName

 

GetDebugName()

Gets the recipient's name (for debugging purposes).

Public function Virtual Const

const FGuid ...

 

GetRecipientId()

Gets the recipient's unique identifier (for debugging purposes).

Public function Virtual Const

ENamedThread...

 

GetRecipientThread()

Gets the name of the thread on which to receive messages.

Public function Virtual Const

bool

 

IsLocal()

Checks whether this recipient represents a local endpoint.

Public function Virtual

void

 

ReceiveMessage

(
    const TSharedRef< IMessageContext, ...
)

Handles the given message.

Overridden from IMessageSender

Name Description

Public function Virtual

FMessageAddr...

 

GetSenderAddress()

Gets the sender's address.

Public function Virtual

void

 

NotifyMessageError

(
    const TSharedRef< IMessageContext, ...,
    const FString& Error
)

Notifies the sender of errors.

Overridden from IBusListener

Name Description

Public function Virtual Const

ENamedThread...

 

GetListenerThread()

Gets the name of the thread on which to receive notifications.

Public function Virtual

void

 

NotifyRegistration

(
    const FMessageAddress& Address,
    EMessageBusNotification Notificatio...
)

Notify a registration event from the bus This is called when a receiver is registered or unregistered from the bus.

Typedefs

Name

Description

Builder

Type definition for the endpoint builder.

Deprecated Functions

Name Description

Public function

void

 

Send

(
    void* Message,
    UScriptStruct* TypeInfo,
    const TSharedPtr< IMessageAttachmen...,
    const TArray< FMessageAddress >& R...,
    const FTimespan& Delay,
    const FDateTime& Expiration
)

FMessageEndpoint::Send with 6 params is deprecated. Please use FMessageEndpoint::Send that takes additionnal EMessageFlags instead!

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss