UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FMessageRouter Class Reference

#include <MessageRouter.h>

+ Inheritance diagram for FMessageRouter:

Public Member Functions

 FMessageRouter ()
 
 ~FMessageRouter ()
 
FORCEINLINE void AddInterceptor (const TSharedRef< IMessageInterceptor, ESPMode::ThreadSafe > &Interceptor, const FTopLevelAssetPath &MessageType)
 
FORCEINLINE void AddRecipient (const FMessageAddress &Address, const TSharedRef< IMessageReceiver, ESPMode::ThreadSafe > &Recipient)
 
FORCEINLINE void AddSubscription (const TSharedRef< IMessageSubscription, ESPMode::ThreadSafe > &Subscription)
 
FORCEINLINE TSharedRef< IMessageTracer, ESPMode::ThreadSafeGetTracer ()
 
FORCEINLINE void RemoveInterceptor (const TSharedRef< IMessageInterceptor, ESPMode::ThreadSafe > &Interceptor, const FTopLevelAssetPath &MessageType)
 
FORCEINLINE void RemoveRecipient (const FMessageAddress &Address)
 
FORCEINLINE void RemoveSubscription (const TSharedRef< IMessageReceiver, ESPMode::ThreadSafe > &Subscriber, const FTopLevelAssetPath &MessageType)
 
FORCEINLINE void RouteMessage (const TSharedRef< IMessageContext, ESPMode::ThreadSafe > &Context)
 
FORCEINLINE void AddNotificationListener (const TSharedRef< IBusListener, ESPMode::ThreadSafe > &Listener)
 
FORCEINLINE void RemoveNotificationListener (const TSharedRef< IBusListener, ESPMode::ThreadSafe > &Listener)
 
virtual FSingleThreadRunnableGetSingleThreadInterface () override
 
virtual bool Init () override
 
virtual uint32 Run () override
 
virtual void Stop () override
 
virtual void Exit () override
 
- Public Member Functions inherited from FRunnable
virtual ~FRunnable ()
 

Protected Member Functions

FTimespan CalculateWaitTime ()
 
FORCEINLINE bool EnqueueCommand (CommandDelegate Command)
 
void FilterSubscriptions (TArray< TSharedPtr< IMessageSubscription, ESPMode::ThreadSafe > > &Subscriptions, const TSharedRef< IMessageContext, ESPMode::ThreadSafe > &Context, TArray< TSharedPtr< IMessageReceiver, ESPMode::ThreadSafe > > &OutRecipients)
 
void FilterRecipients (const TSharedRef< IMessageContext, ESPMode::ThreadSafe > &Context, TArray< TSharedPtr< IMessageReceiver, ESPMode::ThreadSafe > > &OutRecipients)
 
void DispatchMessage (const TSharedRef< IMessageContext, ESPMode::ThreadSafe > &Message)
 
void ProcessCommands ()
 
void ProcessDelayedMessages ()
 
virtual void Tick () override
 

Detailed Description

Implements a topic-based message router.

Constructor & Destructor Documentation

◆ FMessageRouter()

FMessageRouter::FMessageRouter ( )

Default constructor.

◆ ~FMessageRouter()

FMessageRouter::~FMessageRouter ( )

Destructor.

Member Function Documentation

◆ AddInterceptor()

FORCEINLINE void FMessageRouter::AddInterceptor ( const TSharedRef< IMessageInterceptor, ESPMode::ThreadSafe > &  Interceptor,
const FTopLevelAssetPath MessageType 
)
inline

Adds a message interceptor.

Parameters
InterceptorThe interceptor to add.
MessageTypeThe type of messages to intercept.

◆ AddNotificationListener()

FORCEINLINE void FMessageRouter::AddNotificationListener ( const TSharedRef< IBusListener, ESPMode::ThreadSafe > &  Listener)
inline

Add a listener to the bus registration events

Parameters
ListenerThe listener to as to the registration notifications

◆ AddRecipient()

FORCEINLINE void FMessageRouter::AddRecipient ( const FMessageAddress Address,
const TSharedRef< IMessageReceiver, ESPMode::ThreadSafe > &  Recipient 
)
inline

Adds a recipient.

Parameters
AddressThe address of the recipient to add.
RecipientThe recipient.

◆ AddSubscription()

FORCEINLINE void FMessageRouter::AddSubscription ( const TSharedRef< IMessageSubscription, ESPMode::ThreadSafe > &  Subscription)
inline

Adds a subscription.

Parameters
SubscriptionThe subscription to add.

◆ CalculateWaitTime()

FTimespan FMessageRouter::CalculateWaitTime ( )
protected

Calculates the time that the thread will wait for new work.

Returns
Wait time.

◆ DispatchMessage()

void FMessageRouter::DispatchMessage ( const TSharedRef< IMessageContext, ESPMode::ThreadSafe > &  Message)
protected

Dispatches a single message to its recipients.

Parameters
MessageThe message to dispatch.

◆ EnqueueCommand()

