GroupMemberInfo.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 » GroupMemberInfo.cs
using System;

namespace grof{
  /// <summary>
  /// The <c>GroupMemberInfo</c> class caches all
    /// important data of a group member like
    /// the host address, the port number the
    /// group member listens for incoming messages and
    /// the group name. The <c>GroupMemberInfo</c> class
    /// is declared as serializable because each sent message
    /// contains a <c>GroupMemberInfo</c> object. Therefore for
    /// each message the addresser can be detected.
  /// </summary>
  [Serializable]
  public class GroupMemberInfo : IComparable
  {
    
        /// <summary>
        /// The IP address of the machine where
        /// the group member process runs.
      /// </summary>
    private string hostAddress;
    
        /// <summary>
        /// The port number where the
        /// group member listens for incoming
        /// requests.          
        /// </summary>
    private int portNumber;
    
    /// <summary>
        /// The name of the group member.
    /// </summary>
    private string name;
    
    /// <summary>
    /// Creates instances of class 
        /// <c>GroupMemberInfo</c>.
    /// </summary>
    /// <param name="name">The name of the group member.</param>
    /// <param name="host">The host address (IP) of the group member.</param>
    /// <param name="port">The number of the port the group member
        ///             listens for incoming messages.</param>
    public GroupMemberInfo( string name, string host, int port )
    {
      this.name = name;
      this.hostAddress = host;
      this.portNumber = port;
    }
    
        /// <summary>
        /// Returns the name of the group member.
        /// </summary>
        /// <returns>The name of the group member.</returns>
    public string GetName()
    {
      return this.name;      
    }
    
        /// <summary>
        /// Returns the host address of the
        /// group member.
        /// </summary>
        /// <returns>The host address.</returns>
    public string GetHostAddress()
    {
      return this.hostAddress;
    }
    
        /// <summary>
        /// Returns the port number of the group
        /// member.
        /// </summary>
        /// <returns>The port number.</returns>
    public int GetPortNumber()
    {
      return this.portNumber;
    }
    
        /// <summary>
        /// Returns the object in
        /// string representation.
        /// </summary>
        /// <returns>The <c>GroupMemberInfo</c> object in string form.</returns>
    public string ToString()
    {
      return this.name + "|" + this.hostAddress + "|" + this.portNumber;
    }
    
    /// <summary>
    /// <code>GroupMemberInfo</code> instances are
    /// cached in hashtables. Therefore the <code>Equals</code>
    /// and <code>GetHashCode</code> methods have to be
    /// overriden.
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public override bool Equals(object obj)
      {
          GroupMemberInfo gmInfo = (GroupMemberInfo) obj;
          if ( !this.name.Equals( gmInfo.name ) )
              return false;
          if ( !this.hostAddress.Equals( gmInfo.hostAddress ) )
              return false;
          if ( this.portNumber != gmInfo.portNumber )
              return false;
          return true;
      }
    
    /// <summary>
    /// <code>GroupMemberInfo</code> instances are
    /// cached in hashtables. Therefore the <code>Equals</code>
    /// and <code>GetHashCode</code> methods have to be
    /// overriden. 
    /// TODO: This implementation is not very performant. 
    /// Think about better solution!
    /// </summary>
    /// <returns>The hash value.</returns>
    public override int GetHashCode()
      {
      return ( this.name + this.hostAddress + this.portNumber ).GetHashCode() ;
      }
    
    /// <summary>
    /// Compares with other <c>GroupMemberInfo</c> objects.
    /// This method is called by the <c>Sort</c> and
    /// <c>BinarySearch</c> methods of class
    /// <c>Array</c>.
    /// </summary>
    /// <param name="obj">The object which is compared with
    ///   this instance.</param>
    /// <returns>The result of the comparison</returns>
    public int CompareTo( object obj ) {
          if( obj is GroupMemberInfo ) {
              GroupMemberInfo temp = ( GroupMemberInfo ) obj;
  
              return this.ToString().CompareTo( temp.ToString() );
          }
        
          throw new ArgumentException( "object is not a GroupMemberInfo" );    
      }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.