private void PollRequest(string clientId, short callbackId, EventTypeInternal eventType) { if (_client != null) { //client older then 4.1 sp2 private patch 4 does not support bulk Events if (_client.ClientVersion >= 4124) { Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse eventItem = new Common.Protobuf.BulkEventItemResponse(); eventItem.eventType = Common.Protobuf.BulkEventItemResponse.EventType.POLL_NOTIFY_EVENT; eventItem.pollNotifyEvent = EventHelper.GetPollNotifyEvent(callbackId, eventType); //To avoid NullReference problem if both evnt and NCache.Dispose are called simultaenously ClientManager client = _client; if (client != null) { client.ConnectionManager.EnqueueEvent(eventItem, _client.SlaveId); } } else { lock (ConnectionManager.CallbackQueue) { ConnectionManager.CallbackQueue.Enqueue(new CallbackTasks.PollRequestCallback(_client.ClientID, callbackId, eventType)); Monitor.Pulse(ConnectionManager.CallbackQueue); } } } }
internal void RaisePollNotification(short callbackId, EventTypeInternal eventType) { try { // just invoke the callback if not null. // callbackId is of no use here. PollNotificationCallback _pollCallback = null; if ((eventType & EventTypeInternal.PubSub) != 0) { _pollCallback = _pollPubSubCallback; } if (_pollCallback != null) { _pollCallback.Invoke(); } } catch (Exception ex) { if (_logger != null && _logger.IsErrorEnabled) { _logger.CriticalInfo(ex.ToString()); } } }
internal static PollNotifyEventResponse GetPollNotifyEvent(int callbackId, EventTypeInternal eventType) { PollNotifyEventResponse response = new PollNotifyEventResponse(); response.callbackId = callbackId; response.eventType = (int)eventType; return(response); }
internal short RegisterPollingEvent(PollNotificationCallback callback, EventTypeInternal eventType) { // Only one poll callback can be configured. // No need to use pools. if ((eventType & EventTypeInternal.PubSub) != 0) { _pollPubSubCallback = callback; } return(10001); }
/// <summary> /// Returns the filter type of the eventType /// </summary> /// <param name="eventType"></param> /// <returns></returns> internal EventDataFilter MaxFilterAgainstEvent(EventTypeInternal eventType) { if ((eventType & EventTypeInternal.ItemAdded) != 0) { return(_addDataFilter); } if ((eventType & EventTypeInternal.ItemRemoved) != 0) { return(_removeDataFilter); } if ((eventType & EventTypeInternal.ItemUpdated) != 0) { return(_updateDataFilter); } return(EventDataFilter.None); }
/// <summary> /// Provide /// </summary> /// <param name="eventType"></param> /// <returns></returns> internal short GeneralEventRefCountAgainstEvent(EventTypeInternal eventType) { if ((eventType & EventTypeInternal.ItemAdded) != 0) { return(_addEventRegistrationSequence); } if ((eventType & EventTypeInternal.ItemRemoved) != 0) { return(_removeEventRegistrationSequenceId); } if ((eventType & EventTypeInternal.ItemUpdated) != 0) { return(_updateEventRegisrationSequenceId); } return(-1); }
private ResourcePool GetEventPool(EventTypeInternal eventType) { ResourcePool pool = null; if ((eventType & EventTypeInternal.ItemAdded) != 0) { pool = _addEventPool; } else if ((eventType & EventTypeInternal.ItemRemoved) != 0) { pool = _removeEventPool; } else if ((eventType & EventTypeInternal.ItemUpdated) != 0) { pool = _updateEventPool; } return(pool); }
internal static EventTypeInternal GetEventTypeInternal(Runtime.Events.EventType eventType) { EventTypeInternal eventTypeInternal = EventTypeInternal.None; if ((eventType & EventType.ItemAdded) != 0) { eventTypeInternal |= EventTypeInternal.ItemAdded; } if ((eventType & EventType.ItemUpdated) != 0) { eventTypeInternal |= EventTypeInternal.ItemUpdated; } if ((eventType & EventType.ItemRemoved) != 0) { eventTypeInternal |= EventTypeInternal.ItemRemoved; } return(eventTypeInternal); }
/// <summary> /// Unregisters CacheDataNotificationCallback /// <para>Flag based unregistration</para> /// </summary> /// <param name="callback"></param> /// <param name="key"></param> /// <param name="eventType"></param> internal short[] UnregisterSelectiveNotification(CacheDataNotificationCallback callback, EventTypeInternal eventType) { if (callback == null) { return(null); } short[] returnValue = new short[] { -1, -1 }; //First value update callback ref & sencond is remove callbackref foreach (EventTypeInternal type in Enum.GetValues(typeof(EventTypeInternal))) { if (type == EventTypeInternal.ItemAdded) //ItemAdded not supported Yet { continue; } object id = -1; lock (SyncLockSelective) { ResourcePool pool = null; ResourcePool poolID = null; #region pool selection if (type == EventTypeInternal.ItemRemoved && (eventType & EventTypeInternal.ItemRemoved) != 0) { pool = _selectiveRemoveEventPool; poolID = _selectiveRemoveEventIDPool; if (pool == null) { removeCallbacks = 0; } } else if (type == EventTypeInternal.ItemUpdated && (eventType & EventTypeInternal.ItemUpdated) != 0) { pool = _selectiveUpdateEventPool; poolID = _selectiveUpdateEventIDPool; if (pool == null) { updateCallbacks = 0; } } if (removeCallbacks == 0 && updateCallbacks == 0) { _selectiveEventsSubscription.UnSubscribeEventTopic(); _selectiveEventsSubscription = null; } if (pool == null) { continue; } #endregion int i = type == EventTypeInternal.ItemUpdated ? 0 : 1; id = pool.GetResource(callback); if (id is short) { returnValue[i] = (short)id; } } } return(returnValue); }
private bool RegisterGeneralDiscriptor(CacheEventDescriptor discriptor, EventTypeInternal eventType) { if (discriptor == null) { return(false); //FAIL CONDITION } EventHandle handle = null; foreach (EventTypeInternal type in Enum.GetValues(typeof(EventTypeInternal))) { ResourcePool pool = null; bool registrationUpdated = false; #region Pool selection if ((type & eventType) != 0) { pool = GetEventPool(type); } if (pool == null) { continue; } #endregion short registrationSequenceId = -1; lock (SyncLockGeneral) { pool.AddResource(discriptor, 1); // Everytime a new Discriptor is forcefully created //Keeps a sequence number switch (type) { case EventTypeInternal.ItemAdded: if (discriptor.DataFilter > _generalAddDataFilter || _addEventRegistrationSequence == REFSTART) { registrationUpdated = true; registrationSequenceId = ++_addEventRegistrationSequence; _generalAddDataFilter = discriptor.DataFilter; } else { registrationSequenceId = _addEventRegistrationSequence; } break; case EventTypeInternal.ItemRemoved: if (discriptor.DataFilter > _generalRemoveDataFilter || _removeEventRegistrationSequenceId == REFSTART) { registrationUpdated = true; registrationSequenceId = ++_removeEventRegistrationSequenceId; _generalRemoveDataFilter = discriptor.DataFilter; } else { registrationSequenceId = _removeEventRegistrationSequenceId; } break; case EventTypeInternal.ItemUpdated: if (discriptor.DataFilter > _generalUpdateDataFilter || _updateEventRegisrationSequenceId == REFSTART) { registrationUpdated = true; registrationSequenceId = ++_updateEventRegisrationSequenceId; _generalUpdateDataFilter = discriptor.DataFilter; } else { registrationSequenceId = _updateEventRegisrationSequenceId; } break; } //Although the handle doesnt matter in general events if (handle == null) { handle = new EventHandle(registrationSequenceId); } } if (_cache != null && registrationSequenceId != -1) { _cache.RegisterCacheNotificationDataFilter(type, discriptor.DataFilter, registrationSequenceId); } } discriptor.IsRegistered = true; discriptor.Handle = handle; return(true); }
/// <summary> /// Returning Negative value means operation not successfull /// </summary> /// <param name="discriptor"></param> /// <param name="eventType"></param> /// <returns>short array <para>1st value is Update callbackRef</para> <para>nd value is removeRef</para></returns> private short[] RegisterSelectiveDiscriptor(CacheDataNotificationCallback callback, EventTypeInternal eventType, CallbackType callbackType) { if (callback == null) { return(null); //FAIL CONDITION } short[] returnValue = new short[] { -1, -1 }; //First value update callback ref & sencond is remove callbackref foreach (EventTypeInternal type in Enum.GetValues(typeof(EventTypeInternal))) { if (type == EventTypeInternal.ItemAdded) //ItemAdded not supported Yet { continue; } lock (SyncLockSelective) { ResourcePool pool = null; ResourcePool poolID = null; #region pool selection if (type == EventTypeInternal.ItemRemoved && (eventType & EventTypeInternal.ItemRemoved) != 0) { pool = _selectiveRemoveEventPool; poolID = _selectiveRemoveEventIDPool; } else if (type == EventTypeInternal.ItemUpdated && (eventType & EventTypeInternal.ItemUpdated) != 0) { pool = _selectiveUpdateEventPool; poolID = _selectiveUpdateEventIDPool; } if (pool == null) { continue; } #endregion while (true) { int i = type == EventTypeInternal.ItemUpdated ? 0 : 1; if (pool.GetResource(callback) == null) { returnValue[i] = type == EventTypeInternal.ItemUpdated ? ++_selectiveUpdateCallbackRef : ++_selectveRemoveCallbackRef; pool.AddResource(callback, returnValue[i]); poolID.AddResource(returnValue[i], callback); break; } else { try { short cref = (short)pool.GetResource(callback); if (cref < 0) { break; //FAIL CONDITION } //add it again into the table for updating ref count. pool.AddResource(callback, cref); poolID.AddResource(cref, callback); returnValue[i] = cref; break; } catch (NullReferenceException) { //Legacy code: can create an infinite loop //Recomendation of returning a negative number instead of continue continue; } } } } } if (_selectiveEventsSubscription == null && callbackType != CallbackType.PullBasedCallback) { Topic topic = (Topic)_cache._messagingService.GetTopic(TopicConstant.ItemLevelEventsTopic, true); _selectiveEventsSubscription = (TopicSubscription)topic.CreateEventSubscription(OnSelectiveEventMessageReceived); } return(returnValue); }
public virtual void RegisterGeneralNotification(EventTypeInternal eventType, EventDataFilter datafilter, short sequenceNumber) { }
public virtual void UnRegisterGeneralNotification(EventTypeInternal unregister, short sequenceNumber) { }
/// <summary> /// Registeres the callback sepeartely and returns short values of registeredCallbacks /// </summary> /// <param name="key"></param> /// <param name="callback"></param> /// <param name="eventType"></param> /// <param name="datafilter"></param> /// <returns>short array,<para>1st element is updated callbackRef</para><para>2st element is removed callbackRef</para></returns> internal short[] RegisterSelectiveEvent(CacheDataNotificationCallback callback, EventTypeInternal eventType, EventDataFilter datafilter, CallbackType callbackType = CallbackType.PushBasedNotification) { if (callback != null) { //Avoiding new ResourcePool(inside = new Hashtable) at constructor level if (_selectiveUpdateEventPool == null) { _selectiveUpdateEventPool = new ResourcePool(); _selectiveUpdateEventIDPool = new ResourcePool(); } if (_selectiveRemoveEventPool == null) { _selectiveRemoveEventPool = new ResourcePool(); _selectiveRemoveEventIDPool = new ResourcePool(); } return(RegisterSelectiveDiscriptor(callback, eventType, callbackType)); } else { return(null); } }
public virtual void UnRegisterKeyNotificationCallback(string[] key, short update, short remove, EventTypeInternal eventType) { }
public EventRegistrationInfo(EventTypeInternal eventTYpe, EventDataFilter filter, short sequenceId) { _eventType = eventTYpe; _filter = filter; _registrationSequence = sequenceId; }
internal PollRequestCallback(string clientId, int callbackId, EventTypeInternal eventType) { _clientId = clientId; _callbackId = callbackId; _eventType = eventType; }