Message-Queues

Message queues are threads with a queue for messages. When a message for a target arrives at the namespace, the message queue to which the target was assigned is determined. The message is then transferred to this queue, where it was temporarily stored (First In, First Out). The messages are then taken one by one from the queue and passed to the targets for processing.

The MessageQueue has an ID of type IId. It is assigned by the system when creating and registering the queue. The getter for it is:

IId getId();

The ID is required when registering targets. If you do not specify a queue ID, the target is always registered at the first queue of the namespace. The message queue ID is often referred to here as QID.

The queue has more methods:

// Returns a description.
String getDescription();

// Returns the number of messages currently received.
int getSize();

// Internal method for passing the messages
void offer(CMessage aMsg);

The underlying thread is obtained by:

Thread getThread();

The remaining methods are more internal.

MessageQueueRegistry

Each namespace has a message queue registry. Normally, the programmer does not come into contact with this, since most of the namespaces have only one MessageQueue and therefore one thread. You can use this registry to create and register message queues.

The namespace ID of the namespaces to which the registry is assigned is obtained in this way:

IId getNamespaceId();

It is created here:

IMessageQueue createAndStartAsyncQueue(String aDesc,
                                       int aThreadPriority) throws CException;

You can also get rid of an existing queue:

void deleteQueue(IId aQID) throws CException;

Since most namespaces have only one queue, this method is available for convenience:

IMessageQueue getFirstQueue();

Other methods for accessing the registered queues:

// Retrieves a specific message queue.
IMessageQueue getQueue(IId aQID);

// With exception at unknown QID
IMessageQueue getQueueEx(IId aQID) throws CException;

// The array of all registered queues for the namespace
IId[] getQueueIdArray();

Information about queues is obtained in this way:

void getQueueInfo(IId aQID,
                  CRecord aRecord) throws CException;

The type of the record is CRecordGetQueueInfo.

The following methods are used to manage listeners:

IId[] registerQueueListener(ITargetAddress aListener);

void deregisterQueueListener(ITargetAddress aListener);

The first method also returns the list of all registered MessageQueues. Listeners get the following notifications:

  • CRecordNotifyQueueRegistered
  • CRecordNotifyQueueDeregistered