Ejemplo n.º 1
0
        internal static AsyncOperationCompletedCallbackResponse GetAsyncOpCompletedResponse(ClientManager clientManager, AsyncCallbackInfo cbInfo, object opResult, object opCode, string key)
        {
            Alachisoft.NCache.Common.Protobuf.AsyncOperationCompletedCallbackResponse asyncOperationCompleted = new Alachisoft.NCache.Common.Protobuf.AsyncOperationCompletedCallbackResponse();

            switch ((AsyncOpCode)opCode)
            {
            case AsyncOpCode.Add:
            case AsyncOpCode.Remove:
            case AsyncOpCode.Update:
                asyncOperationCompleted.key = key;
                break;
            }

            asyncOperationCompleted.requestId = cbInfo.RequestID;

            if (opResult is System.Exception)
            {
                Alachisoft.NCache.Common.Protobuf.Exception exc = new Alachisoft.NCache.Common.Protobuf.Exception();
                exc.message   = ((System.Exception)opResult).Message;
                exc.exception = ((System.Exception)opResult).ToString();
                exc.type      = Alachisoft.NCache.Common.Protobuf.Exception.Type.GENERALFAILURE;

                asyncOperationCompleted.exc     = exc;
                asyncOperationCompleted.success = false;
            }
            else
            {
                asyncOperationCompleted.success = true;
            }

            return(asyncOperationCompleted);
        }
Ejemplo n.º 2
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);
                        }
                    }
                }
            }
        }