IMessageQueue

Each thread of a namespaces has its own message queue. Here the messages are added, which are addressed to targets, which are associated with the thread. The thread fetches the messages from the queue and then delivers them to the target. This ensures that messages for a target are always processed in the same thread.

The methods of the message queue are only used by the system, but they are in principle also accessible to the community, e.g. to configure the thread.

Access via the target

To get the message queue to which a single target is assigned, you can ask the target registry:

final IId qid = target.getQueueId();
final IMessageQueue queue = targetRegistry.getQueue(qid);

Access via the namespace

Each namespace has a message queue registry. All message queues of the namespaces are registered here. Since the message queue registry is accessible via the namespace, you also get the message queue for a given queue ID.

final INamespace namespace = CServiceRegistry.getInstance()
                                             .getService(INamespace.class,
                                                         "nid=SYSTEM");
final IMessageQueueRegistry mqr = namespace.getMessageQueueRegistry();
final IMessageQueue mq = mqr.getQueue(qid);

Start of a message queue

The start is done via the system. This calls the following method:

void start();

Stop of a message queue

The stop is done by calling the following method:

void dismiss();

Getter

The ID of a queue is fetched via:

@NotNull IId getId();

A description of the queue (the description of the thread) is fetched via:

@NotNull String getDescription();

The thread is determined via:

@NotNull Thread getThread();

The number of messages currently in the queue is returned by the following method:

int getSize();

Adding messages

This is the task of the framework:

void offer(@NotNull CMessage aMsg);