Esempio n. 1
0
        public static void Main(string[] args)
        {
            try
            {
                //Initialize cache via 'initializeCache' using 'Cache Name'
                //to be initialized.
                Cache cache = NCache.InitializeCache("mypartitionedcache");

                //Another method to add item(s) to cache is via CacheItem  object
                Customer customer = new Customer();
                customer.Name      = "David Johnes";
                customer.Age       = 23;
                customer.Gender    = "Male";
                customer.ContactNo = "12345-6789";
                customer.Address   = "Silicon Valley, Santa Clara, California";

                DateTime calendar = new DateTime();
                calendar.AddMinutes(1);

                //Adding item with an absolute expiration of 1 minute
                cache.Add("Customer:DavidJohnes", customer, calendar, Cache.NoSlidingExpiration, CacheItemPriority.Normal);
                Customer cachedCustomer = (Customer)cache.Get("Customer:DavidJohnes");

                printCustomerDetails(cachedCustomer);

                //updating item with a sliding expiration of 30 seconds
                customer.Age = 50;
                cache.Insert("Customer:DavidJohnes", customer, Cache.NoAbsoluteExpiration, new TimeSpan(0, 0, 30), CacheItemPriority.Normal);

                //get customer from the cache
                cachedCustomer = (Customer)cache.Get("Customer:DavidJohnes");
                printCustomerDetails(cachedCustomer);


                //Total item count in the cache
                long count = cache.Count;
                Console.WriteLine("Cache Count: " + count);

                //remove the existing customer
                cache.Remove("Customer:DavidJohnes");

                //try to get the customer again, getting non-existing items returns null
                cachedCustomer = (Customer)cache.Get("Customer:DavidJohnes");
                printCustomerDetails(cachedCustomer);

                //get count again, item count should be 0
                count = cache.Count;
                Console.WriteLine("Cache Count: " + count);

                //Dispose the cache once done
                cache.Dispose();

                Environment.Exit(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }
        }
Esempio n. 2
0
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            ClientId = clientManager.ClientID;

            NCache nCache = clientManager.CmdExecuter as NCache;

            try
            {
                serailizationContext = nCache.CacheId;
                cmdInfo = base.ParseCommand(command, clientManager, serailizationContext);
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("BulkInsCmd.Exec", "cmd parsed");
                }
            }
            catch (Exception exc)
            {
                _insertBulkResult = OperationResult.Failure;
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                return;
            }

            byte[] dataPackage = null;

            try
            {
                OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId);
                if (!string.IsNullOrEmpty(cmdInfo.IntendedRecipient))
                {
                    operationContext.Add(OperationContextFieldName.IntendedRecipient, cmdInfo.IntendedRecipient);
                }

                Hashtable insertResult = (Hashtable)nCache.Cache.Insert(cmdInfo.Keys, cmdInfo.Entries, operationContext);
                Alachisoft.NCache.Common.Protobuf.Response           response           = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.BulkInsertResponse bulkInsertResponse = new Alachisoft.NCache.Common.Protobuf.BulkInsertResponse();
                response.requestId                     = Convert.ToInt64(cmdInfo.RequestId);
                response.intendedRecipient             = cmdInfo.IntendedRecipient;
                bulkInsertResponse.keyExceptionPackage = new Alachisoft.NCache.Common.Protobuf.KeyExceptionPackageResponse();

                //TODO : Package Key Value
                Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysExceptions(insertResult, bulkInsertResponse.keyExceptionPackage);

                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.INSERT_BULK;
                response.bulkInsert   = bulkInsertResponse;
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _insertBulkResult = OperationResult.Failure;
                //PROTOBUF:RESPONSE
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("BulkInsCmd.Exec", "cmd executed on cache");
            }
        }
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;
            int         overload;
            string      exception = null;

            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();
            try
            {
                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;
            }

            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;
                EnumerationDataChunk nextChunk = nCache.Cache.GetNextChunk(cmdInfo.Pointer, cmdInfo.OperationContext);

                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.GetGroupNextChunkResponse getNextChunkResponse = new Alachisoft.NCache.Common.Protobuf.GetGroupNextChunkResponse();
                response.requestId    = Convert.ToInt64(cmdInfo.RequestId);
                response.commandID    = command.commandID;
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_GROUP_NEXT_CHUNK;
                response.getGroupNextChunkResponse = getNextChunkResponse;

                getNextChunkResponse.keys.AddRange(nextChunk.Data);
                getNextChunkResponse.groupEnumerationPointer = EnumerationPointerConversionUtil.ConvertToProtobufGroupEnumerationPointer(nextChunk.Pointer as GroupEnumerationPointer);

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                exception = exception.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)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.GetGroupNextChunk.ToLower());
                        log.GenerateGetEnumeratorAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 4
