/*********************************************************************/ /* */ /* 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 AgentService.Platform.AMS; using AgentService.Platform.MTS; namespace AgentService.Agent.Runtime { class AMSProxy: MarshalByRefObject, IAMS { # region Members /// /// Reference to the platform AMS /// private IAMS ams; /// /// Gets a copy of the collection of agents registered with the ams /// public AgentDescriptionCollection RegisteredAgents { get { return this.ams.RegisteredAgents; } } /// /// Gets the White Pages service. /// public IWhitePagesServer WhitePages { get { return this.ams.WhitePages; } } # endregion #region Constructor /// /// AMSProxy Constructor. Set the ams reference to the passed object /// /// the AMS to be referenced public AMSProxy(IAMS obj) { this.ams = obj; } #endregion # region Manage Agent SetUp and Registration /// /// Initites and register the created agent with the AMS. /// /// Agent. /// the configfile of the Agent /// List of value to inizialize Agent's attribute /// persistence flag /// domain flag /// public void Register(AgentService.Agent.IAgent agent, string configFile, bool bPersist) { this.ams.Register(agent, configFile, bPersist); } /// /// Starts agent activity /// /// agent identifier to be started public void Activate(AID aid) { this.ams.Activate(aid); } /// /// Starts the activity of all the registered agents /// public void ActivateAll() { this.ams.ActivateAll(); } /// /// Puts the agent in the previous persisted state. /// /// Agent. public void Resume(AgentService.Agent.IAgent agent) { this.ams.Resume(agent); } /// /// Deregister a specific Agent. Deregistration /// implies the removal of the agent object from /// the collection of managed agents /// /// The Agent's AID public bool Deregister(AID aid, bool bDestroy) { return this.ams.Deregister(aid, bDestroy); } # endregion #region Override /// /// Loads agent data from its persisted version /// /// Persisted version of the agent. public void ResumeFrom(AgentPersistent persistent) { this.ams.ResumeFrom(persistent); } #endregion # region Manage Agent State /// /// Put Agent in active state after transition /// /// The persisted version of the agent public void Execute(AID aid) { this.ams.Execute(aid); } // MOD: 21/07/2006 Simone Belotti: changed the Move method to support timeout value /// /// Put Agent in the transit state before its migration /// /// The Agent's AID /// The name of the destination platform /// Flag that indicates if the request to move /// the agent was originated by the platform /// (i.e. load balancing motivation), or it /// was originated by the agent itself public void Move(AID aid, string destination,TimeSpan timeout, bool bIsSystemRequest) { this.ams.Move(aid, destination,timeout, bIsSystemRequest); } /// /// Put the Agent in the active state after its suspention /// /// The Agent's AID /// true if operation succeds public bool ResumeAgent(AID aid) { return this.ams.ResumeAgent(aid); } /// /// Puts Agent in the suspended state /// /// The Agent's AID /// true if operation succeds public bool Suspend(AID aid) { return this.ams.Suspend(aid); } /// /// Suspends all the active agents /// public void SuspendAll() { this.ams.SuspendAll(); } /// /// Stops the agent activity /// /// agent identifier /// public bool StopAgent(AID aid) { return this.ams.StopAgent(aid); } /// /// Kill the Agent putting it in the unknown state /// /// the Agent's AID /// true if operation succeds public bool Destroy(AID aid) { return this.ams.Destroy(aid); } /// /// Kill all agents putting it in the unknown state /// public void DestroyAll() { this.ams.DestroyAll(); } /// /// Puts Agent in the active state from the waiting state /// /// The Agent's AID /// True if operation succeds public bool WakeUp(AID aid) { return this.ams.WakeUp(aid); } /// /// Put Agent in the active state from the waiting state /// public void WakeUpAll() { this.ams.WakeUpAll(); } # endregion #region CallBacks /// /// Handler of messages directed to the AMS /// /// public void DispatchMessage(AgentMessage msg) { this.ams.DispatchMessage(msg); } /// /// Delegate: invoked when the agentTransferred event is raised. It /// creates the received agent and resumes from the persisted version. The /// agent is added in the agentsToExecute list. It sends /// a message to the remote AMS to inform it of completion of the operation, /// either it is succesfull or not. /// /// Received persisted version of the agent /// Ticket owned by the transferred agent. Parameter for an internal check public void ResumeAgentTransferred(AgentService.Agent.AgentPersistent persistedAgent, int ticket) { this.ResumeAgentTransferred(persistedAgent, ticket); } #endregion } }