当前位置: 首页>>代码示例>>C#>>正文


C# OperationContext.Add方法代码示例

本文整理汇总了C#中OperationContext.Add方法的典型用法代码示例。如果您正苦于以下问题:C# OperationContext.Add方法的具体用法?C# OperationContext.Add怎么用?C# OperationContext.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OperationContext的用法示例。


在下文中一共展示了OperationContext.Add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Remove

        /// <summary>
        /// Removes key and value pairs from the cache. The keys are specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="keys">keys of the entry.</param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <returns>list of removed keys</returns>
        public override Hashtable Remove(object[] keys, ItemRemoveReason removalReason, bool notify, bool isUserOperation, OperationContext operationContext)
        {
            Hashtable table = new Hashtable();
            EventContext eventContext = null;
            EventId eventId = null;
            OperationID opId = operationContext.OperatoinID;
            for (int i = 0; i < keys.Length; i++)
            {
                try
                {
                    operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
                    if (notify)
                    {
                        //generate EventId
                        eventId = new EventId();
                        eventId.EventUniqueID = opId.OperationId;
                        eventId.OperationCounter = opId.OpCounter;
                        eventId.EventCounter = i;
                        eventContext = new EventContext();
                        eventContext.Add(EventContextFieldName.EventID, eventId);
                        operationContext.Add(OperationContextFieldName.EventContext, eventContext);
                    }
                    CacheEntry e = Remove(keys[i], removalReason, notify, null, LockAccessType.IGNORE_LOCK, operationContext);
                    if (e != null)
                    {
                        table[keys[i]] = e;
                    }
                }              
                catch (StateTransferException e)
                {
                    table[keys[i]] = e;
                }
                finally
                {
                    operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
                }
            }


            if (_context.PerfStatsColl != null)
            {
                _context.PerfStatsColl.SetCacheSize(Size);
            }

            return table;
        }
开发者ID:christrotter,项目名称:NCache,代码行数:55,代码来源:LocalCacheBase.cs

示例2: Add

        /// <summary>
        /// Adds key and value pairs to the cache. Throws an exception or returns the
        /// list of keys that failed to add in the cache.
        /// </summary>
        /// <param name="keys">keys of the entries.</param>
        /// <param name="cacheEntries">the cache entries.</param>
        /// <returns>List of keys that are added or that alredy exists in the cache and their status.</returns>
        public sealed override Hashtable Add(object[] keys, CacheEntry[] cacheEntries, bool notify, OperationContext operationContext)
        {

            Hashtable table = new Hashtable();
            EventContext eventContext = null;
            EventId eventId = null;
            OperationID opId = operationContext.OperatoinID;
            for (int i = 0; i < keys.Length; i++)
            {
                try
                {

                    operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
                    if (notify)
                    {
                        //generate EventId
                        eventId = new EventId();
                        eventId.EventUniqueID = opId.OperationId;
                        eventId.OperationCounter = opId.OpCounter;
                        eventId.EventCounter = i;
                        eventContext = new EventContext();
                        eventContext.Add(EventContextFieldName.EventID, eventId);
                        operationContext.Add(OperationContextFieldName.EventContext, eventContext);
                    }
                    CacheAddResult result = Add(keys[i], cacheEntries[i], notify, operationContext);
                    table[keys[i]] = result;
                }
                catch (Exceptions.StateTransferException se)
                {
                    table[keys[i]] = se;
                }
                catch (Exception inner)
                {
                    table[keys[i]] = new OperationFailedException(inner.Message, inner);
                }
                finally 
                {
                    operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
                }
            }

            if (_context.PerfStatsColl != null)
            {
                _context.PerfStatsColl.SetCacheSize(Size);
            }
            return table;
        }
开发者ID:christrotter,项目名称:NCache,代码行数:54,代码来源:LocalCacheBase.cs

