public DoubleVector(IDictionary <k, v> dictionary) : this() { foreach (var kvp in dictionary) { _keyToValue.Add(kvp.Key, kvp.Value); _valueToKey.Add(kvp.Value, kvp.Key); } }
public IDictionary <String, IResponseCollection <T> > SendMessageToAllShards <T>(Message message, bool primaryOnly) { IDictionary <String, IResponseCollection <T> > responses = new HashVector <String, IResponseCollection <T> >(); IDictionary <String, RequestAsync> asyncResults = new HashVector <String, RequestAsync>(); foreach (String shard in _remoteShards.Keys) { IShard dest = GetShardInstance(shard); if (dest != null) { try { if (primaryOnly) { ShardRequestBase <T> request = dest.CreateUnicastRequest <T>(dest.Primary, message); asyncResults.Add(shard, new RequestAsync(request.BeginExecute(), request, dest.Primary)); } else { ShardMulticastRequest <ResponseCollection <T>, T> multicastRequest = dest.CreateMulticastRequest <ResponseCollection <T>, T>(dest.ActiveChannelsList, message); asyncResults.Add(shard, new RequestAsync(multicastRequest.BeginExecute(), multicastRequest)); } } catch (Exception ex) { } } } foreach (KeyValuePair <String, RequestAsync> pair in asyncResults) { String shardName = pair.Key; IResponseCollection <T> shardResponse = new ResponseCollection <T>(); if (primaryOnly) { ShardRequestBase <T> req = pair.Value.Request; IClusterResponse <T> clusterResponse = new ClusterResponse <T>(req.EndExecute(pair.Value.AsyncResult), pair.Value.Destination); IList <IClusterResponse <T> > list = new List <IClusterResponse <T> >(); list.Add(clusterResponse); shardResponse.Responses = list; } else { ShardMulticastRequest <ResponseCollection <T>, T> req = pair.Value.Request; shardResponse = req.EndExecute(pair.Value.AsyncResult); } responses.Add(shardName, shardResponse); } return(responses); }
public void Populate(IDictionaryEnumerator e) { if (e != null) { if (e is RedBlackEnumerator) { while (e.MoveNext()) { HashVector tbl = e.Value as HashVector; this.Add(tbl, CollectionOperation.Union); this.Mark(CollectionOperation.Union); } } else { while (e.MoveNext()) { if (!_resultKeys.ContainsKey(e.Key)) { _resultKeys.Add(e.Key, null); } } } } }
///<summary> ///Insert Value ///</summary> public void Insert(object key, object value) { if (!Data.ContainsKey(key)) { Data.Add(key, null); } }
public IList <MessageInfo> GetNeverAcknowledgedMessages(TimeSpan timeAfterAssignment) { IList <MessageInfo> unacknowledgedMessages = new List <MessageInfo>(); HashVector durableSubscriptions = new HashVector(StringComparer.InvariantCultureIgnoreCase); lock (_mutex) { foreach (ClientSubscriptionManager client in _subscribers.Values) { IList <Message> unacknowledgedMessageList = null; unacknowledgedMessageList = client.GetNeverAcknowledgedMessages(timeAfterAssignment); if (unacknowledgedMessageList != null) { foreach (Message message in unacknowledgedMessageList) { if (!durableSubscriptions.ContainsKey(message.MessageId)) { unacknowledgedMessages.Add(GetMessageInfo(message)); durableSubscriptions.Add(message.MessageId, null); } } } } } return(unacknowledgedMessages); }
public void NodeLeft(Address node, DateTime leaveTime) { HashVector<string, ConnectedClient> deadClients = new HashVector<string, ConnectedClient>(); lock (_lock) { foreach (var connectedClient in _connectedClients) { if (connectedClient.Value.RemoveNode(node) == 0) { deadClients.Add(connectedClient.Key, connectedClient.Value); } } if (deadClients.Count > 0) { foreach (var deadClient in deadClients) { _connectedClients.Remove(deadClient.Key); foreach (var notificationSpecification in _specifications) { var task = new DeadClientNotificationTask(this, deadClient.Key, leaveTime, notificationSpecification.Value, deadClient.Value.Info); notificationSpecification.Value.AddNotificationSpecificationTask(deadClient.Key, task); s_scheduler.AddTask(task); } } } } }
public void KeyRemoved(string key, bool isUserOperation, string clientId) { lock (this) { if (!isUserOperation) { UnRegisterKeyNotification(key, null, null); return; } if (_registeredKeys.ContainsKey(key)) { _lastChangeTime = HPTime.Now; // set last change time KeyInfo keyInfo = _registeredKeys[key]; keyInfo.UpdatedTime = HPTime.Now; keyInfo = keyInfo.Clone() as KeyInfo; keyInfo.UpdatedBy = clientId; if (!_removedKeys.ContainsKey(key)) { _removedKeys.Add(key, keyInfo); } else { _removedKeys[key] = keyInfo; } if (_updatedKeys.ContainsKey(key)) { _updatedKeys.Remove(key); } } } }
public void RegisterRequest(string clientId, long requestId, long commandId, long lastAcknowledged) { if (RequestLoggingEnabled) { if (!String.IsNullOrEmpty(clientId)) { ClientRequestAccount account = new ClientRequestAccount(); lock (ledger) { if (!ledger.ContainsKey(clientId)) { ledger.Add(clientId, account); } else { account = (ClientRequestAccount)ledger[clientId]; } } size -= account.InMemorySize; account.RegisterRequest(requestId, commandId, lastAcknowledged); size += account.InMemorySize; _perfStatsCollector.IncrementRequestLogPerSec(); _perfStatsCollector.IncrementRequestLogCount(1); _perfStatsCollector.RequestLogSize = InMemorySize; } } }
internal void Add(string messageId, DateTime time) { lock (_mutex) { _expirationIndex.Add(messageId, time); } }
private IDictionary <string, object> GetCsvReadyValues(JSONDocument json) { IDictionary <string, object> valueMap = new HashVector <string, object>(); IEnumerator e = json.GetEnumerator(); while (e.MoveNext()) { object obj = e.Current; var type = obj.GetType(); if (type.IsGenericType) { if (type == typeof(KeyValuePair <string, object>)) { var key = type.GetProperty("Key"); var value = type.GetProperty("Value"); var keyObj = key.GetValue(obj, null); var valueObj = value.GetValue(obj, null); if (valueObj.GetType() == typeof(System.Collections.ArrayList) || valueObj.GetType() == typeof(JSONDocument)) { // remove internal qoutes and append to start and end string rem = "\""; rem += valueObj.ToString().Replace("\"", string.Empty); rem += "\""; valueMap.Add(keyObj.ToString(), rem); } else { if (valueObj.GetType() == typeof(string)) { var val = new StringBuilder(); val.Append("\""); val.Append(valueObj.ToString()); val.Append("\""); valueMap.Add(keyObj.ToString(), val.ToString()); } else { valueMap.Add(keyObj.ToString(), valueObj.ToString()); } } } } } return(valueMap); }
public Element(TKey k, TValue value) { Key = k; var hs = new HashVector <TValue, byte>(); hs.Add(value, BYTE); _child = hs; }
public static void BuildResponse(IDictionary <string, IList <object> > getResult, int commandVersion, string requestStringId, IList serializedResponse, int commandId, Cache cache) { Util.KeyPackageBuilder.Cache = cache; int numberOfChunks = 0; int sequenceId = 1; long requestId = Convert.ToInt64(requestStringId); HashVector <string, ClusteredList <List <Message> > > resultInChunks = new HashVector <string, ClusteredList <List <Message> > >(); foreach (var pair in getResult) { var messageListChunks = Util.KeyPackageBuilder.GetMessages(pair.Value); if (resultInChunks.ContainsKey(pair.Key)) { ClusteredList <List <Message> > messageList = resultInChunks[pair.Key]; messageList.AddRange(messageListChunks); } else { resultInChunks.Add(pair.Key, messageListChunks); } numberOfChunks += messageListChunks.Count; } Response response = new Response(); response.requestId = requestId; response.commandID = commandId; response.responseType = Response.Type.GET_MESSAGE; GetMessageResponse getMessageResponse = null; if (resultInChunks.Count == 0) { getMessageResponse = new GetMessageResponse(); response.getMessageResponse = getMessageResponse; serializedResponse.Add(Common.Util.ResponseHelper.SerializeResponse(response)); return; } getMessageResponse = new GetMessageResponse(); foreach (var pair in resultInChunks) { TopicMessages topicMessage = new TopicMessages(); topicMessage.topic = pair.Key; for (int i = 0; i < pair.Value.Count; i++) { topicMessage.messageList.AddRange(pair.Value[i]); } getMessageResponse.topicMessages.Add(topicMessage); } response.getMessageResponse = getMessageResponse; serializedResponse.Add(Common.Util.ResponseHelper.SerializeResponse(response)); }
/// <summary> /// Get the keys that are not in the list /// </summary> /// <param name="keys"></param> /// <param name="list"></param> /// <returns></returns> public static object[] GetNotAvailableKeys(object[] keys, ClusteredArrayList list) { HashVector table = new HashVector(); foreach (object key in list) { table.Add(key, ""); } return(GetNotAvailableKeys(keys, table)); }
public void PushInTaskOutput(string taskId, TaskOutput output) { lock (objectMutex) { if (!taskOutput.ContainsKey(taskId)) { taskOutput.Add(output.TaskId, output); } } }
public IDictionary<string, ClientInfo> GetAllConnectedClientInfos() { var connectedClientInfos = new HashVector<string, ClientInfo>(); lock (_lock) { foreach (var connectedClient in _connectedClients) { connectedClientInfos.Add(connectedClient.Key, connectedClient.Value.Info); } } return connectedClientInfos; }
private StateTxfrInfo GetKeysChunk(int bucketId) { HashVector result = new HashVector(); long sizeToSend = 0; bool lastChunk = true; try { if (_bucketKeysFilterEnumerator != null && _bucketKeysFilterEnumerator.MoveNext()) { List <DocumentKey> bucketKeysList = new List <DocumentKey>(); do { DocumentKey key = _bucketKeysFilterEnumerator.Current; if (key != null) { bucketKeysList.Add(key); long size = GetDocumentSize(key as ISize); sizeToSend += size; if (sizeToSend > _threshold) { lastChunk = false; break; } } } while (_bucketKeysFilterEnumerator.MoveNext()); result.Add(bucketId, bucketKeysList); InsertKeysToCollection(bucketId, new ArrayList(bucketKeysList)); return(new StateTxfrInfo(result, lastChunk, sizeToSend));//, this.stream); } else { return(new StateTxfrInfo(null, true, 0));//, null); } } finally { if (LoggerManager.Instance.StateXferLogger.IsDebugEnabled) { List <DocumentKey> keys = result[bucketId] as List <DocumentKey>; int count = keys == null?0:keys.Count; LoggerManager.Instance.StateXferLogger.Debug("StateXfer", loggingModule + " Corresponder.TransferBucketKeys - BucketId: " + bucketId + " keys : " + count); } } }
public void RegisterKeyNotification(string clientId, string key, CallbackInfo updateCallback, CallbackInfo removeCallback) { lock (this) { if (!_clients.ContainsKey(clientId)) { _clients.Add(clientId, new ClientNotificationMgr(clientId, ref _updatedKeys, ref _removedKeys)); } if (_clients[clientId].AddKey(key, updateCallback, removeCallback)) { if (_registeredKeys.ContainsKey(key)) { _registeredKeys[key].IncrementRefCount(); } else { _registeredKeys.Add(key, new KeyInfo()); } } } }
public void AddMessage(string messageId) { if (!_messageIds.ContainsKey(messageId)) { int preUpdateBuckets = _messageIds.BucketCount; _messageIds.Add(messageId, null); int postUpdateBuckets = _messageIds.BucketCount; if (postUpdateBuckets != preUpdateBuckets) { _size += (postUpdateBuckets - preUpdateBuckets) * MemoryUtil.NetHashtableOverHead; } } }
public void StartLogging(int bucket, LogMode loggingMode) { if (!_loggers.Contains(bucket)) { _loggers.Add(bucket, new OperationLogger(bucket, loggingMode)); } else { OperationLogger logger = _loggers[bucket] as OperationLogger; logger.LoggingMode = loggingMode; logger.BucketTransfered = false; logger.Clear(); } }
public void AddCacheKey(string cacheKey) { if (!_cacheKeys.ContainsKey(cacheKey)) { int preUpdateBuckets = _cacheKeys.BucketCount; _cacheKeys.Add(cacheKey, null); int postUpdateBuckets = _cacheKeys.BucketCount; if (postUpdateBuckets != preUpdateBuckets) { _size += (postUpdateBuckets - preUpdateBuckets) * MemoryUtil.NetHashtableOverHead; } } }
private StateTxfrInfo GetMessages(int bucketId) { long sizeToSend = 0; if (_parent.Context.NCacheLog.IsInfoEnabled) { _parent.Context.NCacheLog.Info("StateTxfrCorresponder.GetData(2)", "bucket size :" + _keyList.Count); } foreach (DictionaryEntry topicWiseMessage in _topicWiseMessageList) { ClusteredArrayList messageList = topicWiseMessage.Value as ClusteredArrayList; foreach (string messageId in messageList) { OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); TransferrableMessage message = _parent.InternalCache.GetTransferrableMessage(topicWiseMessage.Key as string, messageId); if (message != null) { if (sizeToSend > _threshold) { break; } ClusteredArrayList transferrableMessageList = _result[topicWiseMessage.Key] as ClusteredArrayList; if (transferrableMessageList == null) { transferrableMessageList = new ClusteredArrayList(); _result.Add(topicWiseMessage.Key, transferrableMessageList); } _messageCount++; transferrableMessageList.Add(message); sizeToSend += message.Message.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()); } _parent.Context.PerfStatsColl.IncrementStateTxfrPerSecStatsBy(_result.Count); return(new StateTxfrInfo(_result, false, sizeToSend, this.stream, true)); }
/// <summary> /// Provides implementation of Add method of the ICacheStorage interface. /// Add the key value pair to the store. /// </summary> /// <param name="key">key</param> /// <param name="item">object</param> /// <returns>returns the result of operation.</returns> public override StoreAddResult Add(object key, object item, Boolean allowExtendedSize) { try { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("Store.Add", ""); } lock (_itemDict.SyncRoot) { if (_itemDict.ContainsKey(key)) { return(StoreAddResult.KeyExists); } } StoreStatus status = HasSpace((ISizable)item, Common.MemoryUtil.GetStringSize(key), allowExtendedSize); CheckIfCacheNearEviction(); if (status == StoreStatus.HasNotEnoughSpace) { return(StoreAddResult.NotEnoughSpace); } lock (_itemDict.SyncRoot) { _itemDict.Add(key, item); base.Added(item as ISizable, Common.MemoryUtil.GetStringSize(key)); } if (status == StoreStatus.NearEviction) { return(StoreAddResult.SuccessNearEviction); } } catch (OutOfMemoryException e) { return(StoreAddResult.NotEnoughSpace); } catch (Exception e) { throw e; } return(StoreAddResult.Success); }
protected void AddBucketKeyIndex(DocumentKey key) { HashMapBucket bucket = _parent.GetKeyBucket(key); if (bucket != null) { lock (_bucketKeyIndex) { if (!_bucketKeyIndex.ContainsKey(bucket.BucketId)) { _bucketKeyIndex.Add(bucket.BucketId, new ClusteredList <DocumentKey>()); } _bucketKeyIndex[bucket.BucketId].Add(key); } } }
public void AddExclusion(HashVector excludeResult) { if (_excludeResults == null) { _excludeResults = new HashVector(); } IDictionaryEnumerator ie = excludeResult.GetEnumerator(); while (ie.MoveNext()) { if (!(_excludeResults.ContainsKey(ie.Key))) { _excludeResults.Add(ie.Key, null); } } }
/// <summary> /// Provides implementation of Add method of the ICacheStorage interface. /// Add the key value pair to the store. /// </summary> /// <param name="key">key</param> /// <param name="item">object</param> /// <returns>returns the result of operation.</returns> public override StoreAddResult Add(object key, IStorageEntry item, Boolean allowExtendedSize) { try { //if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("Store.Add", ""); lock (_itemDict.SyncRoot) { if (_itemDict.ContainsKey(key)) { return(StoreAddResult.KeyExists); } } StoreStatus status = HasSpace((ISizable)item, Common.MemoryUtil.GetStringSize(key), allowExtendedSize); CheckIfCacheNearEviction(); if (status == StoreStatus.HasNotEnoughSpace) { return(StoreAddResult.NotEnoughSpace); } lock (_itemDict.SyncRoot) { _itemDict.Add(key, item); base.Added(item, Common.MemoryUtil.GetStringSize(key)); item.MarkInUse(NCModulesConstants.CacheStore); } if (status == StoreStatus.NearEviction) { return(StoreAddResult.SuccessNearEviction); } } catch (OutOfMemoryException e) { //Trace.error("ClrHeapStorageProvider.Add()", e.ToString()); return(StoreAddResult.NotEnoughSpace); } catch (Exception e) { //Trace.error("ClrHeapStorageProvider.Add()", e.ToString()); //return StoreAddResult.Failure; throw e; } return(StoreAddResult.Success); }
/// <summary> /// Optimized Enqueue opeartion, adds the opeartion at _tail index and removes /// any previous operations on that key from the queue /// </summary> /// <param name="operation"></param> internal bool Enqueue(object cacheKey, IOptimizedQueueOperation operation) { bool isNewItem = true; try { lock (_sync_mutex) { if (_keyToIndexMap.ContainsKey(cacheKey)) //Optimized Queue, so checking in the map if the current cache key is already mapped to some index of Queue or not { //just update the old operation without chaning it's order in the queue. int index1 = (int)_keyToIndexMap[cacheKey]; IOptimizedQueueOperation oldOperation = _queue[index1] as IOptimizedQueueOperation; _queue[index1] = operation; isNewItem = false; _size -= oldOperation.Size; //subtract old operation size _size += operation.Size; oldOperation.ReturnPooledItemsToPool(_context?.TransactionalPoolManager); return(isNewItem); } if (_tail == int.MaxValue) //checks if the _tail value has reached the maxvalue of the long data type, so reinitialize it { _tail = -1; _tailMaxReached = true; } int index = ++_tail; _size += operation.Size; _queue.Add(index, operation); //Add new opeartion at the tail of the queue _keyToIndexMap[cacheKey] = index; // update (cache key, queue index) map _indexToKeyMap[index] = cacheKey; if (isNewItem) { _count++; } } } catch (Exception exp) { throw exp; } finally { } return(isNewItem); }
public void ClearCache(bool raisenotification) { lock (this) { foreach (KeyValuePair <string, ClientNotificationMgr> kvp in _clients) { kvp.Value.ClearKeys(); } _registeredKeys.Clear(); _removedKeys.Clear(); _updatedKeys.Clear(); } if (raisenotification) { lock (this) { IDictionaryEnumerator ide = _clients.GetEnumerator(); while (ide.MoveNext()) { _lastChangeTime = HPTime.Now; ((ClientNotificationMgr)ide.Value).AddKey(_clearKey, null, null); if (!_registeredKeys.ContainsKey(_clearKey)) { _registeredKeys.Add(_clearKey, new KeyInfo()); } KeyInfo keyInfo = _registeredKeys[_clearKey]; keyInfo.UpdatedTime = HPTime.Now; keyInfo = keyInfo.Clone() as KeyInfo; keyInfo.UpdatedBy = ide.Key as string; if (!_updatedKeys.ContainsKey(_clearKey)) { _updatedKeys.Add(_clearKey, keyInfo); } else { _updatedKeys[_clearKey] = keyInfo; } } } } }
public void Initialize(string groupList) { if (groupList != null) { string[] gList = groupList.Split(new char[] { ',' }); if (gList != null) { for (int i = 0; i < gList.Length; i++) { if (_groupMap.Contains(gList[i])) { _groupMap.Add(gList[i], null); } } } } }
public static IDictionary <T, HashSet <V> > DeserializeDictionaryHashSet <T, V>(CompactReader reader) { bool flag = reader.ReadBoolean(); IDictionary <T, HashSet <V> > dHashSet = new HashVector <T, HashSet <V> >(); if (flag) { T key; int dictionarylength = reader.ReadInt32(); for (int i = 0; i < dictionarylength; i++) { HashSet <V> valueHashSet; key = (T)reader.ReadObject(); valueHashSet = DeserializeHashSet <V>(reader); dHashSet.Add(key, valueHashSet); } } return(dHashSet); }
public void AddMessage(string topic, string messageId) { TopicWiseBucketStatistics topicStats = _topicWiseMessageIds[topic] as TopicWiseBucketStatistics; if (topicStats == null) { topicStats = new TopicWiseBucketStatistics(topic); _topicWiseMessageIds.Add(topic, topicStats); } int preUpdateSize = topicStats.InMemorySize; topicStats.AddMessage(messageId); int postUpdateSize = topicStats.InMemorySize; if (preUpdateSize != postUpdateSize) { _size += postUpdateSize - preUpdateSize; } }