0
        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;
            }

            try
            {
                NCache          nCache = clientManager.CmdExecuter as NCache;
                ReaderResultSet reader = nCache.Cache.GetReaderChunk(cmdInfo.ReaderId, cmdInfo.nextIndex, false, cmdInfo.OperationContext);

                ReaderResponseBuilder.BuildReaderChunkResponse(reader, cmdInfo.RequestId, _serializedResponsePackets);
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
Esempio n. 5
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                return;
            }

            //TODO
            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;
                ClusteredList <ReaderResultSet>            resultSetList    = null;
                Alachisoft.NCache.Caching.OperationContext operationContext = new Alachisoft.NCache.Caching.OperationContext(Alachisoft.NCache.Caching.OperationContextFieldName.OperationType, Alachisoft.NCache.Caching.OperationContextOperationType.CacheOperation);
                operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId);
                //client id
                operationContext.Add(OperationContextFieldName.ClientId, clientManager.ClientID);
                resultSetList = nCache.Cache.ExecuteReader(cmdInfo.Query, cmdInfo.Values, cmdInfo.GetData, cmdInfo.ChunkSize, false, operationContext);
                ReaderResponseBuilder.Cache = nCache.Cache;
                ReaderResponseBuilder.BuildExecuteReaderResponse(resultSetList, cmdInfo.RequestId, _serializedResponsePackets);
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
        //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(clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)));
                }
                return;
            }

            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;
                nCache.Cache.UnregisterKeyNotificationCallback(cmdInfo.Keys
                                                               , new CallbackInfo(clientManager.ClientID, cmdInfo.UpdateCallbackId, EventDataFilter.None) //DataFilter not required while unregistration
                                                               , new CallbackInfo(clientManager.ClientID, cmdInfo.RemoveCallbackId, EventDataFilter.None) //DataFilter not required while unregistration
                                                               , new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.UnregisterBulkKeyNotifResponse unregResponse = new Common.Protobuf.UnregisterBulkKeyNotifResponse();
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.UNREGISTER_BULK_KEY_NOTIF;
                response.requestId    = command.requestID;
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc)));
            }
        }
Esempio n. 7
0
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
            long   requestId;
            string taskId;

            Common.Protobuf.TaskProgressCommand taskProgressCommand = command.TaskProgressCommand;
            taskId    = taskProgressCommand.taskId;
            requestId = command.requestID;

            try
            {
                ICommandExecuter tmpVar = clientManager.CmdExecuter;
                NCache           nCache = (NCache)((tmpVar is NCache) ? tmpVar : null);

                Runtime.MapReduce.TaskStatus taskStatus = nCache.Cache.TaskStatus(taskId);

                Common.Protobuf.Response reponse = new Common.Protobuf.Response();
                reponse.requestId                       = requestId;
                reponse.TaskProgressResponse            = new Common.Protobuf.TaskProgressResponse();
                reponse.TaskProgressResponse.progresses = Serialization.Formatters.CompactBinaryFormatter.ToByteBuffer(taskStatus, nCache.Cache.Name);
                reponse.responseType                    = Common.Protobuf.Response.Type.TASK_PROGRESS;
                reponse.commandID                       = command.commandID;
                _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(reponse));
            }
            catch (Exception ex)
            {
                _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, command.requestID, command.commandID));
            }
        }
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
            try
            {
                NCache cache = clientManager.CmdExecuter as NCache;
                SerializationFormat serializationFormat = cache.Cache.SerializationFormat;

                GetSerializationFormatResponse serializationFormatResponse = new GetSerializationFormatResponse()
                {
                    serializationFormat = (int)serializationFormat
                };

                if (clientManager.ClientVersion >= 5000)
                {
                    Common.Util.ResponseHelper.SetResponse(serializationFormatResponse, command.requestID, command.commandID);
                    _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(serializationFormatResponse, Response.Type.GET_SERIALIZATION_FORMAT));
                }
                else
                {
                    //PROTOBUF:RESPONSE
                    Response response = new Response();
                    response.getSerializationFormatResponse = serializationFormatResponse;
                    Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Response.Type.GET_SERIALIZATION_FORMAT);
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                }
            }
            catch (System.Exception ex)
            {
                _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeExceptionResponseWithType(ex, command.requestID, command.commandID, clientManager.ClientVersion));
            }
        }