示例3: Insert

        /// <summary>
        /// Adds key and value pairs to the cache. If any of the specified keys 
        /// already exists in the cache; it is updated, otherwise a new item is 
        /// added to the cache.
        /// </summary>
        /// <param name="keys">keys of the entries.</param>
        /// <param name="cacheEntry">the cache entries.</param>
        /// <returns>returns keys that are added or updated successfully and their status.</returns>
        public sealed override Hashtable Insert(object[] keys, CacheEntry[] cacheEntries, bool notify, OperationContext operationContext)
        {
            Hashtable table = new Hashtable();
            EventContext eventContext = null;
            EventId eventId = null;
            OperationID opId = operationContext.OperatoinID;
            for (int i = 0; i < keys.Length; i++)
            {
                try
                {
                    operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
                    if (notify)
                    {
                        //generate EventId
                        eventId = new EventId();
                        eventId.EventUniqueID = opId.OperationId;
                        eventId.OperationCounter = opId.OpCounter;
                        eventId.EventCounter = i;
                        eventContext = new EventContext();
                        eventContext.Add(EventContextFieldName.EventID, eventId);
                        operationContext.Add(OperationContextFieldName.EventContext, eventContext);
                    }
                    CacheInsResultWithEntry result = Insert(keys[i], cacheEntries[i], notify, null, LockAccessType.IGNORE_LOCK, operationContext);
                    table.Add(keys[i], result);
                }
                catch (Exception e)
                {
                    table[keys[i]] = e;
                }
                finally
                {
                    operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
                }
            }

            if (_context.PerfStatsColl != null)
            {
                _context.PerfStatsColl.SetCacheSize(Size);
            }

            return table;
        }
开发者ID:christrotter,项目名称:NCache,代码行数:50,代码来源:LocalCacheBase.cs

示例4: FetchObject

            /// <summary>
            /// Does the lazy loading of object. This method is virtual so containers can 
            /// customize object fetching logic.
            /// </summary>
            /// <param name="key"></param>
            /// <returns></returns>
            protected override object FetchObject(object key, OperationContext operationContext)
            {
                ReplicatedCacheBase cache = _cache as ReplicatedCacheBase;

                object obj = null;
                bool doAgain = false;


                do
                {
                    doAgain = false;
                    Address targetNode = cache.Cluster.Coordinator;
                    if (targetNode == null) return null;

                    if (cache.Cluster.IsCoordinator)
                    {
                        //coordinator has left and i am the new coordinator so need not to do
                        //state transfer.
                        _bvalid = false;
                        return obj;
                    }
                    try
                    {
                        operationContext.Add(OperationContextFieldName.GenerateQueryInfo , true);
                        obj = cache.Clustered_Get(targetNode, key, operationContext,_isUserOperation);

                    }
                    catch (Runtime.Exceptions.SuspectedException se)
                    {
                        //coordinator has left; so need to synchronize with the new coordinator.
                        doAgain = true;
                    }
                }
                while (doAgain);

                return obj;
            }
开发者ID:javithalion,项目名称:NCache,代码行数:43,代码来源:ReplicatedCacheBase.cs

示例5: Get

        /// <summary>
        /// Retrieve the objects from the cache.
        /// An array of keys is passed as parameter.
        /// </summary>
        /// <param name="keys">keys of the entries.</param>
        /// <returns>key and entry pairs.</returns>
        public sealed override Hashtable Get(object[] keys, OperationContext operationContext)
        {
            Hashtable entries = new Hashtable();
            CacheEntry e = null;
            for (int i = 0; i < keys.Length; i++)
            {
                try
                {
                    
                    if(operationContext != null)
                    {
                        operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
                        OperationID opId = operationContext.OperatoinID;
                        //generate EventId
                        EventId eventId = EventId.CreateEventId(opId);
                        eventId.EventUniqueID = opId.OperationId;
                        eventId.OperationCounter = opId.OpCounter;
                        eventId.EventCounter = i;
                        EventContext eventContext = new EventContext();
                        eventContext.Add(EventContextFieldName.EventID, eventId);
                        operationContext.Add(OperationContextFieldName.EventContext, eventContext);
                    }

                    e = Get(keys[i], operationContext);
                    if (e != null)
                    {
                        entries[keys[i]] = e;
                    }
                }
                catch (StateTransferException se)
                {
                    entries[keys[i]] = se;
                }
            }
            return entries;
        }
开发者ID:christrotter,项目名称:NCache,代码行数:42,代码来源:LocalCacheBase.cs

