Ejemplo n.º 1
0
 private static void AddHintToDependency(Dependency dependency, ExpirationHint hint)
 {
     if (hint is Alachisoft.NCache.Caching.AutoExpiration.KeyDependency)
     {
         dependency.keyDep.Add(GetKeyDependency((Alachisoft.NCache.Caching.AutoExpiration.KeyDependency)hint));
     }
     else if (hint is Alachisoft.NCache.Caching.AutoExpiration.FileDependency)
     {
         dependency.fileDep.Add(GetFileDependency((Alachisoft.NCache.Caching.AutoExpiration.FileDependency)hint));
     }
     else if (hint is OleDbCacheDependency)
     {
         dependency.oleDbDep.Add(GetOleDbDependency((OleDbCacheDependency)hint));
     }
     else if (hint is Sql7CacheDependency)
     {
         dependency.sql7Dep.Add(GetSql7Dependency((Sql7CacheDependency)hint));
     }
     else if (hint is OracleCacheDependency)
     {
         dependency.oracleDep.Add(GetOracleDependency((OracleCacheDependency)hint));
     }
     else if (hint is SqlYukonCacheDependency)
     {
         dependency.yukonDep.Add(GetYukonDependency((SqlYukonCacheDependency)hint));
     }
     else if (hint is NosDBCacheDependency)
     {
         dependency.NosDep.Add(GetNosDBDependency((NosDBCacheDependency)hint));
     }
 }
