Exemple #1
0
 /// <summary>
 /// Deserializa os dados na instancia.
 /// </summary>
 /// <param name="reader"></param>
 public void Deserialize(CompactReader reader)
 {
     lock (this)
     {
         this.Value         = reader.ReadObject();
         _flags             = new BitSet(reader.ReadByte());
         _evictionHint      = EvictionHint.ReadEvcHint(reader);
         _expirationHint    = ExpirationHint.ReadExpHint(reader);
         _grpInfo           = GroupInfo.ReadGrpInfo(reader);
         _syncDependency    = reader.ReadObject() as Colosoft.Caching.Synchronization.CacheSyncDependency;
         _queryInfo         = (Hashtable)reader.ReadObject();
         _keysDependingOnMe = (Hashtable)reader.ReadObject();
         _size               = reader.ReadInt32();
         _lockId             = reader.ReadObject();
         _lockDate           = reader.ReadDateTime();
         _version            = reader.ReadUInt64();
         _lockExpiration     = reader.ReadObject() as LockExpiration;
         _creationTime       = reader.ReadDateTime();
         _lastModifiedTime   = reader.ReadDateTime();
         _resyncProviderName = reader.ReadObject() as string;
         _priorityValue      = (CacheItemPriority)reader.ReadInt32();
         _lockManager        = reader.ReadObject() as LockManager;
         _providerName       = reader.ReadObject() as string;
     }
 }
Exemple #2
0
 /// <summary>
 /// Verifica se a entrada está bloqueada.
 /// </summary>
 /// <returns></returns>
 public bool IsItemLocked()
 {
     lock (this)
     {
         return(((LockExpiration == null) || !LockExpiration.HasExpired()) && Flag.IsAnyBitSet(0x40));
     }
 }
Exemple #3
0
        public bool Lock(LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate)
        {
            lock (this)
            {
                if (!this.IsLocked(ref lockId, ref lockDate))
                {
                    this.Flag.SetBit(BitSetConstants.LockedItem);
                    this.LockId         = lockId;
                    this.LockDate       = lockDate;
                    this.LockExpiration = lockExpiration;
                    if (this.LockExpiration != null)
                    {
                        this.LockExpiration.Set();
                    }
                    return(true);
                }
                else
                {
                    lockId   = this.LockId;
                    lockDate = this.LockDate;
                }

                return(false);
            }
        }
 /// <summary>
 /// Realiza um lock no item associado com a chave informada.
 /// </summary>
 /// <param name="key">Chave do item do cache.</param>
 /// <param name="lockExpiration">Informações sobre a expiração do lock.</param>
 /// <param name="lockId">Identificador gerado para o lock.</param>
 /// <param name="lockDate">Data do lock.</param>
 /// <param name="operationContext">Contexto da operação.</param>
 /// <returns>Informações sobre o lock.</returns>
 public override LockOptions Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
 {
     base.Sync.AcquireWriterLock(-1);
     try
     {
         return(this.Internal.Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext));
     }
     finally
     {
         base.Sync.ReleaseWriterLock();
     }
 }
Exemple #5
0
 /// <summary>
 /// Copia os dados do lock para a instancia.
 /// </summary>
 /// <param name="lockId">Identificador do lock.</param>
 /// <param name="lockDate">Data do lock.</param>
 /// <param name="lockExpiration">Data que o lock vai expirar.</param>
 public void CopyLock(object lockId, DateTime lockDate, LockExpiration lockExpiration)
 {
     lock (this)
     {
         if (lockId != null)
         {
             Flag.SetBit(0x40);
         }
         else
         {
             Flag.UnsetBit(0x40);
         }
         LockId         = lockId;
         LockDate       = lockDate;
         LockExpiration = lockExpiration;
     }
 }