示例6: ClusteredInsert

        private Hashtable ClusteredInsert(object[] keys, CacheEntry[] cacheEntries, bool notify, OperationContext operationContext)
        {
            Hashtable targetNodes = null;
            Hashtable result = new Hashtable();
            Hashtable tmpResult = null;

            ArrayList totalKeys = new ArrayList(keys);
            ArrayList totalEntries = new ArrayList(cacheEntries);
            ArrayList keysToInsert = new ArrayList(keys);

            Address targetNode = null;
            object[] currentKeys = null;
            CacheEntry[] currentValues = null;

            Dictionary<object, CacheEntry> fullEntrySet = new Dictionary<object, CacheEntry>();

            Hashtable totalAddedKeys = new Hashtable();
            Hashtable totalInsertedKeys = new Hashtable();
            Hashtable totalRemainingKeys = new Hashtable();

            if (_internalCache == null) throw new InvalidOperationException();

            do
            {
                targetNodes = GetTargetNodes(keysToInsert);

                if (targetNodes != null && targetNodes.Count == 0)
                {
                    foreach (object key in keysToInsert)
                    {
                        result[key] = new OperationFailedException("No target node available to accommodate the data.");
                    }
                    return result;
                }
                IDictionaryEnumerator ide = targetNodes.GetEnumerator();
                Hashtable keyList = null;

                //We select one node at a time for Add operation.
                while (ide.MoveNext())
                {
                    targetNode = ide.Key as Address;
                    keyList = (Hashtable) ide.Value;

                    if (targetNode != null && keyList != null)
                    {
                        currentKeys = new object[keyList.Count];
                        currentValues = new CacheEntry[keyList.Count];

                        int j = 0;
                        foreach (object key in keyList.Keys)
                        {
                            int index = totalKeys.IndexOf(key);
                            if (index != -1)
                            {
                                currentKeys[j] = totalKeys[index];
                                currentValues[j] = totalEntries[index] as CacheEntry;
                                if (!fullEntrySet.ContainsKey((string) totalKeys[index]))
                                    fullEntrySet.Add((string) totalKeys[index], (CacheEntry) totalEntries[index]);
                                j++;
                            }
                        }

                        try
                        {
                            if (targetNode.Equals(Cluster.LocalAddress))
                            {
                                tmpResult = Local_Insert(currentKeys, currentValues, Cluster.LocalAddress, notify, operationContext);
                            }
                            else
                            {
                                tmpResult = Clustered_Insert(targetNode, currentKeys, currentValues,
                                    operationContext);
                            }
                        }
                        catch (Runtime.Exceptions.SuspectedException se)
                        {
                            //we redo the operation
                            if (Context.NCacheLog.IsInfoEnabled)
                                Context.NCacheLog.Info("PartitionedServerCache.SafeAdd",
                                    targetNode + " left while addition");

                            tmpResult = new Hashtable();
                            for (int i = 0; i < currentKeys.Length; i++)
                            {
                                tmpResult[currentKeys[i]] = new GeneralFailureException(se.Message, se);
                            }
                        }
                        catch (Runtime.Exceptions.TimeoutException te)
                        {
                            if (Context.NCacheLog.IsInfoEnabled)
                                Context.NCacheLog.Info("PartitionedServerCache.SafeAdd",
                                    targetNode + " operation timed out");

                            tmpResult = new Hashtable();
                            for (int i = 0; i < currentKeys.Length; i++)
                            {
                                tmpResult[currentKeys[i]] = new GeneralFailureException(te.Message, te);
                            }
                        }
                        catch (BucketTransferredException ex)
//.........这里部分代码省略.........
开发者ID:javithalion,项目名称:NCache,代码行数:101,代码来源:PartitionedServerCache.cs

示例7: ArrayList

        void IEvictionPolicy.Execute(CacheBase cache, CacheRuntimeContext context, long evictSize)
        {
          
            ILogger NCacheLog = cache.Context.NCacheLog;
            
            if (NCacheLog.IsInfoEnabled) NCacheLog.Info("LocalCache.Evict()", "Cache Size: {0}" + cache.Count.ToString());

             //if user has updated the values in configuration file then new values will be reloaded.
            _sleepInterval = Convert.ToInt32(ServiceConfiguration.EvictionBulkRemoveDelay);
            _removeThreshhold = Convert.ToInt32(ServiceConfiguration.EvictionBulkRemoveSize);
            DateTime startTime = DateTime.Now;
            ArrayList selectedKeys = this.GetSelectedKeys(cache, (long)Math.Ceiling(evictSize * _ratio));
            DateTime endTime = DateTime.Now;

            if (NCacheLog.IsInfoEnabled) NCacheLog.Info("LocalCache.Evict()", String.Format("Time Span for {0} Items: " + (endTime - startTime), selectedKeys.Count));

            startTime = DateTime.Now;

            Cache rootCache = context.CacheRoot;

            ArrayList keysTobeRemoved = new ArrayList();
            ArrayList dependentItems = new ArrayList();
            ArrayList removedItems = null;

            IEnumerator e = selectedKeys.GetEnumerator();

            int removedThreshhold = _removeThreshhold/300;
            int remIteration = 0;
            while (e.MoveNext())
            {
                object key = e.Current;
                if (key == null) continue;

                keysTobeRemoved.Add(key);

                if (keysTobeRemoved.Count % 300 == 0)
                {
                    try
                    {
                        OperationContext priorityEvictionOperationContext = new OperationContext();
                        priorityEvictionOperationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                        removedItems = cache.RemoveSync(keysTobeRemoved.ToArray(), ItemRemoveReason.Underused, false, priorityEvictionOperationContext) as ArrayList;

                        context.PerfStatsColl.IncrementEvictPerSecStatsBy(keysTobeRemoved.Count);
                    }
                    catch (Exception ex)
                    {
                        NCacheLog.Error("PriorityEvictionPolicy.Execute", "an error occured while removing items. Error " + ex.ToString());
                    }
                    keysTobeRemoved.Clear();
                    if (removedItems != null && removedItems.Count > 0)
                    {
                        dependentItems.AddRange(removedItems);
                    }
                    
                    remIteration++;
                    if (remIteration >= removedThreshhold)
                    {
                        //put some delay so that user operations are not affected.
                        System.Threading.Thread.Sleep(_sleepInterval*1000);
                        remIteration = 0;
                    }
                }
            }

            if (keysTobeRemoved.Count > 0)
            {
                try
                {
                    OperationContext priorityEvictionOperationContext = new OperationContext();
                    priorityEvictionOperationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                    removedItems = cache.RemoveSync(keysTobeRemoved.ToArray(), ItemRemoveReason.Underused, false, priorityEvictionOperationContext) as ArrayList;

                    context.PerfStatsColl.IncrementEvictPerSecStatsBy(keysTobeRemoved.Count);
                    if (removedItems != null && removedItems.Count > 0)
                    {
                        dependentItems.AddRange(removedItems);
                    }
                }
                catch (Exception ex)
                {
                    NCacheLog.Error("PriorityEvictionPolicy.Execute", "an error occured while removing items. Error " + ex.ToString());
                }
            }

            if (dependentItems.Count > 0)
            {
                ArrayList removableList = new ArrayList();
                if (rootCache != null)
                {
                    foreach (object depenentItme in dependentItems)
                    {
                        if (depenentItme == null) continue;
                        removableList.Add(depenentItme);
                        if (removableList.Count % 100 == 0)
                        {
                            try
                            {
                                OperationContext priorityEvictionOperationContext = new OperationContext();
                                priorityEvictionOperationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
//.........这里部分代码省略.........
开发者ID:christrotter,项目名称:NCache,代码行数:101,代码来源:PriorityEvictionPolicy.cs

示例8: GetLoggedData

		 protected virtual StateTxfrInfo GetLoggedData(ArrayList bucketIds)
		 {
			 ArrayList updatedKeys = null;
			 ArrayList removedKeys = null;
			 Hashtable logTbl = null;
			 StateTxfrInfo info = null;

			 bool isLoggingStopped = false;

			 try
			 {

				 logTbl = _parent.InternalCache.GetLogTable(bucketIds, ref isLoggingStopped);

				 if (logTbl != null)
				 {

					 updatedKeys = logTbl["updated"] as ArrayList;
					 removedKeys = logTbl["removed"] as ArrayList;

					 if (updatedKeys != null && updatedKeys.Count > 0)
					 {
						 for (int i = 0; i < updatedKeys.Count; i++)
						 {
							 string key = updatedKeys[i] as string;
                             OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                             operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true);
                             CacheEntry entry = _parent.InternalCache.Get(key, false, operationContext);
                             _result[key] = entry;
						 }
					 }
					 if (removedKeys != null && removedKeys.Count > 0)
					 {
						 for (int i = 0; i < removedKeys.Count; i++)
						 {
							 string key = removedKeys[i] as string;
							 _result[key] = null;
						 }
					 }

                     if (!isLoggingStopped)
                         info = new StateTxfrInfo(_result, false, 0, this.stream);
                     else
                         info = new StateTxfrInfo(_result, true, 0, this.stream);


                     _parent.Context.NCacheLog.Debug("StateTxfrCorresponder.GetLoggedData()", info == null ? "returning null state-txfr-info" : "returning " + info.data.Count.ToString() + " items in state-txfr-info");
					 return info;
				 }
				 else
                     if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresoponder.GetLoggedData", "no logged data found");
			 }
			 catch (Exception e)
			 {
                 _parent.Context.NCacheLog.Error("StateTxfrCorresoponder.GetLoggedData", e.ToString());
				 throw;
			 }
			 finally
			 {
                
			 }
		
			 //no operation has been logged during state transfer.
			 //so announce completion of state transfer for this bucket.
             return new StateTxfrInfo(_result, true, 0, this.stream);
		 }
开发者ID:javithalion,项目名称:NCache,代码行数:66,代码来源:StateTxfrCorresponder.cs

示例9: RemoveFailedKeysOnReplica

        private void RemoveFailedKeysOnReplica()
        {
            try
            {
                if (IsSyncReplica && failedKeysList != null && failedKeysList.Count > 0)
                {
                    OperationContext operationContext = new OperationContext(OperationContextFieldName.RemoveOnReplica, true);
                    operationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);

                    IEnumerator ieFailedKeys = failedKeysList.GetEnumerator();
                    while (ieFailedKeys.MoveNext())
                    {
                        string key = (string)ieFailedKeys.Current;
                        try
                        {
                            _parent.Context.CacheImpl.Remove(key, ItemRemoveReason.Removed, false, null, LockAccessType.IGNORE_LOCK, operationContext);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            finally
            {
                failedKeysList = null;
            }
        }
开发者ID:javithalion,项目名称:NCache,代码行数:28,代码来源:StateTransferTask.cs

示例10: GetData


//.........这里部分代码省略.........
         //                                ubObject = entry.Value as UserBinaryObject;

         //                            payLoad.AddRange(ubObject.Data);
         //                            long size = entry.DataSize;
         //                            int index = payLoadCompilationInfo.Add(size);
         //                            PayloadInfo payLoadInfo = new PayloadInfo(entry.CloneWithoutValue(), index);
         //                            result[ide.Key] = payLoadInfo;
         //                        }

         //                    }
         //                }
         //            }
         //            _sendLogData = true;
         //            if (_parent.Context.NCacheLog.IsInfoEnabled)
         //                _parent.Context.NCacheLog.Info("State Transfer Corresponder", "BalanceDataLoad = " + _isBalanceDataLoad.ToString());
         //            if (_isBalanceDataLoad)
         //            {
         //                _parent.Context.PerfStatsColl.IncrementDataBalPerSecStatsBy(result.Count);
         //            }
         //            else
         //            {
         //                _parent.Context.PerfStatsColl.IncrementStateTxfrPerSecStatsBy(result.Count);
         //            }

         //            return new StateTxfrInfo(result,payLoad,payLoadCompilationInfo, false);
         //        }
         //        else
         //            return GetLoggedData(bucketIds);
         //    }
         //    catch (Exception ex)
         //    {
         //        _parent.Context.NCacheLog.Error("StateTxfrCorresponder.GetData(1)", ex.ToString());
         //        return null;
         //    }
         //}

		 protected StateTxfrInfo GetData(int bucketId)
		 {
             if (_result.Count > 0)
             {
                 _result.Clear();
             }

			 long sizeToSend = 0;

             lock (_parent._bucketStateTxfrStatus.SyncRoot)
             {
                 _parent._bucketStateTxfrStatus[bucketId] = true;
             }

             if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "state txfr request for :" + bucketId + " txfrid :" + _lastTxfrId);

			 if (_keyList != null && _keyList.Count > 0)
			 {
                 if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "bucket size :" + _keyList.Count);

				 for (_keyCount = 0; _keyCount < _keyList.Count; _keyCount++)
				 {
					 string key = _keyList[_keyCount] as string;

                     OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                      operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true);
                     CacheEntry entry = _parent.InternalCache.InternalCache.Get(key, false,operationContext);
					 if (entry != null)
					 {
                         long size = (entry.InMemorySize + Common.MemoryUtil.GetStringSize(key));//.DataSize;                         
                         if (sizeToSend > _threshold) break;

                         _result[key] = entry;
						 sizeToSend += size;
					 }
				 }
                 if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "items sent :" + _keyCount);
                 
                 if (_parent.Context.NCacheLog.IsInfoEnabled)
                     _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "BalanceDataLoad = " + _isBalanceDataLoad.ToString()); 

                 if (_isBalanceDataLoad)
                     _parent.Context.PerfStatsColl.IncrementDataBalPerSecStatsBy(_result.Count);
                 else
                     _parent.Context.PerfStatsColl.IncrementStateTxfrPerSecStatsBy(_result.Count);

				 return new StateTxfrInfo(_result,false,sizeToSend, this.stream);
			 }
             else if (_transferType == StateTransferType.MOVE_DATA)
             {
                 //We need to transfer the logs.
                 if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "sending log data for bucket: " + bucketId);

                 ArrayList list = new ArrayList(1);
                 list.Add(bucketId);
                 return GetLoggedData(list);
             }
             else
             {
                 //As transfer mode is not MOVE_DATA, therefore no logs are maintained
                 //and hence are not transferred.
                 return new StateTxfrInfo(null, true, 0, null);
             }
		 }
开发者ID:javithalion,项目名称:NCache,代码行数:101,代码来源:StateTxfrCorresponder.cs

示例11: GetLoggedData

		 protected virtual StateTxfrInfo GetLoggedData(ArrayList bucketIds)
		 {
			 ArrayList updatedKeys = null;
			 ArrayList removedKeys = null;
			 Hashtable logTbl = null;
			 StateTxfrInfo info = null;
			 Hashtable result = new Hashtable();
             ArrayList payLoad = new ArrayList();
             ArrayList payLoadCompilationInfo = new ArrayList();


			 bool isLoggingStopped = false;

			 try
			 {

				 logTbl = _parent.InternalCache.GetLogTable(bucketIds, ref isLoggingStopped);

				 if (logTbl != null)
				 {

					 updatedKeys = logTbl["updated"] as ArrayList;
					 removedKeys = logTbl["removed"] as ArrayList;

					 if (updatedKeys != null && updatedKeys.Count > 0)
					 {
						 for (int i = 0; i < updatedKeys.Count; i++)
						 {
							 string key = updatedKeys[i] as string;
                             OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                             operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true);
                             CacheEntry entry = _parent.InternalCache.Get(key, false, operationContext);
                             UserBinaryObject ubObject = null;
                             if (entry.Value is CallbackEntry)
                             {
                                 ubObject = ((CallbackEntry)entry.Value).Value as UserBinaryObject;
                             }
                             else
                                 ubObject = entry.Value as UserBinaryObject;

                             payLoad.AddRange(ubObject.Data);
                             long size = entry.DataSize;
                             int index = payLoadCompilationInfo.Add(size);
                             PayloadInfo payLoadInfo = new PayloadInfo(entry.CloneWithoutValue(), index);

							 result[key] = payLoadInfo;
						 }
					 }
					 if (removedKeys != null && removedKeys.Count > 0)
					 {
						 for (int i = 0; i < removedKeys.Count; i++)
						 {
							 string key = removedKeys[i] as string;
							 result[key] = null;
						 }
					 }

					 if (!isLoggingStopped)
						 info = new StateTxfrInfo(result,payLoad,payLoadCompilationInfo, false);
					 else
                         info = new StateTxfrInfo(result, payLoad, payLoadCompilationInfo, true);


                     _parent.Context.NCacheLog.Debug("StateTxfrCorresponder.GetLoggedData()", info == null ? "returning null state-txfr-info" : "returning " + info.data.Count.ToString() + " items in state-txfr-info");
					 return info;
				 }
				 else
                     if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresoponder.GetLoggedData", "no logged data found");
			 }
			 catch (Exception e)
			 {
                 _parent.Context.NCacheLog.Error("StateTxfrCorresoponder.GetLoggedData", e.ToString());
				 throw;
			 }
			 finally
			 {
                
			 }
		
			 //no operation has been logged during state transfer.
			 //so announce completion of state transfer for this bucket.
             return new StateTxfrInfo(result, payLoad, payLoadCompilationInfo, true);
		 }
开发者ID:christrotter,项目名称:NCache,代码行数:83,代码来源:StateTxfrCorresponder.cs

示例12: GetData

		 protected StateTxfrInfo GetData(int bucketId)
		 {
			 Hashtable result = new Hashtable();
             ArrayList payLoad = new ArrayList();
             ArrayList payLoadCompilationInfo = new ArrayList();

			 long sizeToSend = 0;

             lock (_parent._bucketStateTxfrStatus.SyncRoot)
             {
                 _parent._bucketStateTxfrStatus[bucketId] = true;
             }

             if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "state txfr request for :" + bucketId + " txfrid :" + _lastTxfrId);

			 if (_keyList != null && _keyList.Count > 0)
			 {
                 if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "bucket size :" + _keyList.Count);

				 for (_keyCount = 0; _keyCount < _keyList.Count; _keyCount++)
				 {
					 string key = _keyList[_keyCount] as string;

                     OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                      operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true);
                     CacheEntry entry = _parent.InternalCache.InternalCache.Get(key, false,operationContext);
					 if (entry != null)
					 {
                         long size = (entry.InMemorySize + Common.MemoryUtil.GetStringSize(key));//.DataSize;                         
                         if (sizeToSend > _threshold) break;

                         UserBinaryObject ubObject = null;
                         if (entry.Value is CallbackEntry)
                         {
                             ubObject = ((CallbackEntry)entry.Value).Value as UserBinaryObject;
                         }
                         else
                             ubObject = entry.Value as UserBinaryObject;

                         payLoad.AddRange(ubObject.Data);
                         long entrySize = entry.DataSize;
                         int index = payLoadCompilationInfo.Add(entrySize);
                         PayloadInfo payLoadInfo = new PayloadInfo(entry.CloneWithoutValue(), index);

                         result[key] = payLoadInfo;
						 sizeToSend += size;
					 }
				 }
                 if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "items sent :" + _keyCount);
                 
                 if (_parent.Context.NCacheLog.IsInfoEnabled)
                     _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "BalanceDataLoad = " + _isBalanceDataLoad.ToString()); 

                 if (_isBalanceDataLoad)
                     _parent.Context.PerfStatsColl.IncrementDataBalPerSecStatsBy(result.Count);
                 else
                     _parent.Context.PerfStatsColl.IncrementStateTxfrPerSecStatsBy(result.Count);

				 return new StateTxfrInfo(result,payLoad,payLoadCompilationInfo, false,sizeToSend);
			 }
             else if (_transferType == StateTransferType.MOVE_DATA)
             {
                 //We need to transfer the logs.
                 if (_parent.Context.NCacheLog.IsInfoEnabled) _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "sending log data for bucket: " + bucketId);

                 ArrayList list = new ArrayList(1);
                 list.Add(bucketId);
                 return GetLoggedData(list);
             }
             else
             {
                 //As transfer mode is not MOVE_DATA, therefore no logs are maintained
                 //and hence are not transferred.
                 return new StateTxfrInfo(null,null,null, true);
             }
		 }
开发者ID:christrotter,项目名称:NCache,代码行数:76,代码来源:StateTxfrCorresponder.cs

示例13: FetchObject

 /// <summary>
 /// Does the lazy loading of object. This method is virtual so containers can customize object 
 /// fetching logic.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 protected virtual object FetchObject(object key, OperationContext operationContext)
 {
     operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true);
     return _cache.Get(key,operationContext);
 }
开发者ID:javithalion,项目名称:NCache,代码行数:11,代码来源:LazyKeysetEnumerator.cs


注:本文中的OperationContext.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。