/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <filterpriority>2</filterpriority> public virtual void Dispose() { if (innerLock != null) { innerLock.Dispose(); innerLock = null; } resource = null; }
/// <summary> /// Extracts the transaction from a DB-ResourceLock object /// </summary> /// <param name="resourceLock">the lock that was recieved from a ConnectionBuffer - Object</param> /// <returns>the transaction that is associated with the current resourcelock</returns> public static ITransaction FindTransaction(this IResourceLock resourceLock) { IResourceLock tmp = resourceLock; while (tmp != null && !(tmp is ITransaction)) { tmp = tmp.InnerLock; } return(tmp as ITransaction); }
} /* End of Function - BlockFor */ /*----------------------- GetFor ----------------------------------------*/ /// <summary> /// Gets the <see cref="IResourceLock"/> associated with the specified /// key value. /// </summary> /// <param name="key"> /// Key to retrieve resource lock for. /// </param> /// <remarks> /// If a resource does not exist for the key, then one will be created. /// </remarks> public virtual IResourceLock GetFor(TKey key) { IResourceLock retval = null; lock (m_lock) { // If the dictionary has the key, grab its value if (m_resourceLocks.ContainsKey(key)) { retval = m_resourceLocks[key]; } // otherwise will need to create a new one else { retval = m_factory.Create(); m_resourceLocks.Add(key, retval); } // end of else } // end of lock - on resources return(retval); } /* End of Function - GetFor */
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <filterpriority>2</filterpriority> public void Dispose() { if (synchronizedObject != null) { try { Exclusive(() => { if (transaction != null) { try { if (!RollbackAtEnd) { transaction.Commit(); } else { transaction.Rollback(); } } finally { transaction = null; } Disposed?.Invoke(this, EventArgs.Empty); if (InnerLock != null) { InnerLock.Dispose(); InnerLock = null; } } }); } finally { synchronizedObject = null; } } }
/// <summary> /// Initializes a new instance of the Transaction class /// </summary> /// <param name="value">the inner value of this transaction</param> /// <param name="synchronizedObject">an object that can be used by the monitor for locking access of specific resources</param> /// <param name="innerLock">an inner lock object that can be used to lock and free objects cascaded</param> public Transaction(IDbTransaction value, object synchronizedObject, IResourceLock innerLock) : this(value, synchronizedObject) { this.InnerLock = innerLock; }
public TimeoutNotifierResourceLock(IResourceLock resLock, TimeSpan timeout) : this(resLock, timeout.Ticks) { }
protected DiagnosticResourceLock(IResourceLock resLock) : this(resLock, false) { }
public RecursionResourceLock(IResourceLock resLock, int maxReaders) : base(resLock) { this.m_ReaderThreadIdsAndRecurseCounts = new RecursionResourceLock.ThreadIdAndRecurseCount[maxReaders]; }
/// <summary> /// Gets an available Database Connection from the pool of available connections /// </summary> /// <param name="useTransaction">indicates whether to begin a transaction for the returned database connection</param> /// <param name="database">the database that is available for usage</param> /// <returns>a connection that is unused at the moment</returns> public IResourceLock AcquireConnection(bool useTransaction, out IDbWrapper database) { string threadId = Thread.CurrentThread.LocalOwner(); DatabaseContainer db; IResourceLock inner = null; while (!disposing) { try { lock (connections) { var tmp = (from t in connections where !t.InUse && !t.Disposed && t.ThreadId == threadId select t).FirstOrDefault (); if (tmp != null) { tmp.InUse = true; tmp.LastUsage = DateTime.Now; } db = tmp; } if (db == null) { db = new DatabaseContainer { Database = factory.LoadPlugin <IDbWrapper>(DataAccessResources.ParallelDummyInstanceName, databaseConstructor, false), LastUsage = DateTime.Now, InUse = true, ThreadId = threadId }; lock (connections) { connections.Add(db); } } if (useTransaction) { inner = db.Database.AcquireTransaction(); } database = db.Database; lock (activeConnectionLock) { activeConnectionCount++; } OnConnectionAcquiring(database); return(new DataBufferResourceLock(this, db, inner)); } catch (Exception ex) { LogEnvironment.LogEvent(ex.Message, LogSeverity.Error, "DataAccess"); } } database = null; return(null); }
public StatisticsGatheringResourceLock(IResourceLock resLock) : base(resLock, false) { }
public StatisticsGatheringResourceLock(IResourceLock resLock, bool isMutualExclusive) : base(resLock, isMutualExclusive) { }
public ThreadSafeCheckerResourceLock(IResourceLock resLock, bool isMutualExclusive) : base(resLock, isMutualExclusive) { }
public ThreadSafeCheckerResourceLock(IResourceLock resLock) : base(resLock, false) { }
protected DiagnosticResourceLock(IResourceLock resLock, bool isMutualExclusive) : base(isMutualExclusive) { this.m_resLock = resLock; this.m_IsMutualExclusive = isMutualExclusive; }
} /* End of Function - GetWaitTimeSpan */ /*----------------------- LockResource ----------------------------------*/ /// <summary> /// Locks resource based on information from the context object /// </summary> /// <param name="context"> /// Context object, to glean repository information from /// </param> protected virtual void LockResource(ResourceExecutingContext context) { Logger.LogTrace("Attempting to lock resource"); Lock = LockManager.BlockFor(GetResourceKey(context), GetWaitTimeSpan()); Logger.LogTrace("Locked on scenario"); } /* End of Function - LockResource */
/// <summary> /// Initializes a new instance of the ResourceLock class /// </summary> /// <param name="resource">the resource to lock for synchronized access</param> /// <param name="innerLock">the inner lock which is to be unlocked as well as soon as this object disposes</param> public ResourceLock(object resource, IResourceLock innerLock) : this(resource) { this.innerLock = innerLock; }
/// <summary> /// Initializes a new instance of the Mutext class /// </summary> /// <param name="name">the name of the named mutex</param> /// <param name="innerLock">the inner lock that will be released together with this mutex</param> public NamedLock(string name, IResourceLock innerLock) : this(name) { InnerLock = innerLock; }
public TimeoutNotifierResourceLock(IResourceLock resLock, long timeout) : base(resLock) { this.m_timeout = timeout; }
/// <summary> /// Initializes a new instance of the DataBufferResourceLock class /// </summary> /// <param name="buffer">The Queue into which to put the connection after disposal of this lock</param> /// <param name="target">The container object used to cache the connection</param> /// <param name="innerLock">the inner lock of this resource lock</param> public DataBufferResourceLock(DatabaseConnectionBuffer buffer, DatabaseContainer target, IResourceLock innerLock) : this(buffer, target) { InnerLock = innerLock; }
/// <summary> /// Initializes a new instance of the ResourceDisposer class /// </summary> /// <param name="resource">the resource that is used for one-time - access</param> /// <param name="innerLock">the inner lock that may lock further objects</param> public ResourceDisposer(IDisposable resource, IResourceLock innerLock) : base(resource, innerLock) { localResource = resource; }