Exemplo n.º 1
0
        /// <summary>
        /// Called when item is updated
        /// </summary>
        /// <param name="key">key of the item being updated</param>
        /// <param name="callbackEntry">callback entry that contains the updated value</param>
        private void CustomUpdate(object key, object callbackInfo, EventContext eventContext)
        {
            if (_client != null)
            {
                CallbackInfo cbInfo = callbackInfo as CallbackInfo;
                if (cbInfo != null && cbInfo.Client == _client.ClientID)
                {
                    //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.ITEM_UPDATED_CALLBACK;
                        eventitem.ItemUpdatedCallback = EventHelper.GetItemUpdatedCallbackResponse(eventContext, (string)key, (short)cbInfo.Callback, cbInfo.DataFilter);

                        //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 ItemUpdateCallback((short)cbInfo.Callback, (string)key, cbInfo.Client, eventContext, cbInfo.DataFilter));
                            Monitor.Pulse(ConnectionManager.CallbackQueue);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This function is called by CacheStopedCallback
        /// </summary>
        private void CacheStopped()
        {
            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.CACHE_STOPPED_EVENT;
                    eventItem.cacheStoppedEvent = EventHelper.GetCacheStoppedEventResponse(_cacheId);

                    //_client.EnqueueEvent(eventItem);
                    //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 CacheStoppedEvent(_cacheId, _client.ClientID));
                        Monitor.Pulse(ConnectionManager.CallbackQueue);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="notifId"></param>
        /// <param name="value"></param>
        private void CustomNotification(object notifId, object value, EventContext eventContext)
        {
            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.RAISE_CUSTOM_EVENT;
                    eventItem.CustomEvent = EventHelper.GetCustomEventResponse((byte[])notifId, (byte[])value);

                    //_client.EnqueueEvent(eventItem);
                    //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)
                    {
                        if (_client == null)
                        {
                            return;
                        }
                        ConnectionManager.CallbackQueue.Enqueue(new CustomEvent(_cacheId, (byte[])notifId, (byte[])value, _client.ClientID));
                        Monitor.Pulse(ConnectionManager.CallbackQueue);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This function is called by ItemRemovedCallback
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="reason"></param>
        private void ItemRemoved(object key, object value, ItemRemoveReason reason, BitSet Flag, EventContext eventContext)
        {
            //value which arrives will be null
            value = eventContext.Item.Value;

            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.ITEM_REMOVED_EVENT;
                    eventItem.itemRemovedEvent = EventHelper.GetItemRemovedEventResponse(eventContext, (string)key, this.ItemRemovedFilter, Flag, reason, (UserBinaryObject)value);

                    // _client.EnqueueEvent(eventItem);
                    //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 ItemRemovedEvent((string)key, _cacheId, reason, (UserBinaryObject)value, _client.ClientID, Flag, eventContext));
                        Monitor.Pulse(ConnectionManager.CallbackQueue);
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// This function is called by ItemUpdatedCallback
        /// </summary>
        /// <param name="key"></param>
        private void ItemUpdated(object key, EventContext eventContext)
        {
            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.ITEM_UPDATED_EVENT;
                    eventItem.itemUpdatedEvent = EventHelper.GetItemUpdatedEventResponse(eventContext, (string)key, this.ItemUpdatedFilter);

                    //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)
                    {
                        if (_client != null)
                        {
                            ConnectionManager.CallbackQueue.Enqueue(new ItemUpdatedEvent((string)key, _cacheId, _client.ClientID, eventContext));
                            Monitor.Pulse(ConnectionManager.CallbackQueue);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        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);
                    }
                }
            }
        }
Exemplo n.º 7
0
        internal static EventId ConvertToEventID(Common.Protobuf.BulkEventItemResponse eventItem, Alachisoft.NCache.Persistence.EventType eventType)
        {
            EventId eventId = eventId = new EventId();

            switch (eventType)
            {
            case Persistence.EventType.ITEM_ADDED_EVENT:
                eventId.EventUniqueID    = eventItem.itemAddedEvent.eventId.eventUniqueId;
                eventId.EventCounter     = eventItem.itemAddedEvent.eventId.eventCounter;
                eventId.OperationCounter = eventItem.itemAddedEvent.eventId.operationCounter;
                eventId.EventType        = Persistence.EventType.ITEM_ADDED_EVENT;
                break;

            case Persistence.EventType.ITEM_UPDATED_EVENT:
                eventId.EventUniqueID    = eventItem.itemUpdatedEvent.eventId.eventUniqueId;
                eventId.EventCounter     = eventItem.itemUpdatedEvent.eventId.eventCounter;
                eventId.OperationCounter = eventItem.itemUpdatedEvent.eventId.operationCounter;
                eventId.EventType        = Persistence.EventType.ITEM_UPDATED_EVENT;
                break;

            case Persistence.EventType.ITEM_UPDATED_CALLBACK:
                eventId.EventUniqueID    = eventItem.ItemUpdatedCallback.eventId.eventUniqueId;
                eventId.EventCounter     = eventItem.ItemUpdatedCallback.eventId.eventCounter;
                eventId.OperationCounter = eventItem.ItemUpdatedCallback.eventId.operationCounter;
                eventId.EventType        = Persistence.EventType.ITEM_UPDATED_CALLBACK;
                break;



            case Persistence.EventType.ITEM_REMOVED_CALLBACK:
                eventId.EventUniqueID    = eventItem.itemRemoveCallback.eventId.eventUniqueId;
                eventId.EventCounter     = eventItem.itemRemoveCallback.eventId.eventCounter;
                eventId.OperationCounter = eventItem.itemRemoveCallback.eventId.operationCounter;
                eventId.EventType        = Persistence.EventType.ITEM_REMOVED_CALLBACK;
                break;

            case Persistence.EventType.ITEM_REMOVED_EVENT:
                eventId.EventUniqueID    = eventItem.itemRemovedEvent.eventId.eventUniqueId;
                eventId.EventCounter     = eventItem.itemRemovedEvent.eventId.eventCounter;
                eventId.OperationCounter = eventItem.itemRemovedEvent.eventId.operationCounter;
                eventId.EventType        = Persistence.EventType.ITEM_REMOVED_EVENT;
                break;

            case Persistence.EventType.CACHE_CLEARED_EVENT:
                eventId.EventUniqueID    = eventItem.cacheClearedEvent.eventId.eventUniqueId;
                eventId.EventCounter     = eventItem.cacheClearedEvent.eventId.eventCounter;
                eventId.OperationCounter = eventItem.cacheClearedEvent.eventId.operationCounter;
                eventId.EventType        = Persistence.EventType.CACHE_CLEARED_EVENT;
                break;
            }
            return(eventId);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Called when an async operation is completed
        /// </summary>
        /// <param name="key">key being used for async operation</param>
        /// <param name="callbackEntry">callback entry being used for async operation</param>
        private void AsyncOperationCompleted(object opCode, object result, EventContext eventContext)
        {
            if (result is object[])
            {
                if (_client != null)
                {
                    AsyncCallbackInfo cbInfo = ((object[])result)[1] as AsyncCallbackInfo;
                    if (cbInfo != null && cbInfo.Client != _client.ClientID)
                    {
                        return;
                    }
                    //client older then 4.1 sp2 private patch 4 does not support bulk Events
                    if (_client.ClientVersion >= 4124)
                    {
                        object[] package = null;
                        package = (object[])SerializationUtil.CompactDeserialize(result, _cacheId);

                        string            key           = (string)package[0];
                        AsyncCallbackInfo cbInformation = (AsyncCallbackInfo)package[1];
                        object            opResult      = package[2];

                        Alachisoft.NCache.Common.Protobuf.AsyncOperationCompletedCallbackResponse asyncOperationCompleted = EventHelper.GetAsyncOpCompletedResponse(_client, cbInformation, opResult, opCode, key);

                        Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse eventitem = new Common.Protobuf.BulkEventItemResponse();
                        eventitem.eventType = Common.Protobuf.BulkEventItemResponse.EventType.ASYNC_OP_COMPLETED_EVENT;
                        eventitem.asyncOperationCompletedCallback = asyncOperationCompleted;

                        //_client.EnqueueEvent(eventitem);
                        //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 AsyncOpCompletedCallback(/*notification.CallerID,*/ opCode, result, /*notification.ClientSocket,*/ _cacheId));
                            Monitor.Pulse(ConnectionManager.CallbackQueue);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="callbackEntry"></param>
        /// <param name="reason"></param>
        private void CustomRemove(object key, object value, ItemRemoveReason reason, BitSet Flag, EventContext eventContext)
        {
            if (_client != null)
            {
                object[] args = value as object[];
                if (args != null)
                {
                    object       val    = args[0];
                    CallbackInfo cbInfo = args[1] as CallbackInfo;
                    if (cbInfo != null && cbInfo.Client == _client.ClientID)
                    {
                        //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.ITEM_REMOVED_CALLBACK;
                            eventItem.itemRemoveCallback = EventHelper.GetItemRemovedCallbackResponse(eventContext, (short)cbInfo.Callback, (string)key, (UserBinaryObject)val, Flag, reason, cbInfo.DataFilter);

                            // _client.EnqueueEvent(eventItem);
                            //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 ItemRemoveCallback((short)cbInfo.Callback, (string)key, val, reason, _client.ClientID, Flag, eventContext, cbInfo.DataFilter));
                                Monitor.Pulse(ConnectionManager.CallbackQueue);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Called when item is updated
        /// </summary>
        /// <param name="key">key of the item being updated</param>
        /// <param name="callbackEntry">callback entry that contains the updated value</param>
        private void CustomUpdate(object key, object callbackInfo, EventContext eventContext)
        {
            if (_client != null)
            {
                CallbackInfo cbInfo = callbackInfo as CallbackInfo;
                if (cbInfo != null && cbInfo.Client == _client.ClientID)
                {
                    //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.ITEM_UPDATED_CALLBACK;
                        eventitem.ItemUpdatedCallback = EventHelper.GetItemUpdatedCallbackResponse(eventContext, (string)key, (short)cbInfo.Callback, cbInfo.DataFilter);

                        //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 ItemUpdateCallback((short)cbInfo.Callback, (string)key, cbInfo.Client, eventContext, cbInfo.DataFilter));
                            Monitor.Pulse(ConnectionManager.CallbackQueue);
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="callbackEntry"></param>
        /// <param name="reason"></param>
        private void CustomRemove(object key, object value, ItemRemoveReason reason, BitSet Flag, EventContext eventContext)
        {
            if (_client != null)
            {
                object[] args = value as object[];
                if (args != null)
                {
                    object val = args[0];
                    CallbackInfo cbInfo = args[1] as CallbackInfo;
                    if (cbInfo != null && cbInfo.Client == _client.ClientID)
                    {
                        //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.ITEM_REMOVED_CALLBACK;
                            eventItem.itemRemoveCallback = EventHelper.GetItemRemovedCallbackResponse(eventContext, (short)cbInfo.Callback, (string)key, (UserBinaryObject)val, Flag, reason,cbInfo.DataFilter);

                            //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 ItemRemoveCallback((short)cbInfo.Callback, (string)key, val, reason, _client.ClientID, Flag, eventContext,cbInfo.DataFilter));
                                Monitor.Pulse(ConnectionManager.CallbackQueue);
                            }
                        }
                    }
                }
            }
        }