Esempio n. 1
0
		internal void CreateUninitializedItem (string id, int timeout)
		{
			StateServerItem item = new StateServerItem (timeout);
			item.Action = SessionStateActions.InitializeItem;
			LockableStateServerItem cacheItem = new LockableStateServerItem (item);
			Insert (id, cacheItem);
		}
Esempio n. 2
0
        internal void ReleaseItemExclusive(string id, object lockId)
        {
            LockableStateServerItem item = Retrieve(id);

            if (item == null || item.item.LockId != (Int32)lockId)
            {
                return;
            }

            try
            {
                item.rwlock.AcquireWriterLock(lockAcquireTimeout);
                item.item.Locked = false;
            }
            catch
            {
                throw;
            }
            finally
            {
                if (item.rwlock.IsWriterLockHeld)
                {
                    item.rwlock.ReleaseWriterLock();
                }
            }
        }
Esempio n. 3
0
        internal StateServerItem GetItem(string id,
                                         out bool locked,
                                         out TimeSpan lockAge,
                                         out object lockId,
                                         out SessionStateActions actions,
                                         bool exclusive)
        {
            locked  = false;
            lockAge = TimeSpan.MinValue;
            lockId  = Int32.MinValue;
            actions = SessionStateActions.None;

            LockableStateServerItem item = Retrieve(id);

            if (item == null || item.item.IsAbandoned())
            {
                return(null);
            }

            try
            {
                item.rwlock.AcquireReaderLock(lockAcquireTimeout);
                if (item.item.Locked)
                {
                    locked  = true;
                    lockAge = DateTime.UtcNow.Subtract(item.item.LockedTime);
                    lockId  = item.item.LockId;
                    return(null);
                }

                item.rwlock.ReleaseReaderLock();
                if (exclusive)
                {
                    item.rwlock.AcquireWriterLock(lockAcquireTimeout);
                    item.item.Locked     = true;
                    item.item.LockedTime = DateTime.UtcNow;
                    item.item.LockId++;
                    lockId = item.item.LockId;
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (item.rwlock.IsReaderLockHeld)
                {
                    item.rwlock.ReleaseReaderLock();
                }

                if (item.rwlock.IsWriterLockHeld)
                {
                    item.rwlock.ReleaseWriterLock();
                }
            }

            actions = item.item.Action;
            return(item.item);
        }
Esempio n. 4
0
        internal void CreateUninitializedItem(string id, int timeout)
        {
            StateServerItem item = new StateServerItem(timeout);

            item.Action = SessionStateActions.InitializeItem;
            LockableStateServerItem cacheItem = new LockableStateServerItem(item);

            Insert(id, cacheItem);
        }
Esempio n. 5
0
        internal void ResetItemTimeout(string id)
        {
            LockableStateServerItem item = Retrieve(id);

            if (item == null)
            {
                return;
            }
            item.item.Touch();
        }
Esempio n. 6
0
        internal void SetAndReleaseItemExclusive(string id, byte [] collection_data, byte [] sobjs_data,
                                                 object lockId, int timeout, bool newItem)
        {
            Console.WriteLine("RemoteStateServer.SetAndReleaseItemExclusive");
            Console.WriteLine("\tid == {0}", id);
            LockableStateServerItem item = Retrieve(id);
            bool fresh = false;

            if (newItem || item == null)
            {
                Console.WriteLine("\tnew item");
                item             = new LockableStateServerItem(new StateServerItem(collection_data, sobjs_data, timeout));
                item.item.LockId = (Int32)lockId;
                fresh            = true;
            }
            else
            {
                if (item.item.LockId != (Int32)lockId)
                {
                    Console.WriteLine("\tLockId mismatch ({0} != {1})", item.item.LockId, lockId);
                    return;
                }
                Console.WriteLine("\tremoving from cache");
                Remove(id, lockId);
            }

            try {
                Console.WriteLine("\tacquiring writer lock");
                item.rwlock.AcquireWriterLock(lockAcquireTimeout);
                item.item.Locked = false;
                if (!fresh)
                {
                    Console.WriteLine("\tnot fresh = updating data");
                    item.item.CollectionData    = collection_data;
                    item.item.StaticObjectsData = sobjs_data;
                }
                Console.WriteLine("\tInserting in cache");
                Insert(id, item);
            } catch {
                throw;
            } finally {
                if (item.rwlock.IsWriterLockHeld)
                {
                    Console.WriteLine("\treleasing writer lock [finally]");
                    item.rwlock.ReleaseWriterLock();
                }
            }
        }
Esempio n. 7
0
        internal void SetAndReleaseItemExclusive(string id, byte [] collection_data, byte [] sobjs_data,
                                                 object lockId, int timeout, bool newItem)
        {
            LockableStateServerItem item = Retrieve(id);
            bool fresh = false;

            if (newItem || item == null)
            {
                item             = new LockableStateServerItem(new StateServerItem(collection_data, sobjs_data, timeout));
                item.item.LockId = (Int32)lockId;
                fresh            = true;
            }
            else
            {
                if (item.item.LockId != (Int32)lockId)
                {
                    return;
                }
                Remove(id, lockId);
            }

            try
            {
                item.rwlock.AcquireWriterLock(lockAcquireTimeout);
                item.item.Locked = false;
                if (!fresh)
                {
                    item.item.CollectionData    = collection_data;
                    item.item.StaticObjectsData = sobjs_data;
                }
                Insert(id, item);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (item.rwlock.IsWriterLockHeld)
                {
                    item.rwlock.ReleaseWriterLock();
                }
            }
        }
Esempio n. 8
0
		void Insert (string id, LockableStateServerItem item)
		{
			cache.Insert (id, item, null, Cache.NoAbsoluteExpiration, new TimeSpan (0, item.item.Timeout, 0));
		}
Esempio n. 9
0
		internal void SetAndReleaseItemExclusive (string id, byte [] collection_data, byte [] sobjs_data,
							  object lockId, int timeout, bool newItem)
		{
			LockableStateServerItem item = Retrieve (id);
			bool fresh = false;
			
			if (newItem || item == null) {
				item = new LockableStateServerItem (new StateServerItem (collection_data, sobjs_data, timeout));
				item.item.LockId = (Int32)lockId;
				fresh = true;
			} else {
				if (item.item.LockId != (Int32)lockId)
					return;
				Remove (id, lockId);
			}

			try {
				item.rwlock.AcquireWriterLock (lockAcquireTimeout);
				item.item.Locked = false;
				if (!fresh) {
					item.item.CollectionData = collection_data;
					item.item.StaticObjectsData = sobjs_data;
				}
				Insert (id, item);
			} catch {
				throw;
			} finally {
				if (item.rwlock.IsWriterLockHeld)
					item.rwlock.ReleaseWriterLock ();
			}
		}
Esempio n. 10
0
 void Insert(string id, LockableStateServerItem item)
 {
     cache.Insert(id, item, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, item.item.Timeout, 0));
 }
		internal void SetAndReleaseItemExclusive (string id, byte [] collection_data, byte [] sobjs_data,
							  object lockId, int timeout, bool newItem)
		{
			Console.WriteLine ("RemoteStateServer.SetAndReleaseItemExclusive");
			Console.WriteLine ("\tid == {0}", id);
			LockableStateServerItem item = Retrieve (id);
			bool fresh = false;
			
			if (newItem || item == null) {
				Console.WriteLine ("\tnew item");
				item = new LockableStateServerItem (new StateServerItem (collection_data, sobjs_data, timeout));
				item.item.LockId = (Int32)lockId;
				fresh = true;
			} else {
				if (item.item.LockId != (Int32)lockId) {
					Console.WriteLine ("\tLockId mismatch ({0} != {1})", item.item.LockId, lockId);
					return;
				}
				Console.WriteLine ("\tremoving from cache");
				Remove (id, lockId);
			}

			try {
				Console.WriteLine ("\tacquiring writer lock");
				item.rwlock.AcquireWriterLock (lockAcquireTimeout);
				item.item.Locked = false;
				if (!fresh) {
					Console.WriteLine ("\tnot fresh = updating data");
					item.item.CollectionData = collection_data;
					item.item.StaticObjectsData = sobjs_data;
				}
				Console.WriteLine ("\tInserting in cache");
				Insert (id, item);
			} catch {
				throw;
			} finally {
				if (item.rwlock.IsWriterLockHeld) {
					Console.WriteLine ("\treleasing writer lock [finally]");
					item.rwlock.ReleaseWriterLock ();
				}
			}
		}