Ejemplo n.º 2
0
        void ICompactSerializable.Serialize(CompactWriter writer)
        {
            lock (this)
            {
                writer.WriteObject(Value);
                writer.Write(_bitset.Data);
                EvictionHint.WriteEvcHint(writer, _evh);
                ExpirationHint.WriteExpHint(writer, _exh);
                GroupInfo.WriteGrpInfo(writer, _grpInfo);

                writer.WriteObject(_syncDependency);

                writer.WriteObject(_queryInfo);
                writer.WriteObject(_keysDependingOnMe);
                writer.Write(_size);
                writer.WriteObject(lockMetaInfo);
                writer.Write(_version);
                writer.Write(_creationTime);
                writer.Write(_lastModifiedTime);
                writer.WriteObject(ResyncProviderName);
                writer.Write((int)_priorityValue);
                writer.WriteObject(ProviderName);

                writer.WriteObject(this._type);
                writer.WriteObject(_itemUpdateListener);
                writer.WriteObject(_itemRemovedListener);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Serializa os dados da instancia.
 /// </summary>
 /// <param name="writer"></param>
 public void Serialize(CompactWriter writer)
 {
     lock (this)
     {
         writer.WriteObject(this.Value);
         writer.Write(_flags.Data);
         EvictionHint.WriteEvcHint(writer, _evictionHint);
         ExpirationHint.WriteExpHint(writer, _expirationHint);
         GroupInfo.WriteGrpInfo(writer, _grpInfo);
         writer.WriteObject(_syncDependency);
         writer.WriteObject(_queryInfo);
         writer.WriteObject(_keysDependingOnMe);
         writer.Write(_size);
         writer.WriteObject(_lockId);
         writer.Write(_lockDate);
         writer.Write(_version);
         writer.WriteObject(_lockExpiration);
         writer.Write(_creationTime);
         writer.Write(_lastModifiedTime);
         writer.WriteObject(_resyncProviderName);
         writer.Write((int)_priorityValue);
         writer.WriteObject(_lockManager);
         writer.WriteObject(_providerName);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Add the object to the cluster. Does load balancing as well.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <returns>cache entry.</returns>
        /// <remarks>
        /// This method either invokes <see cref="handleAdd"/> on one of the server nodes in the cluster,
        /// or invokes <see cref="Local_Add"/> locally.
        /// </remarks>
        protected bool Clustered_Add(ArrayList dests, object key, ExpirationHint eh, OperationContext operationContext)
        {
            bool result = false;

            try
            {
                /// Ask every server to add the object, except myself.
                Function func    = new Function((int)OpCodes.AddHint, new object[] { key, eh, operationContext }, false, key);
                RspList  results = Cluster.BroadcastToMultiple(dests,
                                                               func,
                                                               GroupRequest.GET_ALL, _asyncOperation);

                ClusterHelper.ValidateResponses(results, typeof(bool), Name);

                /// Check if the operation failed on any node.
                result = ClusterHelper.FindAtomicAddHintReplicated(results);
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            return(result);
        }
Ejemplo n.º 5
0
        public CompactCacheEntry(object key, object value, ExpirationHint dependency,
                                 long expiration,
                                 byte options, object itemRemovedCallback, string group, string subgroup, Hashtable queryInfo, BitSet Flag, object lockId, ulong version, LockAccessType accessType, string providername, string resyncProviderName, Notifications callbackEntry)
        {
            _key   = key;
            _flag  = Flag;
            _value = value;

            _dependency          = dependency;
            _expiration          = expiration;
            _options             = options;
            _itemRemovedCallback = itemRemovedCallback;
            if (group != null)
            {
                _group = group;
                if (subgroup != null)
                {
                    _subgroup = subgroup;
                }
            }
            _queryInfo = queryInfo;

            _lockId             = lockId;
            _accessType         = accessType;
            _version            = version;
            _providerName       = providername;
            _resyncProviderName = resyncProviderName;
            _callbackEntry      = callbackEntry;
        }
Ejemplo n.º 6
0
        void ICompactSerializable.Deserialize(CompactReader reader)
        {
            lock (this)
            {
                Value    = reader.ReadObject();
                _bitset  = new BitSet(reader.ReadByte());
                _evh     = EvictionHint.ReadEvcHint(reader);
                _exh     = ExpirationHint.ReadExpHint(reader);
                _grpInfo = GroupInfo.ReadGrpInfo(reader);

                _syncDependency = reader.ReadObject() as CacheSyncDependency;

                _queryInfo         = (Hashtable)reader.ReadObject();
                _keysDependingOnMe = (HashVector)reader.ReadObject();
                _size        = reader.ReadInt64();
                lockMetaInfo = reader.ReadObject() as LockMetaInfo;

                _version           = reader.ReadUInt64();
                _creationTime      = reader.ReadDateTime();
                _lastModifiedTime  = reader.ReadDateTime();
                ResyncProviderName = reader.ReadObject() as string;
                _priorityValue     = (CacheItemPriority)reader.ReadInt32();
                ProviderName       = reader.ReadObject() as string;
                _type = reader.ReadObject() as string;
                _itemUpdateListener  = reader.ReadObject() as ArrayList;
                _itemRemovedListener = reader.ReadObject() as ArrayList;
            }
        }
Ejemplo n.º 7
0
        internal override void TouchInternal(string key, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("LocalCache.Touch", "");
            }

            if (_cacheStore == null)
            {
                throw new InvalidOperationException();
            }

            CacheEntry e = (CacheEntry)_cacheStore.Get(key);

            if (e != null)
            {
                EvictionHint evh = e.EvictionHint;
                if (_evictionPolicy != null && evh != null && evh.IsVariant)
                {
                    _evictionPolicy.Notify(key, evh, null);
                }
                ExpirationHint exh = e.ExpirationHint;
                if (exh != null && exh.IsVariant)
                {
                    try
                    {
                        _context.ExpiryMgr.ResetVariant(exh);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
Ejemplo n.º 8
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;
     }
 }
Ejemplo n.º 9
0
        internal override bool AddInternal(object key, ExpirationHint expirationHint, OperationContext operationContext)
        {
            if (_cacheStore == null)
            {
                throw new InvalidOperationException();
            }
            CacheEntry item = (CacheEntry)_cacheStore.Get(key);

            if (item == null)
            {
                return(false);
            }
            if (item.ExpirationHint == null)
            {
                item.ExpirationHint = expirationHint;
            }
            else if (item.ExpirationHint is AggregateExpirationHint)
            {
                ((AggregateExpirationHint)item.ExpirationHint).Add(expirationHint);
            }
            else
            {
                AggregateExpirationHint hint = new AggregateExpirationHint();
                hint.Add(item.ExpirationHint);
                hint.Add(expirationHint);
                item.ExpirationHint = hint;
            }
            _cacheStore.Insert(key, item);
            item.LastModifiedTime = DateTime.Now;
            return(true);
        }
Ejemplo n.º 10
0
        internal override bool RemoveInternal(object key, ExpirationHint eh)
        {
            if (_cacheStore == null)
            {
                throw new InvalidOperationException();
            }
            CacheEntry item = (CacheEntry)_cacheStore.Get(key);

            if ((item == null) || (item.ExpirationHint == null))
            {
                return(false);
            }
            if (item.ExpirationHint is AggregateExpirationHint)
            {
                AggregateExpirationHint hint           = new AggregateExpirationHint();
                AggregateExpirationHint expirationHint = (AggregateExpirationHint)item.ExpirationHint;
                foreach (ExpirationHint hint3 in expirationHint)
                {
                    if (!hint3.Equals(eh))
                    {
                        hint.Add(hint3);
                    }
                }
                item.ExpirationHint = hint;
            }
            else if (item.ExpirationHint.Equals(eh))
            {
                item.ExpirationHint = null;
            }
            _cacheStore.Insert(key, item);
            item.LastModifiedTime = DateTime.Now;
            return(true);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Add the ExpirationHint to a specfied node in the cluster.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <returns>cache entry.</returns>
        /// <remarks>
        /// This method either invokes <see cref="handleAdd"/> on every server-node in the cluster.
        /// </remarks>
        protected bool Clustered_Add(Address dest, object key, ExpirationHint eh, OperationContext operationContext)
        {
            bool retVal = false;

            try
            {
                Function func   = new Function((int)OpCodes.AddHint, new object[] { key, eh, operationContext });
                object   result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST);
                if (result == null)
                {
                    return(retVal);
                }
                retVal = (bool)result;
            }
            catch (StateTransferException e)
            {
                throw;
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            return(retVal);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="val">the object to be added to the cache</param>
        /// <param name="expiryHint">expiration hint for the object</param>
        /// <param name="evictionHint">eviction hint for the object</param>
        public CacheEntry(object val, ExpirationHint expiryHint, EvictionHint evictionHint)
            : base(val)
        {
            _exh = expiryHint;
            _evh = evictionHint;
            _bitset.SetBit(FLATTENED);

            _creationTime     = System.DateTime.Now;
            _lastModifiedTime = System.DateTime.Now;
        }
Ejemplo n.º 13
0
 public void Reset()
 {
     _key                 = null;
     _value               = null;
     _dependency          = null;
     _expiration          = 0;
     _options             = 0;
     _itemRemovedCallback = null;
     _queryInfo           = null;
 }
Ejemplo n.º 14
0
 public void Deserialize(CompactReader reader)
 {
     _key                 = reader.ReadObject();
     _value               = reader.ReadObject();
     _expiration          = reader.ReadInt64();
     _dependency          = ExpirationHint.ReadExpHint(reader);
     _options             = reader.ReadByte();
     _itemRemovedCallback = reader.ReadObject();
     _queryInfo           = (Hashtable)reader.ReadObject();
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="key"></param>
 /// <param name="exh"></param>
 /// <param name="evh"></param>
 /// <param name="compressionThreshold"></param>
 /// <param name="groupInfo"></param>
 /// <param name="queryInfo"></param>
 /// <param name="resyncProviderName"></param>
 public CacheResyncTask(DatasourceMgr parent, string key, ExpirationHint exh, EvictionHint evh, long compressionThreshold, GroupInfo groupInfo, Hashtable queryInfo, string resyncProviderName)
 {
     _parent             = parent;
     _key                = key;
     _exh                = exh;
     _evh                = evh;
     _groupInfo          = groupInfo;
     _queryInfo          = queryInfo;
     _resyncProviderName = resyncProviderName;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Add ExpirationHint against the given key
        /// Key must already exists in the cache
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eh"></param>
        /// <returns></returns>
        public override bool Add(object key, ExpirationHint eh, OperationContext operationContext)
        {
            bool result = false;

            if (Internal != null)
            {
                result = Internal.Add(key, eh, operationContext);
            }
            return(result);
        }
Ejemplo n.º 17
0
        public override bool Add(object key, ExpirationHint eh, OperationContext operationContext)
        {
            bool flag = false;

            if (this.Internal != null)
            {
                CacheEntry entry = new CacheEntry();
                entry.ExpirationHint = eh;
                object[] keysIAmDependingOn = entry.KeysIAmDependingOn;
                if (keysIAmDependingOn != null)
                {
                    Hashtable hashtable = this.Contains(keysIAmDependingOn, operationContext);
                    if (!hashtable.ContainsKey("items-found"))
                    {
                        throw new OperationFailedException("One of the dependency keys does not exist.");
                    }
                    if (hashtable["items-found"] == null)
                    {
                        throw new OperationFailedException("One of the dependency keys does not exist.");
                    }
                    if (((ArrayList)hashtable["items-found"]).Count != keysIAmDependingOn.Length)
                    {
                        throw new OperationFailedException("One of the dependency keys does not exist.");
                    }
                }
                flag = this.Internal.Add(key, eh, operationContext);
                if (!flag || (keysIAmDependingOn == null))
                {
                    return(flag);
                }
                var table = new Hashtable();
                for (int i = 0; i < keysIAmDependingOn.Length; i++)
                {
                    if (table[keysIAmDependingOn[i]] == null)
                    {
                        table.Add(keysIAmDependingOn[i], new ArrayList());
                    }
                    ((ArrayList)table[keysIAmDependingOn[i]]).Add(key);
                }
                table = this.Internal.AddDependencyKeyList(table, operationContext);
                if (table == null)
                {
                    return(flag);
                }
                IDictionaryEnumerator enumerator = table.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if ((enumerator.Value is bool) && !((bool)enumerator.Value))
                    {
                        throw new OperationFailedException("One of the dependency keys does not exist.");
                    }
                }
            }
            return(flag);
        }
Ejemplo n.º 18
0
 public OpenStreamOperation(string key, string lockHandle, StreamModes mode, string group, string subGroup, ExpirationHint expHint, EvictionHint evHint, OperationContext operationContext)
 {
     _key              = key;
     _group            = group;
     _subGroup         = subGroup;
     _expHint          = expHint;
     _evictionHint     = evHint;
     _mode             = mode;
     _lockHandle       = lockHandle;
     _operationContext = operationContext;
 }
Ejemplo n.º 19
0
 public void Deserialize(CompactReader reader)
 {
     _key              = reader.ReadObject() as string;
     _mode             = (StreamModes)reader.ReadInt16();
     _group            = reader.ReadObject() as string;
     _subGroup         = reader.ReadObject() as string;
     _expHint          = reader.ReadObject() as ExpirationHint;
     _evictionHint     = reader.ReadObject() as EvictionHint;
     _lockHandle       = reader.ReadObject() as string;
     _operationContext = reader.ReadObject() as OperationContext;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or
 /// resetting unmanaged resources.
 /// </summary>
 void IDisposable.Dispose()
 {
     lock (this)
     {
         if (_exh != null)
         {
             ((IDisposable)_exh).Dispose();
             _exh = null;
         }
         _evh = null;
     }
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Construtor interno.
 /// </summary>
 /// <param name="val">Instancia associada com a entrada.</param>
 /// <param name="expiryHint">Hint de expiração.</param>
 /// <param name="evictionHint">Hint de liberação.</param>
 internal CacheEntry(object val, ExpirationHint expiryHint, EvictionHint evictionHint) : base(val)
 {
     _flags            = new BitSet();
     _creationTime     = new DateTime();
     _lastModifiedTime = new DateTime();
     _size             = -1;
     _version          = 1;
     _expirationHint   = expiryHint;
     _evictionHint     = evictionHint;
     _creationTime     = DateTime.Now;
     _lastModifiedTime = DateTime.Now;
 }
Ejemplo n.º 22
0
 internal override bool AddInternal(object key, ExpirationHint eh, OperationContext operationContext)
 {
     if ((_primary == null) || (_secondary == null))
     {
         throw new InvalidOperationException();
     }
     if (_primary.ContainsInternal(key))
     {
         return(_primary.AddInternal(key, eh, operationContext));
     }
     return(_secondary.Contains(key, operationContext) && _secondary.AddInternal(key, eh, operationContext));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Ressincroniza o item de forma assincrona.
 /// </summary>
 /// <param name="key">Chave da entrada.</param>
 /// <param name="exh">Hint de expiração.</param>
 /// <param name="evh">Hint de liberação.</param>
 /// <param name="groupInfo">Informações do grupo.</param>
 /// <param name="queryInfo">Informações da consulta.</param>
 /// <param name="resyncProviderName">Nome do provedor de ressincronização.</param>
 /// <returns></returns>
 public object ResyncCacheItemAsync(object key, ExpirationHint exh, EvictionHint evh, GroupInfo groupInfo, Hashtable queryInfo, string resyncProviderName)
 {
     lock (_queue)
     {
         if ((_asyncProc != null) && (this.GetQueuedReadRequest(key) == null))
         {
             IAsyncTask evnt = new CacheResyncTask(this, key as string, exh, evh, _context.CompressionThreshold, groupInfo, queryInfo, resyncProviderName);
             _queue[key] = evnt;
             _asyncProc.Enqueue(evnt);
         }
         return(null);
     }
 }
Ejemplo n.º 24
0
 public void Deserialize(CompactReader reader)
 {
     _key                 = reader.ReadObject();
     _value               = reader.ReadObject();
     _expiration          = reader.ReadInt64();
     _dependency          = ExpirationHint.ReadExpHint(reader);//reader.ReadObject();
     _options             = reader.ReadByte();
     _itemRemovedCallback = reader.ReadObject();
     _group               = (string)reader.ReadObject();
     _subgroup            = (string)reader.ReadObject();
     _queryInfo           = (Hashtable)reader.ReadObject();
     _keysDependingOnMe   = (ArrayList)reader.ReadObject();
 }
Ejemplo n.º 25
0
 public void Serialize(CompactWriter writer)
 {
     try
     {
         writer.WriteObject(_key);
         writer.WriteObject(_value);
         writer.Write(_expiration);
         ExpirationHint.WriteExpHint(writer, _dependency);
         writer.Write(_options);
         writer.WriteObject(_itemRemovedCallback);
         writer.WriteObject(_queryInfo);
     }
     catch (Exception) { throw; }
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="cache">Instancia do cache onde a entrada será adicionada.</param>
 /// <param name="key">Chave da entrada.</param>
 /// <param name="value">Valor da entrada.</param>
 /// <param name="expiryHint">Hint de expiração.</param>
 /// <param name="syncDependency">Dependencia de sincronização.</param>
 /// <param name="evictionHint">Hint de liberação</param>
 /// <param name="group"></param>
 /// <param name="subGroup"></param>
 /// <param name="Flag"></param>
 /// <param name="queryInfo"></param>
 /// <param name="operationContext"></param>
 public AsyncAdd(Cache cache, object key, object value, ExpirationHint expiryHint, CacheSyncDependency syncDependency, EvictionHint evictionHint, string group, string subGroup, BitSet Flag, Hashtable queryInfo, OperationContext operationContext)
 {
     _cache            = cache;
     _key              = key;
     _value            = value;
     _expiryHint       = expiryHint;
     _syncDependency   = syncDependency;
     _evictionHint     = evictionHint;
     _group            = group;
     _subGroup         = subGroup;
     _flag             = Flag;
     _queryInfo        = queryInfo;
     _operationContext = operationContext;
 }
Ejemplo n.º 27
0
        public override bool Add(object key, ExpirationHint eh, OperationContext operationContext)
        {
            bool flag = false;

            base.Sync.AcquireWriterLock(-1);
            try
            {
                flag = this.Internal.Add(key, eh, operationContext);
            }
            finally
            {
                base.Sync.ReleaseWriterLock();
            }
            return(flag);
        }
Ejemplo n.º 28
0
 public CompactCacheEntry(object key, object value, ExpirationHint dependency,
                          long expiration,
                          byte options, object itemRemovedCallback, Hashtable queryInfo, BitSet Flag, object lockId, LockAccessType accessType)
 {
     _key                 = key;
     _flag                = Flag;
     _value               = value;
     _dependency          = dependency;
     _expiration          = expiration;
     _options             = options;
     _itemRemovedCallback = itemRemovedCallback;
     _queryInfo           = queryInfo;
     _lockId              = lockId;
     _accessType          = accessType;
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Libera a instancia.
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     lock (this)
     {
         if (_expirationHint != null)
         {
             ((IDisposable)_expirationHint).Dispose();
             if (((this.KeysIAmDependingOn == null) || (this.KeysIAmDependingOn.Length == 0)) && ((this.KeysDependingOnMe == null) || (this.KeysDependingOnMe.Count == 0)))
             {
                 _expirationHint = null;
             }
         }
         _evictionHint = null;
     }
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or
        /// resetting unmanaged resources.
        /// </summary>
        void IDisposable.Dispose()
        {
            lock (this)
            {
                if (_exh != null)
                {
                    ((IDisposable)_exh).Dispose();

                    if ((this.KeysIAmDependingOn == null || this.KeysIAmDependingOn.Length == 0) && (this.KeysDependingOnMe == null || this.KeysDependingOnMe.Count == 0))
                    {
                        _exh = null;
                    }
                }
                _evh = null;
            }
        }