From 12042cdc2b53e581ace6a017d9b17bd763a544b2 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Mon, 20 Oct 2008 18:07:06 +0000 Subject: From: Alan Webb cleanups and assorted fixes to REST inventory, asset, and appearance services. --- .../Rest/Inventory/RestInventoryServices.cs | 87 +++++++++++++++++++--- 1 file changed, 76 insertions(+), 11 deletions(-) (limited to 'OpenSim/ApplicationPlugins/Rest/Inventory/RestInventoryServices.cs') diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RestInventoryServices.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RestInventoryServices.cs index 9cbbf0c..003c6ee 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/RestInventoryServices.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RestInventoryServices.cs @@ -31,6 +31,7 @@ using System.IO; using System.Threading; using System.Xml; using System.Drawing; +using System.Timers; using OpenSim.Framework; using OpenSim.Framework.Servers; using OpenSim.Framework.Communications; @@ -61,6 +62,20 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory Rest.Log.InfoFormat("{0} Inventory services initializing", MsgId); Rest.Log.InfoFormat("{0} Using REST Implementation Version {1}", MsgId, Rest.Version); + // This is better than a null reference. + + if (Rest.InventoryServices == null) + throw new Exception(String.Format("{0} OpenSim inventory services are not available", + MsgId)); + + if (Rest.UserServices == null) + throw new Exception(String.Format("{0} OpenSim user services are not available", + MsgId)); + + if (Rest.AssetServices == null) + throw new Exception(String.Format("{0} OpenSim asset services are not available", + MsgId)); + // If a relative path was specified for the handler's domain, // add the standard prefix to make it absolute, e.g. /admin @@ -167,9 +182,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory try { - // digest scheme seems borked: disable it for the time - // being - rdata.scheme = Rest.AS_BASIC; if (!rdata.IsAuthenticated) { rdata.Fail(Rest.HttpStatusCodeNotAuthorized,String.Format("user \"{0}\" could not be authenticated", rdata.userName)); @@ -283,12 +295,22 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory Rest.Log.DebugFormat("{0} Inventory catalog requested for {1} {2}", MsgId, rdata.userProfile.FirstName, rdata.userProfile.SurName); - lock (rdata) + + lock (rdata) + { + if (!rdata.HaveInventory) + { + rdata.startWD(1000); + rdata.timeout = false; + Monitor.Wait(rdata); + } + } + + if (rdata.timeout) { - if (!rdata.HaveInventory) - { - Monitor.Wait(rdata); - } + Rest.Log.WarnFormat("{0} Inventory not available for {1} {2}. No response from service.", + MsgId, rdata.userProfile.FirstName, rdata.userProfile.SurName); + rdata.Fail(Rest.HttpStatusCodeServerError, "inventory server not responding"); } if (rdata.root == null) @@ -2145,12 +2167,50 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory internal ICollection items = null; internal UserProfileData userProfile = null; internal InventoryFolderBase root = null; + internal bool timeout = false; + internal System.Timers.Timer watchDog = new System.Timers.Timer(); internal InventoryRequestData(OSHttpRequest request, OSHttpResponse response, string prefix) : base(request, response, prefix) { } + internal void startWD(double interval) + { + Rest.Log.DebugFormat("{0} Setting watchdog", MsgId); + watchDog.Elapsed += new ElapsedEventHandler(OnTimeOut); + watchDog.Interval = interval; + watchDog.AutoReset = false; + watchDog.Enabled = true; + watchDog.Start(); + } + + internal void stopWD() + { + Rest.Log.DebugFormat("{0} Reset watchdog", MsgId); + watchDog.Stop(); + } + + /// + /// This is the callback method required by the inventory watchdog. The + /// requestor issues an inventory request and then blocks until the + /// request completes, or this method signals the monitor. + /// + + private void OnTimeOut(object sender, ElapsedEventArgs args) + { + Rest.Log.DebugFormat("{0} Asynchronous inventory update timed-out", MsgId); + // InventoryRequestData rdata = (InventoryRequestData) sender; + lock (this) + { + this.folders = null; + this.items = null; + this.HaveInventory = false; + this.timeout = true; + Monitor.Pulse(this); + } + } + /// /// This is the callback method required by inventory services. The /// requestor issues an inventory request and then blocks until this @@ -2160,11 +2220,16 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory internal void GetUserInventory(ICollection folders, ICollection items) { Rest.Log.DebugFormat("{0} Asynchronously updating inventory data", MsgId); - this.folders = folders; - this.items = items; - this.HaveInventory = true; lock (this) { + if (watchDog.Enabled) + { + this.stopWD(); + } + this.folders = folders; + this.items = items; + this.HaveInventory = true; + this.timeout = false; Monitor.Pulse(this); } } -- cgit v1.1