Exemple #6
0
        public void CopyLock(object lockId, DateTime lockDate, LockExpiration lockExpiration)
        {
            lock (this)
            {
                if (lockId != null)
                {
                    this.Flag.SetBit(BitSetConstants.LockedItem);
                }
                else
                {
                    this.Flag.UnsetBit(BitSetConstants.LockedItem);
                }

                this.LockId         = lockId;
                this.LockDate       = lockDate;
                this.LockExpiration = lockExpiration;
            }
        }
Exemple #7
0
 /// <summary>
 /// Verifica se a instancia está com lock.
 /// </summary>
 /// <param name="lockId"></param>
 /// <param name="lockDate"></param>
 /// <returns></returns>
 public bool IsLocked(ref object lockId, ref DateTime lockDate)
 {
     lock (this)
     {
         if (this.Flag.IsAnyBitSet(0x40))
         {
             if ((LockExpiration == null) || !LockExpiration.HasExpired())
             {
                 lockId   = this.LockId;
                 lockDate = this.LockDate;
                 return(true);
             }
             this.ReleaseLock();
             return(false);
         }
         return(false);
     }
 }
Exemple #8
0
        protected bool Clustered_Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
        {
            try
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.Lock", "enter");
                }
                Function func = new Function((int)OpCodes.LockKey, new object[] { key, lockId, lockDate, lockExpiration, operationContext }, false);

                RspList results = Cluster.BroadcastToMultiple(Cluster.Servers,
                                                              func,
                                                              GroupRequest.GET_ALL);

                try
                {
                    ClusterHelper.ValidateResponses(results, typeof(LockOptions), Name);
                }
                catch (LockingException le)
                {
                    //release the lock preemptively...
                    Clustered_UnLock(key, null, true, operationContext);
                    return(false);
                }

                return(ClusterHelper.FindAtomicLockStatusReplicated(results, ref lockId, ref lockDate));
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            finally
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.Lock", "exit");
                }
            }
        }
