MessageCreator.cs :  » Network-Clients » GROF » grof » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Clients » GROF 
GROF » grof » MessageCreator.cs
using System;

namespace grof{
  /// <summary>
  /// The <c>MessageCreator</c> class is a helper class for
    /// creating <c>Message</c> objects. Each group member has one
    /// <c>MessageCreator</c> instance which is able to create
    /// join, leave, alive and application messages.
  /// </summary>
  public class MessageCreator
  {
        /// <summary>
        /// The name of the group member.
        /// </summary>
    private String name;

        /// <summary>
        /// The IP address of the group member.
        /// </summary>
    private String hostAddress;

        /// <summary>
        /// The port number of the group member.
        /// </summary>
    private int port;

        /// <summary>
        /// The message counter.
        /// </summary>
    private MessageCounter msgCounter;

        /// <summary>
        /// The timestamp of the message which indicates when
        /// the message was created and sent.
        /// </summary>
    private TimeStamp timeStamp;
    
        /// <summary>
        /// Creates instances of class <c>MessageCreator</c>. Each
        /// message holds information (IP address, port number and name)
        /// of the sender object.
        /// </summary>
        /// <param name="name">The name of the sender object.</param>
        /// <param name="hostAddress">The IP address of the sender object.</param>
        /// <param name="port">The port number the sender object
        ///         listens for incoming messages.</param>
    public MessageCreator( String name, String hostAddress, int port )
    {
      this.name = name;
      this.hostAddress = hostAddress;
      this.port = port;
      this.msgCounter = new MessageCounter();
      this.timeStamp = new TimeStamp();
    }
    
        /// <summary>
        /// Creates join messages. When a group member wants to join
        /// a group it sends a JOIN message to all group members of 
        /// this group.
        /// </summary>
        /// <param name="data">Further data the JOIN message holds</param>
        /// <returns>The created message object.</returns>
    public Message CreateJoinMessage( Object data )
    {
      GroupMemberInfo gmInfo = new GroupMemberInfo( 
        this.name, this.hostAddress, this.port );
      return new Message( Message.MessageType.JOIN, this.msgCounter.GetCounter(),
                         this.timeStamp.GetTimeStamp(), data, gmInfo );
    }

        /// <summary>
        /// Creates leave messages. When a group member wants to leave
        /// a group it sends a LEAVE message to all group members of 
        /// this group.
        /// </summary>
        /// <param name="data">Further data the LEAVE message holds</param>
        /// <returns>The created message object.</returns>
        public Message CreateLeaveMessage(Object data)
    {
      GroupMemberInfo gmInfo = new GroupMemberInfo( 
        this.name, this.hostAddress, this.port );
      return new Message( Message.MessageType.LEAVE, this.msgCounter.GetCounter(),
                         this.timeStamp.GetTimeStamp(), data, gmInfo );      
    }

        /// <summary>
        /// When a group member receives a JOIN message from another
        /// group member, it sends an ALIVE message to the joined group
        /// member. On this way the joined group member is able to build
        /// a cache of all group members.
        /// </summary>
        /// <param name="data">Further data the ALIVE message holds</param>
        /// <returns>The created message object.</returns>
    public Message CreateAliveMessage( Object data )
    {
      GroupMemberInfo gmInfo = new GroupMemberInfo( 
        this.name, this.hostAddress, this.port );
      return new Message( Message.MessageType.ALIVE, this.msgCounter.GetCounter(),
                         this.timeStamp.GetTimeStamp(), data, gmInfo );      
    }
    
        /// <summary>
        /// This method is not used by the <c>GROF</c> framework itself but
        /// implicitly by the user of the <c>GroupMember</c> class. Everytime
        /// when the user sends an object the <c>GroupMember</c> instance wraps
        /// this object in an application message.
        /// </summary>
        /// <param name="data">The user data.</param>
        /// <returns>The message object.</returns>
    public Message CreateApplicationMessage( Object data )
    {
      GroupMemberInfo gmInfo = new GroupMemberInfo( 
        this.name, this.hostAddress, this.port );
      return new Message( Message.MessageType.APP, this.msgCounter.GetAppCounter(),
                         this.timeStamp.GetTimeStamp(), data, gmInfo );      
    }
    
        /// <summary>
        /// In order to be able to sort incoming messages from 
        /// different group members by time all group members must
        /// work with the same time. For synchronizing the times this method
        /// compares the timestamp of JOIN and ALIVE messages with
        /// the local time value and updates it if necessary. 
        /// </summary>
        /// <param name="time">The timestamp of incoming messages</param>
    public void CheckAndSetTimeStamp( long time )
    {
      this.timeStamp.CheckAndSetTimeStamp( time );
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.