using System;
namespace grof{
/// <summary>
/// Before a message is sent by the group member
/// the message counter is set to the message. All
/// messages which are sent by a group member are
/// consecutively numbered. This means another group member
/// is able to recognize when a certain message was not received.
/// <para>Example: Group member A sends messages with message counters
/// like 1,2,3,4,5... and group member B only receives 1,2,3,5,...</para>.
/// In this case group member B detects that message 4 is missing and will
/// request message 4 once again.
/// </summary>
public class MessageCounter
{
/// <summary>
/// The message counter for application messages.
/// </summary>
private long applicationCounter = 0;
/// <summary>
/// The message counter for internal messages of
/// the GROF framework (JOIN, LEAVE...)
/// </summary>
private long counter = 0;
/// <summary>
/// Creates instances of class
/// <c>MessageCounter</c>.
/// </summary>
public MessageCounter()
{
}
/// <summary>
/// Increments the current counter
/// of application messages and returns
/// the new value.
/// </summary>
/// <returns>The next message counter value of
/// aplication messages.</returns>
public long GetAppCounter()
{
lock( this )
{
return ++this.applicationCounter;
}
}
/// <summary>
/// Increments the current counter of internal
/// messages and returns the new value.
/// </summary>
/// <returns>The next message counter value of
/// internal messages.</returns>
public long GetCounter()
{
lock( this )
{
return ++this.counter;
}
}
}
}
|