public void Update(ContinuousQuery query, string clientId, string clientUniqueId, bool notifyAdd, bool notifyUpdate, bool notifyRemove, QueryDataFilters datafilters) { lock (this) { if (clientRefs.ContainsKey(query.UniqueId)) { HashVector cRefs = (HashVector)clientRefs[query.UniqueId]; if (cRefs.ContainsKey(clientId)) { ClusteredList <string> refs = (ClusteredList <string>)cRefs[clientId]; if (!refs.Contains(clientUniqueId)) { refs.Add(clientUniqueId); } } else { ClusteredList <string> clientUniqueIds = new ClusteredList <string>(); clientUniqueIds.Add(clientUniqueId); cRefs[clientId] = clientUniqueIds; } UpdateNotifications(notifyAdd, clientId, query.UniqueId, clientUniqueId, addNotifications, datafilters.AddDataFilter, maxAddDFAgainstCID, addDFAgainstCUniqueID); UpdateNotifications(notifyUpdate, clientId, query.UniqueId, clientUniqueId, updateNotifications, datafilters.UpdateDataFilter, maxUpdateDFAgainstCID, updateDFAgainstCUniqueID); UpdateNotifications(notifyRemove, clientId, query.UniqueId, clientUniqueId, removeNotifications, datafilters.RemoveDataFilter, maxRemoveDFAgainstCID, removeDFAgainstCUniqueID); } } }
public void UnRegisterKeyNotification(string clientId, string key, CallbackInfo updateCallback, CallbackInfo removeCallback) { if (clientId == null) { return; } lock (this) { if (!_clients.ContainsKey(clientId)) { return; } if (_clients[clientId].RemoveKey(key)) { if (_registeredKeys.ContainsKey(key)) { if (_registeredKeys[key].DecrementRefCount() <= 0) { _registeredKeys.Remove(key); if (_updatedKeys.ContainsKey(key)) { _updatedKeys.Remove(key); } if (_removedKeys.ContainsKey(key)) { _removedKeys.Remove(key); } } } } } }
public void ClearKeys() { lock (_interestedKeys) { foreach (KeyValuePair <string, NotificationEntry> entry in _interestedKeys) { if (entry.Value.NotifyOnUpdate) { if (_updatedKeys.ContainsKey(entry.Key)) { DecrementOrRemove(ref _updatedKeys, entry.Key); } } if (entry.Value.NotifyOnRemove) { if (_removedKeys.ContainsKey(entry.Key)) { DecrementOrRemove(ref _removedKeys, entry.Key); } } } _interestedKeys.Clear(); } }
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; } } }
/// <summary> /// Determines whether the store contains a specific key. /// </summary> /// <param name="key">The key to locate in the store.</param> /// <returns>true if the store contains an element /// with the specified key; otherwise, false.</returns> public override bool Contains(object key) { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("Store.Cont", ""); } return(_itemDict.ContainsKey(key)); }
public EventDataFilter GetDataFilter(string serverUID, string clientID, QueryChangeType type) { HashVector clientDF = null; EventDataFilter datafilter = EventDataFilter.None; if (type == QueryChangeType.Add) { if (maxAddDFAgainstCID.ContainsKey(serverUID)) { clientDF = maxAddDFAgainstCID[serverUID] as HashVector; if (clientDF.ContainsKey(clientID)) { datafilter = (EventDataFilter)clientDF[clientID]; } return(datafilter); } else { return(EventDataFilter.None); } } else if (type == QueryChangeType.Update) { if (maxUpdateDFAgainstCID.ContainsKey(serverUID)) { clientDF = maxUpdateDFAgainstCID[serverUID] as HashVector; if (clientDF.ContainsKey(clientID)) { datafilter = (EventDataFilter)clientDF[clientID]; } return(datafilter); } else { return(EventDataFilter.None); } } else { if (maxRemoveDFAgainstCID.ContainsKey(serverUID)) { clientDF = maxRemoveDFAgainstCID[serverUID] as HashVector; if (clientDF.ContainsKey(clientID)) { datafilter = (EventDataFilter)clientDF[clientID]; } return(datafilter); } else { return(EventDataFilter.None); } } }
public void PushInTaskOutput(string taskId, TaskOutput output) { lock (objectMutex) { if (!taskOutput.ContainsKey(taskId)) { taskOutput.Add(output.TaskId, output); } } }
public void AddObject(object obj, CollectionOperation op) { if (_excludeResults != null && _excludeResults.ContainsKey(obj)) { return; } if (!(_resultKeys.ContainsKey(obj))) { _resultKeys[obj] = null; _wrappedResult.AddObject(obj, op); } }
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 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; } } }
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 bool MoveNext() { if (_dataWithValue != null && _index < _chunkKeys.Count) { object key = _chunkKeys[_index++]; if (_dataWithValue.ContainsKey(key)) { if (_getData) { _currentValue = new ClusteredArray <object>(2); _currentValue[0] = key; _currentValue[1] = _dataWithValue[key]; return(true); } else { _currentValue = new ClusteredArray <object>(1); _currentValue[0] = key; return(true); } } else { return(HasMoreData); } } return(HasMoreData); }
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> ///Insert Value ///</summary> public void Insert(object key, object value) { if (!Data.ContainsKey(key)) { Data.Add(key, null); } }
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 virtual void Initialize(ArrayList attribList) { IIndexStore store; if (attribList != null && attribList.Count > 0) { IEnumerator e = attribList.GetEnumerator(); while (e.MoveNext()) { string attribName = e.Current.ToString(); if (commonRbStores != null && commonRbStores.ContainsKey(_type + ":" + attribName)) { IIndexStore commonStore = (IIndexStore)commonRbStores[_type + ":" + attribName]; IndexTable.Add(attribName, commonStore); } else { String storeDataType = String.Empty; if (_typeMap != null) { storeDataType = _typeMap.GetAttributeType(this.TypeName, attribName); } Type genericType = typeof(RBStore <>).MakeGenericType(Common.MemoryUtil.GetDataType(storeDataType)); store = (IIndexStore)Activator.CreateInstance(genericType, new object[] { CacheName, storeDataType, attribName, _haveDuplicateKeys }); IndexTable.Add(attribName, store); } } if (commonRbStores != null && commonRbStores.ContainsKey(TAG_INDEX_KEY)) { store = (IIndexStore)commonRbStores[TAG_INDEX_KEY]; IndexTable.Add(TAG_INDEX_KEY, store); } else { Type genericType = typeof(RBStore <>).MakeGenericType(Common.MemoryUtil.GetDataType(Common.MemoryUtil.Net_System_String)); store = (IIndexStore)Activator.CreateInstance(genericType, new object[] { CacheName, Common.MemoryUtil.Net_System_String, TAG_INDEX_KEY, _haveDuplicateKeys }); IndexTable.Add(TAG_INDEX_KEY, store); } } if (!IndexTable.ContainsKey(TAG_INDEX_KEY) && commonRbStores != null && commonRbStores.ContainsKey(TAG_INDEX_KEY)) { store = (IIndexStore)commonRbStores[TAG_INDEX_KEY]; IndexTable.Add(TAG_INDEX_KEY, store); } }
/// <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 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)); }
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 bool AddKey(string key, CallbackInfo updateCallback, CallbackInfo removeCallback) { lock (_interestedKeys) { if (!_interestedKeys.ContainsKey(key)) { _interestedKeys.Add(key, new NotificationEntry(updateCallback, removeCallback) { RegistrationTime = HPTime.Now }); return(true); } else { NotificationEntry entry = _interestedKeys[key]; entry.SetNotifications(updateCallback, removeCallback); _interestedKeys[key] = entry; } } return(false); }
public void RegisterRequest(long requestId, long commandId, long lastAcknowledged) { if (requestId > -1) { CommandLog commands; lock (requestBook) { if (!requestBook.ContainsKey(requestId)) { commands = new CommandLog(); requestBook.Add(requestId, commands); } else { commands = (CommandLog)requestBook[requestId]; size -= commands.InMemorySize; } } commands.MakeEntry(commandId); size += commands.InMemorySize; } lastAcknowledgedId = lastAcknowledged; }
private void UnregisterDataFilter(string serverUID, string clientID, string clientUID, HashVector CID, HashVector CUID) { //updating clientUIDs HashVector clientUIDs = null; if (CUID.ContainsKey(clientID)) { clientUIDs = CUID[clientID] as HashVector; clientUIDs.Remove(clientUID); if (clientUIDs.Count == 0) { CUID[clientID] = null; clientUIDs = CUID[clientID] as HashVector; CUID.Remove(clientID); } } //updating Max values HashVector clientDF = null; if (CID.ContainsKey(serverUID)) { clientDF = CID[serverUID] as HashVector; EventDataFilter max = EventDataFilter.None; if (clientUIDs != null) { IDictionaryEnumerator ide = clientUIDs.GetEnumerator(); while (ide.MoveNext()) { if (((EventDataFilter)ide.Value) > max) { max = (EventDataFilter)ide.Value; } } if (!clientDF.ContainsKey(clientID) || ((EventDataFilter)clientDF[clientID]) < max) { clientDF[clientID] = max; } } else { ((IDictionary)CID[serverUID]).Remove(clientID); if (((IDictionary)CID[serverUID]).Count == 0) { CID.Remove(serverUID); } } } }
//assumption contains checks are outside this function private void DecrementOrRemove(ref HashVector <string, KeyInfo> keyVector, string key) { lock (keyVector) { if (keyVector.ContainsKey(key)) { KeyInfo kInfo = keyVector[key]; if (kInfo.DecrementRefCount() <= 0) { keyVector.Remove(key); } } } }
public bool UnRegister(string serverUniqueId, string clientUniqueId, string clientId) { lock (this) { if (clientRefs.ContainsKey(serverUniqueId)) { HashVector cRefs = (HashVector)clientRefs[serverUniqueId]; if (cRefs.ContainsKey(clientId)) { ClusteredList <string> refs = (ClusteredList <string>)cRefs[clientId]; if (refs.Count > 0) { refs.Remove(clientUniqueId); UnRegisterNotifications(serverUniqueId, clientUniqueId, clientId, addNotifications, maxAddDFAgainstCID, addDFAgainstCUniqueID); UnRegisterNotifications(serverUniqueId, clientUniqueId, clientId, updateNotifications, maxUpdateDFAgainstCID, updateDFAgainstCUniqueID); UnRegisterNotifications(serverUniqueId, clientUniqueId, clientId, removeNotifications, maxRemoveDFAgainstCID, removeDFAgainstCUniqueID); if (refs.Count == 0) { cRefs.Remove(clientId); } } if (cRefs.Count == 0) { int qIndex = -1; foreach (ContinuousQuery query in registeredQueries) { if (query.UniqueId.Equals(serverUniqueId)) { qIndex = registeredQueries.IndexOf(query); break; } } if (qIndex != -1) { registeredQueries.RemoveAt(qIndex); } return(true); } } } return(false); } }
public bool AllowNotification(string queryId, string clientId, QueryChangeType changeType) { lock (this) { if (changeType == QueryChangeType.Add) { if (addNotifications.ContainsKey(queryId)) { HashVector clients = (HashVector)addNotifications[queryId]; if (clients != null && clients.ContainsKey(clientId)) { return(true); } } } else if (changeType == QueryChangeType.Update) { if (updateNotifications.ContainsKey(queryId)) { HashVector clients = updateNotifications[queryId] as HashVector; if (clients != null && clients.ContainsKey(clientId)) { return(true); } } } else { if (removeNotifications.ContainsKey(queryId)) { HashVector clients = removeNotifications[queryId] as HashVector; if (clients != null && clients.ContainsKey(clientId)) { return(true); } } } return(false); } }
public void UpdateIndex(object key, CacheEntry entry) { if (key == null || entry == null || entry.ExpirationHint == null || !entry.ExpirationHint.IsIndexable) { return; } ExpirationHint hint = entry.ExpirationHint; lock (_status_mutex) { int addSize = hint.InMemorySize; if (!IsInProgress) { if (_mainIndex.Contains(key)) { ExpirationHint expHint = _mainIndex[key] as ExpirationHint; addSize -= expHint.InMemorySize; } _mainIndex[key] = hint; } else { if (_transitoryIndex.ContainsKey(key)) { ExpirationHint expHint = _transitoryIndex[key] as ExpirationHint; if (expHint != null) { addSize -= expHint.InMemorySize; } } _transitoryIndex[key] = hint; } _expirationManagerSize += addSize; } }
internal IDictionary <long, DataSlice> RecreateSliceMetaInfo(Stream stream) { IDictionary <long, DataSlice> sliceMap = new HashVector <long, DataSlice>(); foreach (Segment seg in _segmentMap.Values) { List <DataSlice> _sliceList = seg.RecreateSliceMetaInfo(stream); foreach (DataSlice _slice in _sliceList) { if (!sliceMap.ContainsKey(_slice.SliceHeader.Id)) { sliceMap.Add(_slice.SliceHeader.Id, _slice); } else { sliceMap[_slice.SliceHeader.Id].SliceHeader.SegmentIds.Add(seg.SegmentHeader.Id); sliceMap[_slice.SliceHeader.Id].SliceHeader.TotalSize += _slice.SliceHeader.TotalSize; } } } return(sliceMap); }
/// <summary> /// handles the case for 'AND' condition /// </summary> /// <param name="list"></param> /// <returns></returns> private ClusteredArrayList GetIntersection(SortedList list) { HashVector finalTable = new HashVector(); if (list.Count > 0) { ClusteredArrayList keys = list.GetByIndex(0) as ClusteredArrayList; for (int i = 0; i < keys.Count; i++) { finalTable[keys[i]] = null; } for (int i = 1; i < list.Count; i++) { HashVector shiftTable = new HashVector(); keys = list.GetByIndex(i) as ClusteredArrayList; if (keys != null) { for (int j = 0; j < keys.Count; j++) { object key = keys[j]; if (finalTable.ContainsKey(key)) { shiftTable[key] = null; } } } finalTable = shiftTable; } } return(new ClusteredArrayList(finalTable.Keys)); }
private void UnRegisterNotifications(string serverUniqueId, string clientUniqueId, string clientId, HashVector notifications , HashVector CID, HashVector CUID) { if (notifications.ContainsKey(serverUniqueId)) { HashVector clients = notifications[serverUniqueId] as HashVector; if (clients.ContainsKey(clientId)) { ClusteredList <string> clientQueries = clients[clientId] as ClusteredList <string>; if (clientQueries.Contains(clientUniqueId)) { clientQueries.Remove(clientUniqueId); if (clientQueries.Count == 0) { clients.Remove(clientId); } } } } UnregisterDataFilter(serverUniqueId, clientId, clientUniqueId, CID, CUID); }
public bool ContainsValue(v value) { return(_valueToKey.ContainsKey(value)); }