Exemple #9
0
        public bool Lock(LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
        {
            string clientId       = operationContext.GetValueByField(OperationContextFieldName.ClientId) as string;
            int    clientThreadId = operationContext.GetValueByField(OperationContextFieldName.ClientThreadId) != null ? (int)operationContext.GetValueByField(OperationContextFieldName.ClientThreadId) : -1;

            lock (this)
            {
                if (!this.IsLocked(ref lockId, ref lockDate))
                {
                    this.Flag.SetBit(BitSetConstants.LockedItem);
                    this.LockId         = lockId;
                    this.LockDate       = lockDate;
                    this.LockExpiration = lockExpiration;
                    if (this.LockExpiration != null)
                    {
                        this.LockExpiration.Set();
                    }
                    if (!String.IsNullOrEmpty(clientId) && clientThreadId != -1)
                    {
                        this._lockClientId = clientId;
                        this._lockThreadId = clientThreadId;
                        object isRetryOperation = operationContext.GetValueByField(OperationContextFieldName.IsRetryOperation);
                        if (isRetryOperation != null && (Boolean)isRetryOperation)
                        {
                            if (!String.IsNullOrEmpty(clientId) && clientThreadId != -1 &&
                                clientId.Equals(this._lockClientId) && clientThreadId == this._lockThreadId)
                            {
                                return(true);
                            }
                        }
                    }
                    return(true);
                }
                else
                {
                    lockId   = this.LockId;
                    lockDate = this.LockDate;
                }

                return(false);
            }
        }
Exemple #10
0
 /// <summary>
 /// Realiza um lock na instancia.
 /// </summary>
 /// <param name="lockExpiration">Dados sobre a expiração do lock.</param>
 /// <param name="lockId">Identificador do lock gerado.</param>
 /// <param name="lockDate">Data do lock gerado.</param>
 /// <returns>True caso o lock tenha sido criado com sucesso.</returns>
 public bool Lock(LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate)
 {
     lock (this)
     {
         if (!IsLocked(ref lockId, ref lockDate))
         {
             Flag.SetBit(0x40);
             LockId         = lockId;
             LockDate       = lockDate;
             LockExpiration = lockExpiration;
             if (LockExpiration != null)
             {
                 LockExpiration.Set();
             }
             return(true);
         }
         lockId   = LockId;
         lockDate = LockDate;
         return(false);
     }
 }
Exemple #11
0
 public override CacheEntry GetGroup(object key, string group, string subGroup, ref ulong version, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
 {
     if (_grpIndexManager.KeyExists(key, group, subGroup))
     {
         return(this.Get(key, ref version, ref lockId, ref lockDate, lockExpiration, accessType, operationContext));
     }
     return(null);
 }
        public override CacheEntry GetGroup(object key, string group, string subGroup, ref ulong version, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry entry = null;

            base.Sync.AcquireReaderLock(-1);
            try
            {
                entry = this.Internal.GetGroup(key, group, subGroup, ref version, ref lockId, ref lockDate, lockExpiration, accessType, operationContext);
            }
            finally
            {
                base.Sync.ReleaseReaderLock();
            }
            return(entry);
        }
Exemple #13
0
 public virtual CacheEntry GetGroup(object key, string group, string subGroup, ref ulong version, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
 {
     return(null);
 }
 internal override void UpdateLockInfo(object key, object lockId, DateTime lockDate, LockExpiration lockExpiration, OperationContext operationContext)
 {
     base.Sync.AcquireWriterLock(-1);
     try
     {
         this.Internal.UpdateLockInfo(key, lockId, lockDate, lockExpiration, operationContext);
     }
     finally
     {
         base.Sync.ReleaseWriterLock();
     }
 }
        public override CacheEntry Get(object key, bool IsUserOperation, ref ulong version, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry entry = null;

            base.Sync.AcquireWriterLock(-1);
            try
            {
                entry = this.Internal.Get(key, IsUserOperation, ref version, ref lockId, ref lockDate, lockExpiration, accessType, operationContext);
            }
            finally
            {
                base.Sync.ReleaseWriterLock();
            }
            return(entry);
        }
Exemple #16
0
 public virtual CacheEntry Get(object key, bool isUserOperation, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
 {
     return(null);
 }
Exemple #17
0
 internal virtual void UpdateLockInfo(object key, object lockId, DateTime lockDate, LockExpiration lockExpiration, OperationContext operationContext)
 {
 }
Exemple #18
0
 /// <summary>
 /// Retrieve the object from the cache. A string key is passed as parameter.
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <param name="lockId"></param>
 /// <param name="lockDate"></param>
 /// <param name="lockExpiration"></param>
 /// <param name="accessType"></param>
 /// <param name="operationContext"></param>
 /// <returns>cache entry.</returns>
 public virtual CacheEntry Get(object key, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
 {
     lockId   = null;
     lockDate = DateTime.Now;
     return(null);
 }
Exemple #19
0
 public virtual LockOptions Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
 {
     lockId   = null;
     lockDate = DateTime.Now;
     return(null);
 }
Exemple #20
0
        public override CacheEntry GetGroup(object key, string group, string subGroup, ref ulong version, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry entry = this.Internal.GetGroup(key, group, subGroup, ref version, ref lockId, ref lockDate, lockExpiration, accessType, operationContext);

            if ((entry != null) && base.KeepDeflattedValues)
            {
                entry.KeepDeflattedValue(base._context.SerializationContext);
            }
            return(entry);
        }
Exemple #21
0
        /// <summary>
        /// Retrieve the object from the cache. A string key is passed as parameter.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="lockId"></param>
        /// <param name="lockDate"></param>
        /// <param name="lockExpiration"></param>
        /// <param name="accessType"></param>
        /// <param name="operationContext"></param>
        /// <returns>cache entry.</returns>
        public override CacheEntry Get(object key, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry entry = Internal.Get(key, ref lockId, ref lockDate, lockExpiration, accessType, operationContext);

            if (entry != null && KeepDeflattedValues)
            {
                entry.KeepDeflattedValue(_context.SerializationContext);
            }
            return(entry);
        }
Exemple #22
0
 public override LockOptions Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
 {
     return(Internal.Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext));
 }