Esempio n. 9
0
        public async Task <Author> GetAuthor(int id)
        {
            _cache = NCache.InitializeCache("CacheName");
            var    cacheKey = "Key";
            Author author   = null;

            if (_cache != null)
            {
                author = _cache.Get(cacheKey) as Author;
            }
            if (author == null) //Data not available in the cache
            {
                //Write code here to fetch the author
                // object from the database
                if (author != null)
                {
                    if (_cache != null)
                    {
                        _cache.Insert(cacheKey, author, null,
                                      Alachisoft.NCache.Web.Caching.Cache.NoAbsoluteExpiration,
                                      TimeSpan.FromMinutes(10),
                                      Alachisoft.NCache.Runtime.
                                      CacheItemPriority.Default);
                    }
                }
            }
            return(author);
        }
Esempio n. 10
0
        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;
            }

            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;
                nCache.Cache.DisposeReader(cmdInfo.ReaderId, cmdInfo.OperationContext);
                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.DisposeReaderResponse disposeReaderResponse = new Alachisoft.NCache.Common.Protobuf.DisposeReaderResponse();
                response.requestId             = Convert.ToInt64(cmdInfo.RequestId);
                response.responseType          = Alachisoft.NCache.Common.Protobuf.Response.Type.DISPOSE_READER;
                response.disposeReaderResponse = disposeReaderResponse;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
Esempio n. 11
0
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
            // int overload;
            string exception = null;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            long messageCount = 0;


            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;

                if (nCache != null)
                {
                    messageCount            = nCache.Cache.GetMessageCount(command.messageCountCommand.topicName);
                    _operationSuccessStatus = true;
                }
                stopwatch.Stop();

                Common.Protobuf.MessageCountResponse messageCountResponse = new Common.Protobuf.MessageCountResponse();
                messageCountResponse.messageCount = messageCount;


                if (clientManager.ClientVersion >= 5000)
                {
                    Common.Util.ResponseHelper.SetResponse(messageCountResponse, command.requestID, command.commandID);
                    _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(messageCountResponse, Common.Protobuf.Response.Type.MESSAGE_COUNT));
                }
                else
                {
                    //PROTOBUF:RESPONSE
                    Common.Protobuf.Response response = new Common.Protobuf.Response();
                    response.messageCountResponse = messageCountResponse;
                    Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.MESSAGE_COUNT);
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                }
            }
            catch (Exception e)
            {
                exception = e.ToString();
                _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeExceptionResponseWithType(e, command.requestID, command.commandID, clientManager.ClientVersion));
            }
            finally
            {
                TimeSpan executionTime = stopwatch.Elapsed;
                try
                {
                    if (Management.APILogging.APILogManager.APILogManger != null && Management.APILogging.APILogManager.EnableLogging)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.MessageCount.ToLower());
                        log.GenerateCacheCountAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), messageCount);
                    }
                }
                catch { }
            }
        }
Esempio n. 12
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            //TODO
            byte[] data = null;

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

            data = null;
            NCache nCache = clientManager.CmdExecuter as NCache;

            try
            {
                string compactTypesString = "";

                if (nCache.Cache.CompactRegisteredTypesForDotNet != null && cmdInfo.isDotNetClient)
                {
                    compactTypesString = SerializationUtil.GetProtocolStringFromTypeMap(nCache.Cache.CompactRegisteredTypesForDotNet);
                }
                else if (nCache.Cache.CompactRegisteredTypesForJava != null && !cmdInfo.isDotNetClient)
                {
                    compactTypesString = SerializationUtil.GetProtocolStringFromTypeMap(nCache.Cache.CompactRegisteredTypesForJava);
                }


                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.GetCompactTypeResponse getCompactTypesResponse = new Alachisoft.NCache.Common.Protobuf.GetCompactTypeResponse();
                getCompactTypesResponse.compactTypeString = compactTypesString;
                response.getCompactTypes = getCompactTypesResponse;
                response.requestId       = Convert.ToInt64(cmdInfo.RequestId);
                response.commandID       = command.commandID;
                response.responseType    = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_COMPACT_TYPES;

                //PROTOBUF:RESPONSE
                if (clientManager.ClientVersion >= 5000)
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.GET_COMPACT_TYPES));
                }
                else
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                }
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
            }
        }
