Ejemplo n.º 1
0
        //PROTOBUF

        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                }
                return;
            }

            NCache nCache = clientManager.CmdExecuter as NCache;

            try
            {
                object           lockId           = cmdInfo.LockId;
                DateTime         lockDate         = new DateTime();
                OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true);
                CacheEntry entry = (CacheEntry)nCache.Cache.GetCacheEntry(cmdInfo.Key, ref lockId, ref lockDate, cmdInfo.LockTimeout, cmdInfo.LockAccessType, operationContext);

                Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse getCacheItemResponse = new Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse();
                Alachisoft.NCache.Common.Protobuf.Response             response             = new Alachisoft.NCache.Common.Protobuf.Response();
                response.requestId    = Convert.ToInt64(cmdInfo.RequestId);
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_CACHE_ITEM;

                if (entry == null)
                {
                    getCacheItemResponse.lockId    = lockId == null ? string.Empty : lockId.ToString();
                    getCacheItemResponse.lockTicks = lockDate.Ticks;
                    response.getItem = getCacheItemResponse;
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                    return;
                }

                getCacheItemResponse = PopulateResponse(entry, getCacheItemResponse, clientManager);
                response.getItem     = getCacheItemResponse;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
Ejemplo n.º 2
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                return;
            }

            NCache nCache = clientManager.CmdExecuter as NCache;

            try
            {
                object lockId = cmdInfo.LockId;
                DateTime lockDate = new DateTime();
                OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true);
                CacheEntry entry = (CacheEntry)nCache.Cache.GetCacheEntry(cmdInfo.Key, ref lockId, ref lockDate, cmdInfo.LockTimeout, cmdInfo.LockAccessType, operationContext);

                Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse getCacheItemResponse = new Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse();
                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                response.requestId = Convert.ToInt64(cmdInfo.RequestId);
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_CACHE_ITEM;

                if (entry == null)
                {
                    getCacheItemResponse.lockId = lockId == null ? string.Empty : lockId.ToString();
                    getCacheItemResponse.lockTicks = lockDate.Ticks;
                    response.getItem = getCacheItemResponse;
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                    return;
                }

                getCacheItemResponse = PopulateResponse(entry, getCacheItemResponse, clientManager);
                response.getItem = getCacheItemResponse;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
Ejemplo n.º 3
0
        private Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse PopulateResponse(CacheEntry entry, Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse response, ClientManager clientManager)
        {
            if (entry.ExpirationHint is FixedExpiration)
            {
                response.absExp = ((FixedExpiration)entry.ExpirationHint).AbsoluteTime.Ticks;
            }
            else if (entry.ExpirationHint is IdleExpiration)
            {
                response.sldExp = ((IdleExpiration)entry.ExpirationHint).SlidingTime.Ticks;
            }

            response.priority = (int)entry.Priority;


            if (entry.ExpirationHint != null)
            {
                response.hasExpired  = entry.ExpirationHint.HasExpired;
                response.needsResync = entry.ExpirationHint.NeedsReSync;
            }
            response.flag             = entry.Flag.Data;
            response.creationTime     = entry.CreationTime.Ticks;
            response.lastModifiedTime = entry.LastModifiedTime.Ticks;
            response.lockId           = (entry.LockId != null ? entry.LockId.ToString() : null);
            response.lockTicks        = entry.LockDate.Ticks;

            object userValue = entry.Value;

            if (userValue is CallbackEntry)
            {
                userValue = ((CallbackEntry)userValue).Value;
            }
            response.value.AddRange(((UserBinaryObject)userValue).DataList);

            return(response);
        }