FORCEINLINE bool FMessageRouter::EnqueueCommand ( CommandDelegate  Command)
inlineprotected

Queues up a router command.

Parameters
CommandThe command to queue up.
Returns
true if the command was enqueued, false otherwise.

◆ Exit()

void FMessageRouter::Exit ( void  )
overridevirtual

Exits the runnable object.

Called in the context of the aggregating thread to perform any cleanup.

See also
Init, Run, Stop

Reimplemented from FRunnable.

◆ FilterRecipients()

void FMessageRouter::FilterRecipients ( const TSharedRef< IMessageContext, ESPMode::ThreadSafe > &  Context,
TArray< TSharedPtr< IMessageReceiver, ESPMode::ThreadSafe > > &  OutRecipients 
)
protected

Filters recipients from the given message context to gather actual recipients.

Parameters
ContextThe message context to filter by.
OutRecipientsWill hold the collection of recipients.

◆ FilterSubscriptions()

void FMessageRouter::FilterSubscriptions ( TArray< TSharedPtr< IMessageSubscription, ESPMode::ThreadSafe > > &  Subscriptions,
const TSharedRef< IMessageContext, ESPMode::ThreadSafe > &  Context,
TArray< TSharedPtr< IMessageReceiver, ESPMode::ThreadSafe > > &  OutRecipients 
)
protected

Filters a collection of subscriptions using the given message context.

Parameters
SubscriptionsThe subscriptions to filter.
ContextThe message context to filter by.
OutRecipientsWill hold the collection of recipients.

◆ GetSingleThreadInterface()

FSingleThreadRunnable * FMessageRouter::GetSingleThreadInterface ( )
overridevirtual

Gets single thread interface pointer used for ticking this runnable when multi-threading is disabled. If the interface is not implemented, this runnable will not be ticked when FPlatformProcess::SupportsMultithreading() is false.

Returns
Pointer to the single thread interface or nullptr if not implemented.

Reimplemented from FRunnable.

◆ GetTracer()

FORCEINLINE TSharedRef< IMessageTracer, ESPMode::ThreadSafe > FMessageRouter::GetTracer ( )
inline

Gets the message tracer.

Returns
Weak pointer to the message tracer.

◆ Init()

bool FMessageRouter::Init ( void  )
overridevirtual

Initializes the runnable object.

This method is called in the context of the thread object that aggregates this, not the thread that passes this runnable to a new thread.

Returns
True if initialization was successful, false otherwise
See also
Run, Stop, Exit

Reimplemented from FRunnable.

◆ ProcessCommands()

void FMessageRouter::ProcessCommands ( )
protected

Process all queued commands.

See also
ProcessDelayedMessages

◆ ProcessDelayedMessages()

void FMessageRouter::ProcessDelayedMessages ( )
protected

Processes all delayed messages.

See also
ProcessCommands

◆ RemoveInterceptor()

FORCEINLINE void FMessageRouter::RemoveInterceptor ( const TSharedRef< IMessageInterceptor, ESPMode::ThreadSafe > &  Interceptor,
const FTopLevelAssetPath MessageType 
)
inline

Removes a message interceptor.

Parameters
InterceptorThe interceptor to remove.
MessageTypeThe type of messages to stop intercepting.

◆ RemoveNotificationListener()

FORCEINLINE void FMessageRouter::RemoveNotificationListener ( const TSharedRef< IBusListener, ESPMode::ThreadSafe > &  Listener)
inline

Remove a listener to the bus registration events

Parameters
ListenerThe listener to remove from the registration notifications

◆ RemoveRecipient()

FORCEINLINE void FMessageRouter::RemoveRecipient ( const FMessageAddress Address)
inline

Removes a recipient.

Parameters
AddressThe address of the recipient to remove.

◆ RemoveSubscription()

FORCEINLINE void FMessageRouter::RemoveSubscription ( const TSharedRef< IMessageReceiver, ESPMode::ThreadSafe > &  Subscriber,
const FTopLevelAssetPath MessageType 
)
inline

Removes a subscription.

Parameters
SubscriberThe subscriber to stop routing messages to.
MessageTypeThe type of message to unsubscribe from (NAME_None = all types).

◆ RouteMessage()

FORCEINLINE void FMessageRouter::RouteMessage ( const TSharedRef< IMessageContext, ESPMode::ThreadSafe > &  Context)
inline

Routes a message to the specified recipients.

Parameters
ContextThe context of the message to route.

◆ Run()

uint32 FMessageRouter::Run ( )
overridevirtual

Runs the runnable object.

This is where all per object thread work is done. This is only called if the initialization was successful.

Returns
The exit code of the runnable object
See also
Init, Stop, Exit

Implements FRunnable.

◆ Stop()

void FMessageRouter::Stop ( void  )
overridevirtual

Stops the runnable object.

This is called if a thread is requested to terminate early.

See also
Init, Run, Exit

Reimplemented from FRunnable.

◆ Tick()

void FMessageRouter::Tick ( )
overrideprotectedvirtual

Implements FSingleThreadRunnable.


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