aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs66
1 files changed, 57 insertions, 9 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
index 391326f..468dccf 100644
--- a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
+++ b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
@@ -28,10 +28,12 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection; 30using System.Reflection;
31using System.Threading;
31using Nini.Config; 32using Nini.Config;
32using log4net; 33using log4net;
33using OpenMetaverse; 34using OpenMetaverse;
34using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Framework.Monitoring;
35using OpenSim.Region.Framework.Interfaces; 37using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes; 38using OpenSim.Region.Framework.Scenes;
37 39
@@ -45,9 +47,14 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
45 private Scene m_scene; 47 private Scene m_scene;
46 private Dictionary<string, FileData> NewFiles = new Dictionary<string, FileData>(); 48 private Dictionary<string, FileData> NewFiles = new Dictionary<string, FileData>();
47 private Dictionary<ulong, XferDownLoad> Transfers = new Dictionary<ulong, XferDownLoad>(); 49 private Dictionary<ulong, XferDownLoad> Transfers = new Dictionary<ulong, XferDownLoad>();
48 private double lastFilesExpire = 0;
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 51
52
53 private object timeTickLock = new object();
54 private double lastTimeTick = 0.0;
55 private bool inTimeTick = false;
56 private double lastFilesExpire = 0.0;
57
51 public struct XferRequest 58 public struct XferRequest
52 { 59 {
53 public IClientAPI remoteClient; 60 public IClientAPI remoteClient;
@@ -67,20 +74,22 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
67 74
68 public void Initialise(IConfigSource config) 75 public void Initialise(IConfigSource config)
69 { 76 {
70 lastFilesExpire = Util.GetTimeStampMS() + 300000.0; 77 lastTimeTick = Util.GetTimeStampMS() + 30000.0;
78 lastFilesExpire = lastTimeTick + 180000.0;
71 } 79 }
72 80
73 public void AddRegion(Scene scene) 81 public void AddRegion(Scene scene)
74 { 82 {
75 m_scene = scene; 83 m_scene = scene;
76 m_scene.EventManager.OnNewClient += NewClient; 84 m_scene.EventManager.OnNewClient += NewClient;
77 85 m_scene.EventManager.OnRegionHeartbeatEnd += OnTimeTick;
78 m_scene.RegisterModuleInterface<IXfer>(this); 86 m_scene.RegisterModuleInterface<IXfer>(this);
79 } 87 }
80 88
81 public void RemoveRegion(Scene scene) 89 public void RemoveRegion(Scene scene)
82 { 90 {
83 m_scene.EventManager.OnNewClient -= NewClient; 91 m_scene.EventManager.OnNewClient -= NewClient;
92 m_scene.EventManager.OnRegionHeartbeatEnd -= OnTimeTick;
84 93
85 m_scene.UnregisterModuleInterface<IXfer>(this); 94 m_scene.UnregisterModuleInterface<IXfer>(this);
86 m_scene = null; 95 m_scene = null;
@@ -106,6 +115,35 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
106 115
107 #endregion 116 #endregion
108 117
118 public void OnTimeTick(Scene scene)
119 {
120 // we are on a heartbeat thread we there can be several
121 if(Monitor.TryEnter(timeTickLock))
122 {
123 if(!inTimeTick)
124 {
125 double now = Util.GetTimeStampMS();
126 if(now - lastTimeTick > 1500.0) // 1.5 second
127 {
128 inTimeTick = true;
129
130 //don't overload busy heartbeat
131 WorkManager.RunInThread(
132 delegate
133 {
134 transfersTimeTick(now);
135 expireFiles(now);
136
137 lastTimeTick = now;
138 inTimeTick = false;
139 },
140 null,
141 "XferTimeTick");
142 }
143 }
144 Monitor.Exit(timeTickLock);
145 }
146 }
109 #region IXfer Members 147 #region IXfer Members
110 148
111 /// <summary> 149 /// <summary>
@@ -135,26 +173,31 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
135 fd.timeStampMS = now; 173 fd.timeStampMS = now;
136 NewFiles.Add(fileName, fd); 174 NewFiles.Add(fileName, fd);
137 } 175 }
176 }
177 return true;
178 }
138 179
139 // lazy expires hopefully we will not have many files so nasty code will do it 180 #endregion
140 if(now - lastFilesExpire > 180000.0) 181 public void expireFiles(double now)
182 {
183 lock (NewFiles)
184 {
185 // hopefully we will not have many files so nasty code will do it
186 if(now - lastFilesExpire > 120000.0)
141 { 187 {
142 lastFilesExpire = now; 188 lastFilesExpire = now;
143 List<string> expires = new List<string>(); 189 List<string> expires = new List<string>();
144 foreach(string fname in NewFiles.Keys) 190 foreach(string fname in NewFiles.Keys)
145 { 191 {
146 if(NewFiles[fname].refsCount == 0 && now - NewFiles[fname].timeStampMS > 180000.0) 192 if(NewFiles[fname].refsCount == 0 && now - NewFiles[fname].timeStampMS > 120000.0)
147 expires.Add(fname); 193 expires.Add(fname);
148 } 194 }
149 foreach(string fname in expires) 195 foreach(string fname in expires)
150 NewFiles.Remove(fname); 196 NewFiles.Remove(fname);
151 } 197 }
152 } 198 }
153 return true;
154 } 199 }
155 200
156 #endregion
157
158 public void NewClient(IClientAPI client) 201 public void NewClient(IClientAPI client)
159 { 202 {
160 client.OnRequestXfer += RequestXfer; 203 client.OnRequestXfer += RequestXfer;
@@ -162,6 +205,11 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
162 client.OnAbortXfer += AbortXfer; 205 client.OnAbortXfer += AbortXfer;
163 } 206 }
164 207
208 public void transfersTimeTick(double now)
209 {
210
211 }
212
165 /// <summary> 213 /// <summary>
166 /// 214 ///
167 /// </summary> 215 /// </summary>