You do not need to read all of the data in a message--you can read just enough to determine that a message is not of interest. However, if you try to read beyond the amount of data contained in the object, this raises an exception.
Each incoming message includes:
The sender identifier corresponds to the caucus member that originated the message.
The message type identifies the message using an enumerated value:
kJoin | Join message; zero bytes. Indicates that the sender joined the caucus. | |
kLeave | Leave message; zero bytes. Indicates that either the sender exited the caucus intentionally or the sender crashed. | |
kData | A message not generated automatically by the standard implementation; a custom message as defined by a caucus member. | |
kPause | Pause message. Indicates that the sender is pausing caucus communication. | |
kResume | Resume message. Confirms that the sender has resumed caucus communication. |
One way to set up a caucus member to receive messages is to create a thread that loops continuously, creating TStandardCaucusReceiveMessage objects. This thread blocks until it can create a valid TCaucusReceiveMessage object--once it successfully creates a receive message object, the code can stream the data out and destroy the object.
To receive a message:
NOTE The example code shows the body of Run, a member of TStandardCaucusReadThread. This class is shown for example only; it is not a part of the CommonPoint application system. The variable fMessageHandler is a member of MStandardCaucusMessageHandler, a user-defined class not shown here. For Beta, you need to define your own read thread classes; you can model your own using TStandardCaucusReadThread as an example.
// Copyright 1995 Taligent, Inc. All rights reserved. void TStandardCaucusReadThread::Run() { try { TCaucusMember::Identifier member = 0; TCaucusMember::Identifier me = fCaucusMember->GetIdentity(); TStandardCaucusMember::EMessageType messageType = TStandardCaucusMember::kJoin; // stop only when the message is my Leave message while ( !((messageType == TStandardCaucusMember::kLeave) && (member == me)) ) { TStandardCaucusReceiveMessage message(fCaucusMember, member, messageType); switch (messageType) { case TStandardCaucusMember::kData: fMessageHandler->HandleReceivedData(message, member); break; case TStandardCaucusMember::kLeave: fMessageHandler->HandleMemberLeft(member); break; case TStandardCaucusMember::kJoin: fMessageHandler->HandleMemberJoin(member); break; case TStandardCaucusMember::kPause: fMessageHandler->HandleReceivedPause(message, member); break; case TStandardCaucusMember::kResume: fMessageHandler->HandleReceivedResume(message, member); break; } } } catch (const TCaucusException &e) { // Can only mean the caucus no longer exists fMessageHandler->HandleCaucusReadException(e); } }