Ejemplo n.º 4
0
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            int       overload;
            string    exception = null;
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            try
            {
                overload = command.MethodOverload;
                cmdInfo  = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
                }
                return;
            }

            NCache     nCache = clientManager.CmdExecuter as NCache;
            CacheEntry entry  = null;

            try
            {
                object           lockId           = cmdInfo.LockId;
                DateTime         lockDate         = new DateTime();
                OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                operationContext.Add(OperationContextFieldName.ReadThru, cmdInfo.FlagMap.IsBitSet(BitSetConstants.ReadThru));
                operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true);
                if (cmdInfo.ProviderName != null)
                {
                    operationContext.Add(OperationContextFieldName.ReadThruProviderName, cmdInfo.ProviderName);
                }

                entry = (CacheEntry)nCache.Cache.GetCacheEntry(cmdInfo.Key, cmdInfo.Group, cmdInfo.SubGroup, ref lockId, ref lockDate, cmdInfo.LockTimeout, cmdInfo.LockAccessType, operationContext, ref cmdInfo.CacheItemVersion);
                stopWatch.Stop();
                Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse getCacheItemResponse = new Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse();
                Alachisoft.NCache.Common.Protobuf.Response             response             = new Alachisoft.NCache.Common.Protobuf.Response();
                response.requestId    = Convert.ToInt64(cmdInfo.RequestId);
                response.commandID    = command.commandID;
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_CACHE_ITEM;


                getCacheItemResponse.lockId    = lockId == null ? string.Empty : lockId.ToString();
                getCacheItemResponse.lockTicks = lockDate.Ticks;

                if (entry == null)
                {
                    response.getItem = getCacheItemResponse;
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                    return;
                }

                getCacheItemResponse = PopulateResponse(entry, getCacheItemResponse, clientManager, nCache.Cache);
                response.getItem     = getCacheItemResponse;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                exception = exc.ToString();
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
            }
            finally
            {
                TimeSpan executionTime = stopWatch.Elapsed;
                try
                {
                    if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                    {
                        int result = 0;
                        if (entry != null)
                        {
                            result = 1;
                        }
                        else
                        {
                            result = 0;
                        }

                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.GetCacheItem.ToLower());
                        log.GenerateGetCacheItemAPILogItem(cmdInfo.Key, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.FlagMap, (long)cmdInfo.CacheItemVersion, cmdInfo.LockAccessType, cmdInfo.LockTimeout, cmdInfo.LockId.ToString(), cmdInfo.ProviderName, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), result);
                    }
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 5
0
        private Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse PopulateResponse(CacheEntry entry, Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse response, ClientManager clientManager, Caching.Cache cache)
        {
            if (entry.ExpirationHint is AggregateExpirationHint)
            {
                IList <ExpirationHint> hints = ((AggregateExpirationHint)entry.ExpirationHint).Hints;
                // All hints are on same level now. There will be no AggregateExpirationHint within an AggregateExpirationHint
                for (int i = 0; i < hints.Count; i++)
                {
                    if (hints[i] is FixedExpiration)
                    {
                        response.absExp = ((FixedExpiration)hints[i]).AbsoluteTime.Ticks;
                    }
                    else if (hints[i] is IdleExpiration)
                    {
                        response.sldExp = ((IdleExpiration)hints[i]).SlidingTime.Ticks;
                    }
                }
            }
            else
            {
                if (entry.ExpirationHint is FixedExpiration)
                {
                    response.absExp = ((FixedExpiration)entry.ExpirationHint).AbsoluteTime.Ticks;
                }
                else if (entry.ExpirationHint is IdleExpiration)
                {
                    response.sldExp = ((IdleExpiration)entry.ExpirationHint).SlidingTime.Ticks;
                }
            }
            // Fixed and Idle expiration hints are not included in making of protobuf dependency object
            response.dependency = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetDependencyObj(entry.ExpirationHint);

            response.priority = (int)entry.Priority;

            if (entry.QueryInfo != null)
            {
                if (entry.QueryInfo["tag-info"] != null)
                {
                    response.tagInfo = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetTagInfoObj(entry.QueryInfo["tag-info"] as Hashtable);
                }
                if (entry.QueryInfo["named-tag-info"] != null)
                {
                    response.namedTagInfo = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetNamedTagInfoObj(entry.QueryInfo["named-tag-info"] as Hashtable, clientManager.IsDotNetClient);
                }
            }

            if (entry.ExpirationHint != null)
            {
                response.hasExpired  = entry.ExpirationHint.HasExpired;
                response.needsResync = entry.ExpirationHint.NeedsReSync;
            }

            response.version = entry.Version;

            response.creationTime     = entry.CreationTime.Ticks;
            response.lastModifiedTime = entry.LastModifiedTime.Ticks;

            if (entry.GroupInfo != null)
            {
                response.group    = entry.GroupInfo.Group;
                response.subGroup = entry.GroupInfo.SubGroup;
            }

            object userValue = entry.Value;

            if (userValue is CallbackEntry)
            {
                userValue = ((CallbackEntry)userValue).Value;
            }

            BitSet flag = entry.Flag;

            response.value.AddRange(((UserBinaryObject)cache.SocketServerDataService.GetClientData(userValue, ref flag, LanguageContext.DOTNET)).DataList);
            response.flag = flag.Data;
            return(response);
        }
Ejemplo n.º 6
0
        private Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse PopulateResponse(CacheEntry entry, ClientManager clientManager, Caching.Cache cache)
        {
            DateTime lockDate = new DateTime();

            Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse response = new Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse();
            response.lockId    = string.Empty;
            response.lockTicks = lockDate.Ticks;
            if (entry != null)
            {
                if (entry.ExpirationHint is AggregateExpirationHint)
                {
                    IList <ExpirationHint> hints = ((AggregateExpirationHint)entry.ExpirationHint).Hints;
                    ///All hints are on same level now. There will be no AggregateExpirationHint within an AggregateExpirationHint
                    for (int i = 0; i < hints.Count; i++)
                    {
                        if (hints[i] is FixedExpiration)
                        {
                            response.absExp = ((FixedExpiration)hints[i]).AbsoluteTime.Ticks;
                        }
                        else if (hints[i] is IdleExpiration)
                        {
                            response.sldExp = ((IdleExpiration)hints[i]).SlidingTime.Ticks;
                        }
                    }
                }
                else
                {
                    if (entry.ExpirationHint is FixedExpiration)
                    {
                        response.absExp = ((FixedExpiration)entry.ExpirationHint).AbsoluteTime.Ticks;
                    }
                    else if (entry.ExpirationHint is IdleExpiration)
                    {
                        response.sldExp = ((IdleExpiration)entry.ExpirationHint).SlidingTime.Ticks;
                    }
                }
                response.itemType = MiscUtil.EntryTypeToProtoItemType(entry.Type);// (Alachisoft.NCache.Common.Protobuf.CacheItemType.ItemType)entry.Type;


                response.priority = (int)entry.Priority;


                if (entry.QueryInfo != null)
                {
                }

                if (entry.ExpirationHint != null)
                {
                    response.hasExpired  = entry.ExpirationHint.HasExpired;
                    response.needsResync = entry.ExpirationHint.NeedsReSync;
                }

                response.version = entry.Version;

                response.creationTime     = entry.CreationTime.Ticks;
                response.lastModifiedTime = entry.LastModifiedTime.Ticks;
                //response.lockId = (entry.LockId != null ? entry.LockId.ToString() : null);
                //response.lockTicks = entry.LockDate.Ticks;

                object userValue = entry.Value;

                BitSet flag = entry.Flag;
                response.value.AddRange(((UserBinaryObject)cache.SocketServerDataService.GetClientData(userValue, ref flag, LanguageContext.DOTNET)).DataList);
                response.flag = flag.Data;
            }
            return(response);
        }