Esempio n. 12
0
        internal StateServerItem GetItem(string id,
                                         out bool locked,
                                         out TimeSpan lockAge,
                                         out object lockId,
                                         out SessionStateActions actions,
                                         bool exclusive)
        {
            Console.WriteLine("RemoteStateServer.GetItem");
            Console.WriteLine("\tid == {0}", id);
            locked  = false;
            lockAge = TimeSpan.MinValue;
            lockId  = Int32.MinValue;
            actions = SessionStateActions.None;

            LockableStateServerItem item = Retrieve(id);

            if (item == null || item.item.IsAbandoned())
            {
                Console.WriteLine("\tNo item for that id (abandoned == {0})", item != null ? item.item.IsAbandoned() : false);
                return(null);
            }

            try {
                Console.WriteLine("\tacquiring reader lock");
                item.rwlock.AcquireReaderLock(lockAcquireTimeout);
                if (item.item.Locked)
                {
                    Console.WriteLine("\titem is locked");
                    locked  = true;
                    lockAge = DateTime.UtcNow.Subtract(item.item.LockedTime);
                    lockId  = item.item.LockId;
                    return(null);
                }
                Console.WriteLine("\teleasing reader lock");
                item.rwlock.ReleaseReaderLock();
                if (exclusive)
                {
                    Console.WriteLine("\tacquiring writer lock");
                    item.rwlock.AcquireWriterLock(lockAcquireTimeout);
                    Console.WriteLine("\tlocking the item");
                    item.item.Locked     = true;
                    item.item.LockedTime = DateTime.UtcNow;
                    item.item.LockId++;
                    Console.WriteLine("\tnew lock id == {0}", item.item.LockId);
                    lockId = item.item.LockId;
                }
            } catch {
                throw;
            } finally {
                if (item.rwlock.IsReaderLockHeld)
                {
                    Console.WriteLine("\treleasing reader lock [finally]");
                    item.rwlock.ReleaseReaderLock();
                }
                if (item.rwlock.IsWriterLockHeld)
                {
                    Console.WriteLine("\treleasing writer lock [finally]");
                    item.rwlock.ReleaseWriterLock();
                }
            }

            Console.WriteLine("\treturning an item");
            actions = item.item.Action;
            return(item.item);
        }