Esempio n. 13
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)
            {
                _removeQueryResult = OperationResult.Failure;
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
                }
                return;
            }

            byte[] data = null;

            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;

                OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                operationContext.Add(OperationContextFieldName.RaiseCQNotification, true);
                operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId);
                operationContext.Add(OperationContextFieldName.RemoveQueryOperation, true);

                removeRes = nCache.Cache.RemoveQuery(cmdInfo.Query, cmdInfo.Values, operationContext);
                stopWatch.Stop();
                RemoveQueryResponseBuilder.BuildResponse(removeRes, cmdInfo.CommandVersion, cmdInfo.RequestId, _serializedResponsePackets, command.commandID, nCache.Cache);
            }
            catch (Exception exc)
            {
                _removeQueryResult = OperationResult.Failure;
                exception          = exc.ToString();
                //PROTOBUF:RESPONSE
                _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)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.ExecuteNonQuery.ToLower());
                        log.GenerateDeleteQueryAPILogItem(cmdInfo.Query, cmdInfo.Values, 1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 14
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            int    overload;
            string exception = null;

            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();
            try
            {
                if (clientManager != null)
                {
                    clientManager._leftGracefully = true;
                    NCache nCache = clientManager.CmdExecuter as NCache;
                    if (nCache != null)
                    {
                        nCache.Dispose();
                    }
                    stopWatch.Stop();



                    Alachisoft.NCache.Common.Protobuf.DisposeResponse disposeResponse = new Alachisoft.NCache.Common.Protobuf.DisposeResponse();
                    if (clientManager.ClientVersion >= 5000)
                    {
                        Common.Util.ResponseHelper.SetResponse(disposeResponse, command.requestID, command.commandID);
                        _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(disposeResponse, Common.Protobuf.Response.Type.DISPOSE));
                    }
                    else
                    {
                        //PROTOBUF:RESPONSE
                        Common.Protobuf.Response response = new Common.Protobuf.Response();
                        response.disposeResponse = disposeResponse;
                        Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.DISPOSE);
                        _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                    }
                }
            }
            catch (Exception ex)
            {
                exception = ex.ToString();
            }
            finally
            {
                TimeSpan executionTime = stopWatch.Elapsed;
                try
                {
                    if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.Dispose.ToLower());
                        log.GenerateDisposeAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());

                        // Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo);
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 15
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
            }
            catch (ArgumentOutOfRangeException arEx)
            {
                if (SocketServer.Logger.IsErrorLogsEnabled)
                {
                    SocketServer.Logger.NCacheLog.Error("IsLockedCommand", "command: " + command + " Error" + arEx);
                }
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(arEx, command.requestID, command.commandID));
                }
                return;
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    //PROTOBUF:RESPONSE
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
                }
                return;
            }

            try
            {
                NCache   nCache   = clientManager.CmdExecuter as NCache;
                object   lockId   = cmdInfo.LockId;
                DateTime lockDate = new DateTime();

                bool res = nCache.Cache.IsLocked(cmdInfo.Key, ref lockId, ref lockDate, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));

                //PROTOBUF:RESPONSE
                Alachisoft.NCache.Common.Protobuf.Response         response         = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.IsLockedResponse isLockedResponse = new Alachisoft.NCache.Common.Protobuf.IsLockedResponse();
                response.requestId        = Convert.ToInt64(cmdInfo.RequestId);
                response.commandID        = command.commandID;
                response.responseType     = Alachisoft.NCache.Common.Protobuf.Response.Type.ISLOCKED;
                response.isLockedResponse = isLockedResponse;

                isLockedResponse.isLocked = res;
                isLockedResponse.lockId   = lockId != null?lockId.ToString() : cmdInfo.LockId.ToString();

                isLockedResponse.lockTime = lockDate != null ? lockDate.Ticks : new DateTime().Ticks;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                //PROTOBUF:RESPONSE
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
            }
        }
