/*********************************************************************/ /* */ /* AgentService Framework */ /* www.agentservice.it */ /* */ /* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */ /* GNU Lesser General Public License */ /* */ /* This library is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU Lesser General Public */ /* License as published by the Free Software Foundation, */ /* version 2.1 of the License. */ /* */ /* This library is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ /* Lesser General Public License for more details. */ /* */ /* You should have received a copy of the GNU Lesser General Public */ /* License along with this library; if not, write to the */ /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ /* Boston, MA 02111-1307, USA. */ /* */ /*********************************************************************/ using System; using System.Collections.Specialized; using System.Runtime.Serialization; using AgentService.Interop; using System.Collections.Generic; namespace AgentService.Platform.AMS { /// /// Class AID. Agent Identifier. An agent identifier is a gloablly unique identifier /// associated to a given agent. An agent identifier is composed by: /// - agent name: a symbolic name of the agent /// - platform name: the symbolic name of the platform where the agent is deployed /// - a list of addresses where the agent can be contacted /// - a list of resolvers AID that know how to contact the agent /// An agent is also characterized by a a global name in the form: /// [agent-name]@[platform-name] /// [Serializable] [DataContract] public class AID { #region Core Agents Canonical Names /// /// Canonical name of the AMS. /// public static readonly string AMS = "ams"; /// /// Canonical name of the MTS. /// public static readonly string MTS = "mts"; /// /// Canonical name of the DF. /// public static readonly string DF = "df"; #endregion # region AID Members /// /// Symbolic name of the agent. /// private string name; /// /// Gets the symbolic name of the agent. /// [DataMember] public string Name { get { return this.name; } set { name = value; } } /// /// Gets the Agent's name with platform extention. /// public string GlobalName { get { return this.name + "@" + this.hapName; } } /// /// Name of the owining platform. /// private string hapName; /// /// Gets the name of the owning platform. /// [DataMember] public string HapName { get { return this.hapName; } set { hapName = value; } } //MOD 19/04/2006: Marco Garr added bdomain and domainName to support AppDomain /// /// Created in domain flag /// private bool bdomain; /// /// Gets the domain flag /// [DataMember] public bool RequireDomain { get { return this.bdomain; } set { bdomain = value; } } /// /// Name of the domainName /// private string domainName; /// /// Gets the name of the AppDomain in which the Agent is created /// [DataMember] public string DomainName { get { return this.domainName; } set { domainName = value; } } /// /// A sequence of ordered transport addresses where the agent can be contacted /// The order implies a preference relation of the agent to receive messages over that address. /// private List addresses; /// /// Gets the addresses where the agent can be contacted. /// [DataMember] public List Addresses { get { return this.addresses; } set { addresses = value; } } /// /// A sequence of AIDs at which the AID of the agent can ultimately be resolved into a transport /// address or set of transport address. /// The order implies a preference relation of the agent to be resolved over that address. /// private AIDCollection resolvers; /// /// Gets the resolvers addresses where the agent can be contacted. A resolver is an entity that /// knows how to contact the agent and forwards him the messages. /// [DataMember] public AIDCollection Resolvers { get { return this.resolvers; } set { resolvers = value; } } # endregion # region Constructor /// /// Constructs an AID with empty addresses and empty resolver addresses. /// public AID() { this.addresses = new List(); this.resolvers = new AIDCollection(); // MOD: 17/07/2006 Simone Belotti: added support for bDomain, DomainName this.bdomain = false; this.domainName = string.Empty; } /// /// Constructs an AID with a given name, and empty addresses and resolver addresses. /// /// agent's name /// name of the owning Platform public AID(string agentName, string hapName) { this.addresses = new List(); this.resolvers = new AIDCollection(); this.name = agentName; this.hapName = hapName; // MOD: 17/07/2006 Simone Belotti: added support for bDomain, DomainName this.bdomain = false; this.domainName = string.Empty; } //MOD: 19/04/2006: Marco Garr: added a new constructor to support AppDomain /// /// Constructs an AID with a given name, and empty addresses and resolver addresses. /// /// agent's name /// name of the owning Platform /// domain flag /// the name of the AppDomain in which the agent is created public AID(string agentName, string hapName, bool bDomain, string domainName) { this.addresses = new List(); this.resolvers = new AIDCollection(); this.name = agentName; this.hapName = hapName; this.bdomain = bDomain; this.domainName = domainName; } //Added by Passa, in order to support the transport profile. /// /// Constructs an AID with a given name, and empty addresses and resolver addresses. /// /// agent's name /// name of the owning Platform /// domain flag /// the name of the AppDomain in which the agent is created /// the transport profile of the platform public AID(string agentName, string hapName, bool bDomain, string domainName, string address) { this.addresses = new List(); this.resolvers = new AIDCollection(); this.name = agentName; this.hapName = hapName; this.bdomain = bDomain; this.domainName = domainName; this.addresses.Add(address); } /// /// Constructs an AID with a given name, and a given resolver AID. /// /// agent's name /// agent's resolvers public AID(string agentName,AID resolver) { this.addresses = new List(); this.resolvers = new AIDCollection(); this.name = agentName; this.resolvers.Add(resolver); // MOD: 17/07/2006 Simone Belotti: added support for bDomain, DomainName this.bdomain = false; this.domainName = string.Empty; } /// /// Constructs an AID with a given name, a given address, and a given resolver AID. /// /// agent's name /// agent's address /// agent's resolvers public AID(string agentName,string address,AID resolver) { this.addresses = new List(); this.resolvers = new AIDCollection(); this.name = agentName; this.resolvers.Add(resolver); this.addresses.Add(address); // MOD: 17/07/2006 Simone Belotti: added support for bDomain, DomainName this.bdomain = false; this.domainName = string.Empty; } /// /// Constructs an AID with a given name, a given address, a given resolver AID, /// and the platform name where the agent will be deployed. /// /// agent's name /// agent's address /// agent's resolvers /// platform where the agent will be deployed public AID(string agentName,string address,AID resolver,string hapName) { this.addresses = new List(); this.resolvers = new AIDCollection(); this.name = agentName; this.resolvers.Add(resolver); this.addresses.Add(address); this.hapName = hapName; // MOD: 17/07/2006 Simone Belotti: added support for bDomain, DomainName this.bdomain = false; this.domainName = string.Empty; } # endregion # region Manage Members /// /// Sets the name of the platform the agent belongs to. /// /// platform name internal void SetPlatformName(string hapName) { if (hapName == null) throw new ArgumentNullException("hapName", "platform name cannot be null"); this.hapName = hapName; } /// /// Compares two AID objects by looking at their gloabal names. /// /// AID to compare to /// true, if the two global name are lexicographically equivalent (case sensitive) public override bool Equals(object obj) { AID aid = obj as AID; if (aid == null) return false; return (this.GlobalName.CompareTo(aid.GlobalName) == 0); } /// /// Gets the hash code for the given AID instance. /// /// hash code of the global name string public override int GetHashCode() { return this.GlobalName.GetHashCode(); } # endregion } }