Esempio n. 16
0
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;
            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;
            }

            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;
                nCache.Cache.DisposeReader(cmdInfo.ReaderId, cmdInfo.OperationContext);
                stopWatch.Stop();
                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.DisposeReaderResponse disposeReaderResponse = new Alachisoft.NCache.Common.Protobuf.DisposeReaderResponse();
                response.requestId             = Convert.ToInt64(cmdInfo.RequestId);
                response.commandID             = command.commandID;
                response.responseType          = Alachisoft.NCache.Common.Protobuf.Response.Type.DISPOSE_READER;
                response.disposeReaderResponse = disposeReaderResponse;

                _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)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.DisposeReader.ToLower());
                        log.GenerateDisposeReaderAPILogItem(overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 17
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;
            }

            try
            {
                NCache     nCache     = clientManager.CmdExecuter as NCache;
                int        bucketSize = 0;
                NewHashmap hashmap    = nCache.Cache.GetOwnerHashMap(out bucketSize);
                byte[]     buffer     = new byte[0];

                //TODO:Incomplete conversion
                Alachisoft.NCache.Common.Protobuf.Response           response           = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.GetHashmapResponse getHashmapResponse = new Alachisoft.NCache.Common.Protobuf.GetHashmapResponse();

                response.getHashmap   = getHashmapResponse;
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_HASHMAP;
                response.requestId    = command.requestID;

                if (hashmap != null)
                {
                    getHashmapResponse.viewId     = hashmap.LastViewId;
                    getHashmapResponse.bucketSize = bucketSize;

                    foreach (string member in hashmap.Members)
                    {
                        getHashmapResponse.members.Add(member);
                    }
                    foreach (DictionaryEntry entry in hashmap.Map)
                    {
                        Alachisoft.NCache.Common.Protobuf.KeyValuePair keyValue =
                            new Alachisoft.NCache.Common.Protobuf.KeyValuePair();
                        keyValue.key   = entry.Key.ToString();
                        keyValue.value = entry.Value.ToString();

                        getHashmapResponse.keyValuePair.Add(keyValue);
                    }
                }
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
Esempio n. 18
0
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();
            int    overload         = 1;
            string exceptionMessage = null;
            bool   result           = false;

            try
            {
                NCache nCache           = clientManager.CmdExecuter as NCache;
                var    operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                if (command.commandVersion < 1)
                {
                    operationContext.Add(OperationContextFieldName.ClientLastViewId, forcedViewId);
                }
                else
                {
                    operationContext.Add(OperationContextFieldName.ClientLastViewId, command.clientLastViewId.ToString(CultureInfo.InvariantCulture));
                }
                if (nCache != null)
                {
                    _command = command.removeTopicCommand;
                    TopicOperation topicOperation = new TopicOperation(_command.topicName, TopicOperationType.Remove);

                    result = nCache.Cache.TopicOpertion(topicOperation, operationContext);

                    Common.Protobuf.Response            response            = new Common.Protobuf.Response();
                    Common.Protobuf.RemoveTopicResponse removeTopicResponse = new Common.Protobuf.RemoveTopicResponse();
                    response.requestId           = _command.requestId;
                    response.commandID           = command.commandID;
                    removeTopicResponse.success  = result;
                    response.responseType        = Common.Protobuf.Response.Type.REMOVE_TOPIC;
                    response.removeTopicResponse = removeTopicResponse;
                    _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(response));
                }
            }
            catch (Exception exc)
            {
                exceptionMessage = exc.ToString();
                _serializedResponsePackets.Add(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)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.DeleteTopic);
                        log.GenerateGetCreateOrDeleteTopicAPILogItem(_command.topicName, executionTime, clientManager.ClientID, clientManager.ClientIP, overload, result, exceptionMessage);
                    }
                }
                catch
                {
                }
            }
        }
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;
            int         overload;
            string      exception = null;

            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();

            try
            {
                overload = command.MethodOverload;
                stopWatch.Start();
                cmdInfo = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)));
                }
                return;
            }

            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;
                nCache.Cache.UnregisterKeyNotificationCallback(cmdInfo.Keys
                                                               , new CallbackInfo(clientManager.ClientID, cmdInfo.UpdateCallbackId, EventDataFilter.None) // DataFilter not required while unregistration
                                                               , new CallbackInfo(clientManager.ClientID, cmdInfo.RemoveCallbackId, EventDataFilter.None) // DataFilter not required while unregistration
                                                               , new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
                stopWatch.Stop();
                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.UnregisterBulkKeyNotifResponse unregResponse = new Common.Protobuf.UnregisterBulkKeyNotifResponse();
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.UNREGISTER_BULK_KEY_NOTIF;
                response.requestId    = command.requestID;
                response.commandID    = command.commandID;
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc)));
            }
            finally
            {
                TimeSpan executionTime = stopWatch.Elapsed;
                try
                {
                    if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.UnRegisterKeyNotificationCallback.ToLower());
                        log.GenerateKeyNotificationCallback(cmdInfo.Keys.Length, cmdInfo.UpdateCallbackId, cmdInfo.RemoveCallbackId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 20
0
 internal static void SubscribeEvents(string clientId, string topicName, NCache nCache, OperationContext operationContext)
 {
     SubscriptionInfo subInfo = new SubscriptionInfo()
     {
         SubscriptionId = SubscriptionInfo.EventsSubscriptionName, ClientId = clientId, Type = SubscriptionType.Subscriber, SubPolicyType = SubscriptionPolicyType.EventSubscription, Expiration = TimeSpan.MaxValue.Ticks
     };
     var  topicOperation = new SubscriptionOperation(topicName, TopicOperationType.Subscribe, subInfo);
     bool subscribed     = nCache.Cache.TopicOpertion(topicOperation, operationContext);
 }
Esempio n. 21
0
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;
            int         overload;
            string      exception = null;
            Stopwatch   stopWatch = new Stopwatch();

            stopWatch.Start();
            try
            {
                overload = command.MethodOverload;
                cmdInfo  = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
                return;
            }
            int resultCount = 0;

            try
            {
                NCache cache = clientManager.CmdExecuter as NCache;
                List <ReaderResultSet> resultSetList = null;
                QueryDataFilters       datafilters   = new QueryDataFilters(cmdInfo.addDF, cmdInfo.updateDF, cmdInfo.removeDF);

                Alachisoft.NCache.Caching.OperationContext operationContext = new Caching.OperationContext(Alachisoft.NCache.Caching.OperationContextFieldName.OperationType, Alachisoft.NCache.Caching.OperationContextOperationType.CacheOperation);
                operationContext.Add(Caching.OperationContextFieldName.ClientId, clientManager.ClientID);
                operationContext.Add(Caching.OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId);

                resultSetList = cache.Cache.ExecuteReaderCQ(cmdInfo.Query, cmdInfo.Values, cmdInfo.getData, cmdInfo.chunkSize, cmdInfo.clientUniqueId, clientManager.ClientID, cmdInfo.notifyAdd, cmdInfo.notifyUpdate, cmdInfo.notifyRemove, operationContext, datafilters);
                stopWatch.Stop();
                ReaderResponseBuilder.Cache = cache.Cache;
                ReaderResponseBuilder.BuildExecuteReaderCQResponse(resultSetList, cmdInfo.CommandVersion, cmdInfo.RequestId, _serializedResponsePackets, command.commandID, clientManager.ClientVersion < 4620, out resultCount);
            }
            catch (Exception exc)
            {
                //PROTOBUF:RESPONSE
                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)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.ExecuteReaderCQ.ToLower());
                        log.GenerateExecuteReaderCQAPILogItem(cmdInfo.Query, cmdInfo.Values, cmdInfo.getData, cmdInfo.chunkSize, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), resultCount);
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 22
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)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
                return;
            }
            int resultCount = 0;

            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;
                Alachisoft.NCache.Caching.OperationContext operationContext = new Alachisoft.NCache.Caching.OperationContext(Alachisoft.NCache.Caching.OperationContextFieldName.OperationType, Alachisoft.NCache.Caching.OperationContextOperationType.CacheOperation);
                if (cmdInfo.CommandVersion <= 1) //NCache 3.8 SP4 and previous
                {
                    operationContext.Add(OperationContextFieldName.ClientLastViewId, forcedViewId);
                }
                else
                {
                    operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId);
                }

                resultSet = nCache.Cache.Search(cmdInfo.Query, cmdInfo.Values, operationContext);
                stopWatch.Stop();
                SearchResponseBuilder.BuildResponse(resultSet, cmdInfo.RequestId, command.commandID, _serializedResponsePackets, cmdInfo.CommandVersion, out resultCount);
            }
            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)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.Search.ToLower());
                        log.GenerateSearchAPILogItem(cmdInfo.Query, cmdInfo.Values, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), resultCount);
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 23
0
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
            short  callbackId;
            string taskId;
            int    overload;
            string exception = null;

            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();

            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;
                stopWatch.Start();
                IEnumerable <ClientInfo> connectedClients = nCache.Cache.GetConnectedClientInfos();
                Common.Protobuf.GetConnectedClientsResponse clientsResponse = new Common.Protobuf.GetConnectedClientsResponse();
                Common.Protobuf.Response response = new Common.Protobuf.Response();
                response.getConnectedClientsResponse = clientsResponse;
                response.requestId    = command.getConnectedClientsCommand.requestId;
                response.commandID    = command.commandID;
                response.responseType = Response.Type.GET_CONNECTED_CLIENTS;
                if (connectedClients != null)
                {
                    foreach (var connectedClient in connectedClients)
                    {
                        clientsResponse.connectedClients.Add(new Common.Protobuf.ClientInfo
                        {
                            clientId    = connectedClient.ClientID,
                            processId   = connectedClient.ProcessID,
                            appName     = connectedClient.AppName,
                            ipAddress   = connectedClient.IPAddress.ToString(),
                            machineName = connectedClient.MachineName
                        });
                    }
                }
                stopWatch.Stop();
                _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _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)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.GetConnectedClientList.ToLower());
                        log.GenerateGetConnectedClientsAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());
                    }
                }
                catch
                {
                }
            }
        }
        //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"))
                {
                    //PROTOBUF:RESPONSE
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                }
                return;
            }

            try
            {
                CallbackInfo cbUpdate = null;
                CallbackInfo cbRemove = null;


                if (cmdInfo.dataFilter != -1) //Default value in protbuf set to -1
                {
                    EventDataFilter datafilter = (EventDataFilter)cmdInfo.dataFilter;

                    cbUpdate = new CallbackInfo(clientManager.ClientID, cmdInfo.UpdateCallbackId, datafilter);
                    cbRemove = new CallbackInfo(clientManager.ClientID, cmdInfo.RemoveCallbackId, datafilter, cmdInfo.NotifyOnExpiration);
                }
                else
                {
                    cbUpdate = new CallbackInfo(clientManager.ClientID, cmdInfo.UpdateCallbackId, EventDataFilter.None);
                    cbRemove = new CallbackInfo(clientManager.ClientID, cmdInfo.RemoveCallbackId, EventDataFilter.DataWithMetadata, cmdInfo.NotifyOnExpiration);
                }


                NCache nCache = clientManager.CmdExecuter as NCache;

                nCache.Cache.RegisterKeyNotificationCallback(cmdInfo.Key, cbUpdate, cbRemove
                                                             , new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));

                //PROTOBUF:RESPONSE
                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.RegisterKeyNotifResponse registerKeyNotifResponse = new Alachisoft.NCache.Common.Protobuf.RegisterKeyNotifResponse();
                response.responseType             = Alachisoft.NCache.Common.Protobuf.Response.Type.REGISTER_KEY_NOTIF;
                response.registerKeyNotifResponse = registerKeyNotifResponse;
                response.requestId = command.registerKeyNotifCommand.requestId;
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                //PROTOBUF:RESPONSE
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
Esempio n. 25
0
        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;
            }

            int    count      = 0;
            string keyPackage = null;

            try
            {
                NCache nCache = clientManager.CmdExecuter as NCache;
                EnumerationDataChunk nextChunk = nCache.Cache.GetNextChunk(cmdInfo.Pointer, cmdInfo.OperationContext);

                if (!clientManager.EnumerationPointers.ContainsKey(cmdInfo.Pointer.Id))
                {
                    clientManager.EnumerationPointers.Add(cmdInfo.Pointer.Id, cmdInfo.Pointer);
                }
                else
                {
                    clientManager.EnumerationPointers[cmdInfo.Pointer.Id] = cmdInfo.Pointer;
                }

                Alachisoft.NCache.Common.Protobuf.Response             response             = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.GetNextChunkResponse getNextChunkResponse = new Alachisoft.NCache.Common.Protobuf.GetNextChunkResponse();
                response.requestId            = Convert.ToInt64(cmdInfo.RequestId);
                response.intendedRecipient    = cmdInfo.OperationContext.GetValueByField(OperationContextFieldName.IntendedRecipient).ToString();
                response.responseType         = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK;
                response.getNextChunkResponse = getNextChunkResponse;

                if (nextChunk.Data != null)
                {
                    getNextChunkResponse.keys.AddRange(nextChunk.Data);
                }

                getNextChunkResponse.enumerationPointer = EnumerationPointerConversionUtil.ConvertToProtobufEnumerationPointer(nextChunk.Pointer);

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
Esempio n. 26
0
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
            string    exception = null;
            int       overload;
            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;
            }
            try
            {
                NCache           nCache           = clientManager.CmdExecuter as NCache;
                OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);

                nCache.Cache.Touch(cmdInfo.Keys, operationContext);
                stopWatch.Stop();
                Common.Protobuf.Response      response      = new Common.Protobuf.Response();
                Common.Protobuf.TouchResponse touchResponse = new Common.Protobuf.TouchResponse();
                response.requestId     = Convert.ToInt64(cmdInfo.RequestId);
                response.commandID     = command.commandID;
                response.responseType  = Common.Protobuf.Response.Type.TOUCH;
                response.touchResponse = touchResponse;
                _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                exception = exc.ToString();
                _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
            }
            finally
            {
                TimeSpan executionTime = stopWatch.Elapsed;
                try
                {
                    if (Management.APILogging.APILogManager.APILogManger != null && Management.APILogging.APILogManager.EnableLogging)
                    {
                        APILogItemBuilder log = new APILogItemBuilder(MethodsName.Touch.ToLower());
                        log.GenerateTouchCommandAPILogItem(cmdInfo.Keys.Count, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 27
0
        public static void Main(string[] args)
        {
            try
            {
                //Initialize cache
                Cache cache;
                cache = NCache.InitializeCache("mypartitionedcache");
                cache.Clear();

                //Locking prevents multiple clients from updating the same data simultaneously
                //and also provides the data consistency.

                //Adding an item the cache
                Customer customer = new Customer();
                customer.Name      = "Kirsten Goli";
                customer.Age       = 40;
                customer.Address   = "45-A West Boulevard, Cartago, Costa Rica";
                customer.Gender    = "Female";
                customer.ContactNo = "52566-1779";

                cache.Add("Customer:KirstenGoli", customer);

                //Get
                TimeSpan   timeSpan    = new TimeSpan(0, 0, 0, 20);
                LockHandle lockHandle  = new LockHandle();
                Customer   getCustomer = (Customer)cache.Get("Customer:KirstenGoli", timeSpan, ref lockHandle, true);

                PrintCustomerDetails(getCustomer);

                Console.WriteLine("Lock acquired on " + lockHandle.LockId);

                //Lock item in cache
                bool isLocked = cache.Lock("Customer:KirstenGoli", timeSpan, out lockHandle);

                if (!isLocked)
                {
                    Console.WriteLine("Lock acquired on " + lockHandle.LockId);
                }

                //Unlock item in cache
                cache.Unlock("Customer:KirstenGoli");

                //Unlock via lockhandle
                cache.Unlock("Customer:KirstenGoli", lockHandle);

                //Must dispose cache
                cache.Dispose();

                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Environment.Exit(0);
            }
        }
Esempio n. 28
0
 public void Add(string key, object value, TimeSpan slidingExpiration, CacheItemRemovedCallback cacheRemove)
 {
     string cacheKey = CacheKey(key, _hashkey);
     lock (GetLock(cacheKey, TimeSpan.Zero, slidingExpiration, null, this))
     {
         object local = NCache.Get(cacheKey);
         if (local == null)
             local = NHashtable.InternalCallback(cacheKey);
     }
 }
Esempio n. 29
0
 protected override void InitialiseInternal()
 {
     if (_cacheName == null)
     {
         _cacheName = CacheConfiguration.Current.DefaultCacheName;
         Log.Debug("NCacheExpress.Initialise - initialising with cacheName: {0}", _cacheName);
         NoAbsoluteExpiry = DateTime.MaxValue;
         NoSlidingExpiry  = new TimeSpan(0);
         NCache.InitializeCache(_cacheName);
     }
 }
Esempio n. 30
0
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd parsed");
                }
            }
            catch (Exception exc)
            {
                _removeResult = OperationResult.Failure;
                if (!base.immatureId.Equals("-2"))
                {
                    //PROTOBUF:RESPONSE
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                }
                return;
            }
            NCache nCache = clientManager.CmdExecuter as NCache;

            try
            {
                CallbackEntry    cbEntry          = null;
                OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                nCache.Cache.Delete(cmdInfo.Key, cmdInfo.FlagMap, cbEntry, cmdInfo.LockId, cmdInfo.LockAccessType, operationContext);
                //PROTOBUF:RESPONSE
                Alachisoft.NCache.Common.Protobuf.Response       response       = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.DeleteResponse removeResponse = new Alachisoft.NCache.Common.Protobuf.DeleteResponse();
                response.responseType   = Alachisoft.NCache.Common.Protobuf.Response.Type.DELETE;
                response.deleteResponse = removeResponse;
                response.requestId      = Convert.ToInt64(cmdInfo.RequestId);
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _removeResult = OperationResult.Failure;

                //PROTOBUF:RESPONSE
                _serializedResponsePackets.Add(
                    Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
            finally
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd executed on cache");
                }
            }
        }