public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int overload; string exception = null; int count = 0; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("BulkGetCmd.Exec", "cmd parsed"); } } catch (Exception exc) { _getBulkCacheItemResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; List <CacheEntry> pooledEntries = 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); } operationContext.Add(OperationContextFieldName.ClientOperationTimeout, clientManager.RequestTimeout); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); operationContext.CancellationToken = CancellationToken; IDictionary getResult = (IDictionary)nCache.Cache.GetBulkCacheItems(cmdInfo.Keys, cmdInfo.FlagMap, operationContext); count = getResult.Count; stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.BulkGetCacheItemResponse bulkGetCacheItemResponse = new Alachisoft.NCache.Common.Protobuf.BulkGetCacheItemResponse(); IDictionaryEnumerator enu = getResult.GetEnumerator(); while (enu.MoveNext()) { CacheEntry cacheEntry = null; try { var keyCacheItem = new Alachisoft.NCache.Common.Protobuf.KeyCacheItemPair(); keyCacheItem.key = (string)enu.Key; cacheEntry = (CacheEntry)enu.Value; if (cacheEntry != null) { if (cacheEntry.IsFromPool) { if (pooledEntries == null) { pooledEntries = new List <CacheEntry>(); } pooledEntries.Add(cacheEntry); } keyCacheItem.cacheItem = PopulateResponse(cacheEntry, clientManager, nCache.Cache); keyCacheItem.cacheItem.itemType = MiscUtil.EntryTypeToProtoItemType(cacheEntry.Type); bulkGetCacheItemResponse.KeyCacheItemPairs.Add(keyCacheItem); } else { bulkGetCacheItemResponse.KeyCacheItemPairs.Add(null); } } finally { if (cacheEntry != null) { cacheEntry.MarkFree(NCModulesConstants.Global); } } } if (clientManager.ClientVersion >= 5000) { ResponseHelper.SetResponse(bulkGetCacheItemResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(bulkGetCacheItemResponse, Common.Protobuf.Response.Type.BULK_GET_CACHEITEM)); } else { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.BULK_GET_CACHEITEM); response.bulkGetCacheItem = bulkGetCacheItemResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (OperationCanceledException ex) { exception = ex.ToString(); Dispose(); } catch (System.Exception exc) { _getBulkCacheItemResult = OperationResult.Failure; exception = exc.ToString(); //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } 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.GetBulk.ToLower()); log.GenerateBulkGetAPILogItem(cmdInfo.Keys.Length, cmdInfo.providerName, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString(), count); } if (pooledEntries != null && pooledEntries.Count > 0) { MiscUtil.ReturnEntriesToPool(pooledEntries, clientManager.CacheTransactionalPool); } } catch { } try { cmdInfo.FlagMap?.MarkFree(NCModulesConstants.SocketServer); } catch { } } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("BulkGetCmd.Exec", "cmd executed on cache"); } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", clientManager.ClientSocket.RemoteEndPoint.ToString() + " parsing error " + exc.ToString()); } if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } try { clientManager.ClientID = cmdInfo.ClientID; clientManager.IsDotNetClient = cmdInfo.IsDotNetClient; clientManager.SupportAcknowledgement = cmdInfo.CommandVersion >= 2 && requestLoggingEnabled; clientManager.ClientVersion = cmdInfo.clientVersion; #if (CLIENT) if (((IPEndPoint)clientManager.ClientSocket.LocalEndPoint).Address.Address != ((IPEndPoint)clientManager.ClientSocket.RemoteEndPoint).Address.Address) { throw new OperationNotSupportedException("Server can not accept remote clients in this edition of NCache"); } #endif clientManager.CmdExecuter = new NCache(cmdInfo.CacheId, cmdInfo.IsDotNetClient, clientManager, cmdInfo.LicenceCode, cmdInfo.clientInfo); // we dont need license logging in express edition. // and all our server components are in VS2005. ClientManager cmgr = null; lock (ConnectionManager.ConnectionTable) { if (ConnectionManager.ConnectionTable.Contains(clientManager.ClientID)) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", "Another client with same clientID exists. Client ID is " + clientManager.ClientID); } cmgr = ConnectionManager.ConnectionTable[clientManager.ClientID] as ClientManager; ConnectionManager.ConnectionTable.Remove(clientManager.ClientID); } ConnectionManager.ConnectionTable.Add(clientManager.ClientID, clientManager); } try { if (cmgr != null) { cmgr.RaiseClientDisconnectEvent = false; cmgr.Dispose(); } } catch (Exception e) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", " an error occurred while forcefully disposing a client. " + e.ToString()); } } clientManager.EventQueue = new EventsQueue(); clientManager.SlaveId = clientManager.ConnectionManager.EventsAndCallbackQueue.RegisterSlaveQueue(clientManager.EventQueue, clientManager.ClientID); // register queue with distributed queue. if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", clientManager.ClientID + " is connected to " + cmdInfo.CacheId); } //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.InitializeCacheResponse initializeCacheResponse = new Alachisoft.NCache.Common.Protobuf.InitializeCacheResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.INIT; response.initCache = initializeCacheResponse; initializeCacheResponse.requestLoggingEnabled = this.requestLoggingEnabled; initializeCacheResponse.isPersistenceEnabled = ((NCache)clientManager.CmdExecuter).Cache.IsPersistEnabled; initializeCacheResponse.persistenceInterval = ((NCache)clientManager.CmdExecuter).Cache.PersistenceInterval; initializeCacheResponse.cacheType = ((NCache)clientManager.CmdExecuter).Cache.CacheType.ToLower(); // if graceful shutdown is happening on any server node... List <Alachisoft.NCache.Caching.ShutDownServerInfo> shutDownServers = ((NCache)(clientManager.CmdExecuter)).Cache.GetShutDownServers(); if (shutDownServers != null && shutDownServers.Count > 0) { initializeCacheResponse.isShutDownProcessEnabled = true; foreach (Alachisoft.NCache.Caching.ShutDownServerInfo ssInfo in shutDownServers) { Alachisoft.NCache.Common.Protobuf.ShutDownServerInfo server = new Alachisoft.NCache.Common.Protobuf.ShutDownServerInfo(); server.serverIP = ssInfo.RenderedAddress.IpAddress.ToString(); server.port = ssInfo.RenderedAddress.Port; server.uniqueKey = ssInfo.UniqueBlockingId; server.timeoutInterval = ssInfo.BlockInterval; initializeCacheResponse.shutDownServerInfo.Add(server); } } _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); if (SocketServer.Logger.IsDetailedLogsEnabled) { SocketServer.Logger.NCacheLog.Info("InitializeCommand.Execute", clientManager.ClientSocket.RemoteEndPoint.ToString() + " : " + clientManager.ClientID + " connected to " + cmdInfo.CacheId); } } catch (Exception exc) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", clientManager.ClientSocket.RemoteEndPoint.ToString() + " : " + clientManager.ClientID + " failed to connect to " + cmdInfo.CacheId + " Error: " + exc.ToString()); } //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int overload; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); byte[] data = null; try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); } catch (ArgumentOutOfRangeException arEx) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("GetCommand", "command: " + command + " Error" + arEx); } _getResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(arEx, command.requestID, command.commandID)); } return; } catch (Exception exc) { _getResult = OperationResult.Failure; 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); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); operationContext.Add(OperationContextFieldName.ClientOperationTimeout, clientManager.RequestTimeout); operationContext.CancellationToken = CancellationToken; nCache.Cache.RemoveByTag(cmdInfo.Tags, cmdInfo.ComparisonType, operationContext); stopWatch.Stop(); //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.RemoveByTagResponse removeTagResponse = new Alachisoft.NCache.Common.Protobuf.RemoveByTagResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.REMOVE_TAG; response.removeTagResponse = removeTagResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (OperationCanceledException ex) { exception = ex.ToString(); Dispose(); } catch (Exception exc) { exception = exc.ToString(); _getResult = OperationResult.Failure; _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) { if (cmdInfo.ComparisonType == TagComparisonType.ALL_MATCHING_TAGS) { Hashtable tags = new Hashtable(); foreach (string tag in cmdInfo.Tags) { tags.Add(tag, tag); } APILogItemBuilder log = new APILogItemBuilder(MethodsName.RemoveByAllTags.ToLower()); log.GenerateRemoveByAllTagsAPILogItem(tags, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } else if (cmdInfo.ComparisonType == TagComparisonType.BY_TAG) { Hashtable tags = new Hashtable(); foreach (string tag in cmdInfo.Tags) { tags.Add(tag, tag); } if (tags != null) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.RemoveByTag.ToLower()); log.GenerateRemoveByTagAPILogItem(tags, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } else if (cmdInfo.ComparisonType == TagComparisonType.ANY_MATCHING_TAG) { Hashtable tags = new Hashtable(); foreach (string tag in cmdInfo.Tags) { tags.Add(tag, tag); } if (tags != null) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.RemoveByAnyTag.ToLower()); log.GenerateRemoveByAnyTagAPILogItem(tags, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } } } catch { } } }
//PROTOBUF private CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager) { CommandInfo cmdInfo = new CommandInfo(); Alachisoft.NCache.Common.Protobuf.DeleteQueryCommand deleteQueryCommand = command.deleteQueryCommand; cmdInfo.RequestId = deleteQueryCommand.requestId.ToString(); cmdInfo.ClientLastViewId = command.clientLastViewId; cmdInfo.CommandVersion = command.commandVersion; cmdInfo.Query = deleteQueryCommand.query; { cmdInfo.Values = new Hashtable(); foreach (Alachisoft.NCache.Common.Protobuf.KeyValue searchValue in deleteQueryCommand.values) { string key = searchValue.key; List <Alachisoft.NCache.Common.Protobuf.ValueWithType> valueWithTypes = searchValue.value; Type type = null; object value = null; foreach (Alachisoft.NCache.Common.Protobuf.ValueWithType valueWithType in valueWithTypes) { string typeStr = valueWithType.type; if (!clientManager.IsDotNetClient) { typeStr = JavaClrTypeMapping.JavaToClr(valueWithType.type); } type = Type.GetType(typeStr, true, true); if (valueWithType.value != null) { try { if (type == typeof(System.DateTime)) { // For client we would be sending ticks instead // of string representation of Date. value = new DateTime(Convert.ToInt64(valueWithType.value)); } else { value = Convert.ChangeType(valueWithType.value, type); } } catch (Exception) { throw new System.FormatException("Cannot convert '" + valueWithType.value + "' to " + type.ToString()); } } if (!cmdInfo.Values.Contains(key)) { cmdInfo.Values.Add(key, value); } else { ArrayList list = cmdInfo.Values[key] as ArrayList; // the value is not array list if (list == null) { list = new ArrayList(); list.Add(cmdInfo.Values[key]); // add the already present value in the list cmdInfo.Values.Remove(key); // remove the key from hashtable to avoid key already exists exception list.Add(value); // add the new value in the list cmdInfo.Values.Add(key, list); } else { list.Add(value); } } } } } return(cmdInfo); }
//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("LockCommand", "command: " + command + " Error" + arEx); } _lockResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(arEx, command.requestID)); } return; } catch (Exception exc) { _lockResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } try { NCache nCache = clientManager.CmdExecuter as NCache; object lockId = null; DateTime lockDate = DateTime.Now; bool res = nCache.Cache.Lock(cmdInfo.Key, cmdInfo.LockTimeout, out lockId, out 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.VerifyLockResponse verifyLockResponse = new Alachisoft.NCache.Common.Protobuf.VerifyLockResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.LOCK_VERIFY; response.lockVerify = verifyLockResponse; verifyLockResponse.lockId = lockId.ToString(); verifyLockResponse.success = res; verifyLockResponse.lockExpiration = lockDate.Ticks; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _lockResult = OperationResult.Failure; //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } }
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); } operationContext.Add(OperationContextFieldName.ClientOperationTimeout, clientManager.RequestTimeout); operationContext.CancellationToken = CancellationToken; resultSet = nCache.Cache.Search(cmdInfo.Query, cmdInfo.Values, operationContext); stopWatch.Stop(); SearchResponseBuilder.BuildResponse(resultSet, cmdInfo.RequestId, command.commandID, _serializedResponsePackets, cmdInfo.CommandVersion, out resultCount); } catch (OperationCanceledException ex) { exception = ex.ToString(); Dispose(); } 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 { } } }
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); 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, command.commandID)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; if (!cmdInfo.DoAsync) { try { CallbackEntry cbEntry = null; if (cmdInfo.DsItemRemovedId != -1) { cbEntry = new CallbackEntry(clientManager.ClientID, -1, null, -1, -1, -1, cmdInfo.DsItemRemovedId, cmdInfo.FlagMap , Runtime.Events.EventDataFilter.None, Runtime.Events.EventDataFilter.None); //DataFilter not required } OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.MethodOverload, overload); operationContext.Add(OperationContextFieldName.ClientId, clientManager.ClientID); nCache.Cache.Delete(cmdInfo.Key, cmdInfo.FlagMap, cbEntry, cmdInfo.LockId, cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, operationContext); stopWatch.Stop(); //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); response.commandID = command.commandID; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _removeResult = 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.DELETE.ToLower()); log.GenerateDeleteAPILogItem(cmdInfo.Key, cmdInfo.FlagMap, cmdInfo.LockId, (long)cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, cmdInfo.DsItemRemovedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd executed on cache"); } } } else { object[] package = null; if (!cmdInfo.RequestId.Equals("-1") || cmdInfo.DsItemRemovedId != -1) { package = new object[] { cmdInfo.Key, cmdInfo.FlagMap, new CallbackEntry(clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), null, -1, -1, (short)(cmdInfo.RequestId.Equals("-1") ? -1 : 0), cmdInfo.DsItemRemovedId, cmdInfo.FlagMap, EventDataFilter.None, EventDataFilter.None) }; // DataFilter not required } else { package = new object[] { cmdInfo.Key, cmdInfo.FlagMap, null, cmdInfo.ProviderName }; } OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.MethodOverload, overload); nCache.Cache.RemoveAsync(package, operationContext); stopWatch.Stop(); TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.DELETEASYNC.ToLower()); log.GenerateDeleteAPILogItem(cmdInfo.Key, cmdInfo.FlagMap, cmdInfo.LockId, (long)cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, cmdInfo.DsItemRemovedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; int overload; string exception = null; NotificationsType notif = 0; 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")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } try { NCache nCache = clientManager.CmdExecuter as NCache; OperationContext context = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); context.Add(OperationContextFieldName.ClientId, clientManager.ClientID); notif = (NotificationsType)cmdInfo.RegNotifs; if (command.commandVersion < 1) { context.Add(OperationContextFieldName.ClientLastViewId, forcedViewId); } else //NCache 4.1 SP1 or later { context.Add(OperationContextFieldName.ClientLastViewId, command.clientLastViewId.ToString(CultureInfo.InvariantCulture)); } //Will only register those which are == null i.e. not initialized nCache.RegisterNotification(notif); //Execute only if successfull if ((notif & NotificationsType.RegAddNotif) != 0 || (notif & NotificationsType.RegUpdateNotif) != 0 || (notif & NotificationsType.RegRemoveNotif) != 0) { nCache.MaxEventRequirement((Runtime.Events.EventDataFilter)cmdInfo.datafilter, notif, (short)cmdInfo.sequence); } stopWatch.Stop(); //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.RegisterNotifResponse registerNotifResponse = new Alachisoft.NCache.Common.Protobuf.RegisterNotifResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.REGISTER_NOTIF; response.registerNotifResponse = registerNotifResponse; if (clientManager.ClientVersion >= 5000) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.REGISTER_NOTIF)); } 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)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { string methodNme = null; if (notif == NotificationsType.UnregAddNotif || notif == NotificationsType.UnregAddNotif || notif == NotificationsType.UnregRemoveNotif) { methodNme = MethodsName.UnRegisterCacheNotification.ToLower(); } else { methodNme = MethodsName.RegisterCacheNotification.ToLower(); } APILogItemBuilder log = new APILogItemBuilder(methodNme); log.GenerateRegisterCacheNotificationCallback(0, notif.ToString(), cmdInfo.datafilter.ToString(), overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
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) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); return; } int resultCount = 0; try { NCache nCache = clientManager.CmdExecuter as NCache; QueryResultSet resultSet = null; QueryDataFilters datafilters = new QueryDataFilters(cmdInfo.addDF, cmdInfo.updateDF, cmdInfo.removeDF); Alachisoft.NCache.Caching.OperationContext operationContext = new Alachisoft.NCache.Caching.OperationContext(Alachisoft.NCache.Caching.OperationContextFieldName.OperationType, Alachisoft.NCache.Caching.OperationContextOperationType.CacheOperation); if (Convert.ToInt64(cmdInfo.ClientLastViewId) != -1) { operationContext.Add(Alachisoft.NCache.Caching.OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); } resultSet = nCache.Cache.SearchCQ(cmdInfo.Query, cmdInfo.Values, cmdInfo.clientUniqueId, clientManager.ClientID, cmdInfo.notifyAdd, cmdInfo.notifyUpdate, cmdInfo.notifyRemove, operationContext, datafilters); stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.searchCQResponse = SearchCQResponseBuilder.BuildResponse(resultSet, out resultCount); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_CQ; _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.SearchCQ.ToLower()); log.GenerateSearchCQAPILogItem(cmdInfo.Query, cmdInfo.Values, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), resultCount); } } catch { } } }
//PROTOBUF 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(); long result = 0; byte[] data = null; 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; long count = nCache.Cache.Count; stopWatch.Stop(); result = count; Alachisoft.NCache.Common.Protobuf.CountResponse countResponse = new Alachisoft.NCache.Common.Protobuf.CountResponse(); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); countResponse.count = count; response.count = countResponse; response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.COUNT; _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.Count.ToLower()); log.GenerateCacheCountAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), result); } } catch { } } }
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")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); // _commandBytes = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); } return; } try { CallbackInfo cbUpdate = null; CallbackInfo cbRemove = null; CallbackType callbackType = CallbackType(cmdInfo.callbackType); if (cmdInfo.dataFilter != -1) //Default value in protbuf set to -1 { EventDataFilter datafilter = (EventDataFilter)cmdInfo.dataFilter; cbUpdate = new CallbackInfo(!string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID, cmdInfo.UpdateCallbackId, datafilter, callbackType); cbRemove = new CallbackInfo(!string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID, cmdInfo.RemoveCallbackId, datafilter, cmdInfo.NotifyOnExpiration, callbackType); } else { cbUpdate = new CallbackInfo(!string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID, cmdInfo.UpdateCallbackId, EventDataFilter.None, callbackType); cbRemove = new CallbackInfo(!string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID, cmdInfo.RemoveCallbackId, EventDataFilter.None, cmdInfo.NotifyOnExpiration, callbackType); } NCache nCache = clientManager.CmdExecuter as NCache; OperationContext context = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); context.Add(OperationContextFieldName.ClientId, !string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID); context.Add(OperationContextFieldName.ClientOperationTimeout, clientManager.RequestTimeout); context.CancellationToken = CancellationToken; CommandsUtil.PopulateClientIdInContext(ref context, clientManager.ClientAddress); nCache.Cache.RegisterKeyNotificationCallback(cmdInfo.Keys, cbUpdate, cbRemove, context); if (clientManager.ClientVersion < 5000 && !clientManager.CreateEventSubscription) { Util.EventHelper.SubscribeEvents(clientManager.ClientID, TopicConstant.ItemLevelEventsTopic, nCache, context); clientManager.CreateEventSubscription = true; } stopWatch.Stop(); //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.RegisterBulkKeyNotifResponse registerBulkKeyNotifResponse = new Alachisoft.NCache.Common.Protobuf.RegisterBulkKeyNotifResponse(); if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(registerBulkKeyNotifResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(registerBulkKeyNotifResponse, Common.Protobuf.Response.Type.REGISTER_BULK_KEY_NOTIF)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.registerBulkKeyNotifResponse = registerBulkKeyNotifResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.REGISTER_BULK_KEY_NOTIF); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (OperationCanceledException ex) { exception = ex.ToString(); Dispose(); } catch (Exception exc) { exception = exc.ToString(); //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } 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.RegisterKeyNotificationCallback.ToLower()); log.GenerateKeyNotificationCallback(cmdInfo.Keys.Length, cmdInfo.UpdateCallbackId, cmdInfo.RemoveCallbackId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { //No need to implement this }
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) { _removeBulkResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } byte[] data = null; try { NCache nCache = clientManager.CmdExecuter as NCache; CallbackEntry cbEnrty = null; if (cmdInfo.DsItemsRemovedId != -1) { cbEnrty = new CallbackEntry(clientManager.ClientID, -1, null, -1, -1, -1, cmdInfo.DsItemsRemovedId, cmdInfo.FlagMap, Runtime.Events.EventDataFilter.None, Runtime.Events.EventDataFilter.None); // DataFilter not required } OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); if (!string.IsNullOrEmpty(cmdInfo.IntendedRecipient)) { operationContext.Add(OperationContextFieldName.IntendedRecipient, cmdInfo.IntendedRecipient); } operationContext.Add(OperationContextFieldName.ClientId, clientManager.ClientID); nCache.Cache.Delete(cmdInfo.Keys, cmdInfo.FlagMap, cbEnrty, cmdInfo.ProviderName, operationContext); stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.BulkDeleteResponse bulkDeleteResponse = new Alachisoft.NCache.Common.Protobuf.BulkDeleteResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.intendedRecipient = cmdInfo.IntendedRecipient; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.DELETE_BULK; response.bulkDeleteResponse = bulkDeleteResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _removeBulkResult = OperationResult.Failure; exception = exc.ToString(); //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } finally { try { TimeSpan executionTime = stopWatch.Elapsed; if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.DELETEBULK.ToLower()); log.GenerateBulkDeleteAPILogItem(cmdInfo.Keys.Length, cmdInfo.FlagMap, cmdInfo.ProviderName, cmdInfo.DsItemsRemovedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } 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(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } try { NCache nCache = clientManager.CmdExecuter as NCache; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.ClientOperationTimeout, clientManager.RequestTimeout); operationContext.CancellationToken = CancellationToken; 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 , operationContext); stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.UnregisterBulkKeyNotifResponse unregResponse = new Common.Protobuf.UnregisterBulkKeyNotifResponse(); if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(unregResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(unregResponse, Common.Protobuf.Response.Type.UNREGISTER_BULK_KEY_NOTIF)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.unregisterBulkKeyNotifResponse = unregResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.UNREGISTER_BULK_KEY_NOTIF); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (OperationCanceledException ex) { exception = ex.ToString(); Dispose(); } catch (Exception exc) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } 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()); // Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { ClientId = clientManager.ClientID; Hashtable queryInfo = null; ExpirationHint expHint = null; NCache nCache = clientManager.CmdExecuter as NCache; int overload; bool itemUpdated = false; bool itemRemove = false; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { serailizationContext = nCache.CacheId; overload = command.MethodOverload; cmdInfo = base.ParseCommand(command, clientManager, serailizationContext); } catch (Exception exc) { _insertBulkResult = OperationResult.Failure; exception = exc.ToString(); //if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); // _resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); } return; } //TODO byte[] dataPackage = null; try { OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); if (!string.IsNullOrEmpty(cmdInfo.IntendedRecipient)) { operationContext.Add(OperationContextFieldName.IntendedRecipient, cmdInfo.IntendedRecipient); } operationContext.Add(OperationContextFieldName.WriteThru, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteThru)); operationContext.Add(OperationContextFieldName.WriteBehind, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteBehind)); if (cmdInfo.ProviderName != null) { operationContext.Add(OperationContextFieldName.WriteThruProviderName, cmdInfo.ProviderName); } operationContext.Add(OperationContextFieldName.ClientOperationTimeout, clientManager.RequestTimeout); operationContext.CancellationToken = CancellationToken; queryInfo = cmdInfo.Entries[0].QueryInfo; expHint = cmdInfo.Entries[0].ExpirationHint; IDictionary itemVersions = null; Hashtable insertResult = (Hashtable)nCache.Cache.Insert(cmdInfo.Keys, cmdInfo.Entries, cmdInfo.Flag, cmdInfo.ProviderName, null, out itemVersions, operationContext); stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.BulkInsertResponse bulkInsertResponse = new Alachisoft.NCache.Common.Protobuf.BulkInsertResponse(); bulkInsertResponse.intendedRecipient = cmdInfo.IntendedRecipient; bulkInsertResponse.keyExceptionPackage = new Alachisoft.NCache.Common.Protobuf.KeyExceptionPackageResponse(); bulkInsertResponse.keyVersionPackage = new Alachisoft.NCache.Common.Protobuf.KeyVersionPackageResponse(); //TODO : Package Key Value Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysExceptions(insertResult, bulkInsertResponse.keyExceptionPackage); if (cmdInfo.returnVersion) { Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysVersion(itemVersions, bulkInsertResponse.keyVersionPackage); } if (clientManager.ClientVersion >= 5000) { ResponseHelper.SetResponse(bulkInsertResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(bulkInsertResponse, Common.Protobuf.Response.Type.INSERT_BULK)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.bulkInsert = bulkInsertResponse; ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.INSERT_BULK); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (OperationCanceledException ex) { exception = ex.ToString(); Dispose(); } catch (Exception exc) { _insertBulkResult = OperationResult.Failure; //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } 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.INSERTBULK.ToLower()); Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(expHint, queryInfo); log.GenerateADDInsertBulkAPILogItem(cmdInfo.Keys.Length, cmdInfo.Entries.Length, expirationHint["dependency"] != null ? expirationHint["dependency"] as ArrayList : null, expirationHint["absolute-expiration"] != null ? (long)expirationHint["absolute-expiration"] : -1, expirationHint["sliding-expiration"] != null ? (long)expirationHint["sliding-expiration"] : -1, cmdInfo.Entries[0].Priority, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.Group != null ? cmdInfo.Group : null, cmdInfo.SubGroup != null ? cmdInfo.SubGroup : null, cmdInfo.Entries[0].Flag, cmdInfo.ProviderName, cmdInfo.Entries[0].ResyncProviderName, false, cmdInfo.Entries[0].HasQueryInfo, (long)cmdInfo.Entries[0].Version, cmdInfo.onUpdateCallbackId, cmdInfo.OnDsItemsAddedCallback, false, false, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString()); } } catch { } } if (cmdInfo.Entries != null) { foreach (var entry in cmdInfo.Entries) { entry.Flag?.MarkFree(NCModulesConstants.SocketServer); } } if (cmdInfo.Entries != null) { cmdInfo.Entries.MarkFree(NCModulesConstants.SocketServer); MiscUtil.ReturnEntriesToPool(cmdInfo.Entries, clientManager.CacheTransactionalPool); } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; byte[] data = null; NCache nCache = clientManager.CmdExecuter as NCache; int overload; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; serializationContext = nCache.CacheId; 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, command.commandID)); } return; } data = new byte[1]; try { //PROTOBUF:RESPONSE bool result = nCache.Cache.AddExpirationHint(cmdInfo.Key, cmdInfo.ExpHint, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); //PROTOBUF:RESPONSE stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.AddDependencyResponse addDependencyResponse = new Alachisoft.NCache.Common.Protobuf.AddDependencyResponse(); addDependencyResponse.success = result; response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.ADD_DEPENDENCY; response.addDep = addDependencyResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } 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.AddDEPENDENCY.ToLower()); Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpHint, null); log.GenerateAddDependencyAPILogItem(cmdInfo.Key, cmdInfo._isResync, expirationHint["dependency"] != null ? expirationHint["dependency"] as ArrayList : null, null, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { NCache nCache = clientManager.CmdExecuter as NCache; int overload; string exception = null; bool itemUpdated = false; bool itemRemove = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; serializationContext = nCache.CacheId; cmdInfo = base.ParseCommand(command, clientManager, serializationContext); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("AddCmd.Exec", "cmd parsed"); } } catch (Exception exc) { _addResult = OperationResult.Failure; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); return; } CallbackEntry callbackEntry = null; if (cmdInfo.UpdateCallbackId != -1 || cmdInfo.RemoveCallbackId != -1 || (!cmdInfo.RequestId.Equals("-1") && cmdInfo.DoAsync) || cmdInfo.DsItemAddedCallbackId != -1) { if (cmdInfo.RemoveCallbackId != -1) { itemRemove = true; } if (cmdInfo.UpdateCallbackId != -1) { itemUpdated = true; } callbackEntry = new CallbackEntry(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), cmdInfo.value, cmdInfo.RemoveCallbackId, cmdInfo.UpdateCallbackId, (short)(cmdInfo.RequestId.Equals("-1") ? -1 : 0), cmdInfo.DsItemAddedCallbackId, cmdInfo.Flag, (EventDataFilter)cmdInfo.UpdateDataFilter, (EventDataFilter)cmdInfo.RemoveDataFilter); } if (!cmdInfo.DoAsync) { try { OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); UInt64 itemVersion = 0; if (cmdInfo.ItemVersion == 0) { itemVersion = (UInt64)(DateTime.Now - new System.DateTime(2016, 1, 1, 0, 0, 0)).TotalMilliseconds; } else { itemVersion = cmdInfo.ItemVersion; } operationContext.Add(OperationContextFieldName.ItemVersion, itemVersion); operationContext.Add(OperationContextFieldName.MethodOverload, overload); nCache.Cache.Add(cmdInfo.Key, callbackEntry == null ? cmdInfo.value : (object)callbackEntry, cmdInfo.ExpirationHint, cmdInfo.SyncDependency, cmdInfo.EvictionHint, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.queryInfo, cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, operationContext, null); stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.AddResponse addResponse = new Alachisoft.NCache.Common.Protobuf.AddResponse(); // retrieve the version added... itemVersion = (ulong)operationContext.GetValueByField(OperationContextFieldName.ItemVersion); addResponse.itemversion = itemVersion; response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.ADD; response.addResponse = addResponse; //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _addResult = OperationResult.Failure; 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.ADD.ToLower()); object toInsert; if (cmdInfo.value is UserBinaryObject) { UserBinaryObject data = (UserBinaryObject)cmdInfo.value; toInsert = data.Length; } else { toInsert = cmdInfo.DataFormatValue; } Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo); log.GenerateADDInsertAPILogItem(cmdInfo.Key, toInsert, expirationHint["dependency"] != null ? expirationHint["dependency"] as ArrayList : null, expirationHint["absolute-expiration"] != null ? (long)expirationHint["absolute-expiration"] : -1, expirationHint["sliding-expiration"] != null ? (long)expirationHint["sliding-expiration"] : -1, cmdInfo.EvictionHint.Priority, cmdInfo.SyncDependency, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, false, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.UpdateCallbackId, cmdInfo.DsItemAddedCallbackId, false, itemUpdated, itemRemove, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString()); } } catch { } } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("AddCmd.Exec", "cmd executed on cache"); } } else { OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.WriteThru, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteThru)); operationContext.Add(OperationContextFieldName.WriteBehind, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteBehind)); if (cmdInfo.ProviderName != null) { operationContext.Add(OperationContextFieldName.WriteThruProviderName, cmdInfo.ProviderName); } operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); UInt64 itemVersion = 0; if (cmdInfo.ItemVersion == 0) { itemVersion = (UInt64)(DateTime.Now - new System.DateTime(2016, 1, 1, 0, 0, 0)).TotalMilliseconds; } else { itemVersion = cmdInfo.ItemVersion; } operationContext.Add(OperationContextFieldName.ItemVersion, itemVersion); operationContext.Add(OperationContextFieldName.MethodOverload, overload); bool onAsyncCall = false; if (callbackEntry != null) { onAsyncCall = true; } nCache.Cache.AddAsync(cmdInfo.Key, callbackEntry == null ? (object)cmdInfo.value : (object)callbackEntry, cmdInfo.ExpirationHint, cmdInfo.SyncDependency, cmdInfo.EvictionHint, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.Flag, cmdInfo.queryInfo, cmdInfo.ProviderName, operationContext); stopWatch.Stop(); TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.ADDASYNC.ToLower()); Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo); object toInsert; if (cmdInfo.value is UserBinaryObject) { UserBinaryObject data = (UserBinaryObject)cmdInfo.value; toInsert = data.Length; } else { toInsert = cmdInfo.DataFormatValue; } log.GenerateADDInsertAPILogItem(cmdInfo.Key, toInsert, expirationHint["dependency"] != null ? expirationHint["dependency"] as ArrayList : null, expirationHint["absolute-expiration"] != null ? (long)expirationHint["absolute-expiration"] : -1, expirationHint["sliding-expiration"] != null ? (long)expirationHint["sliding-expiration"] : -1, cmdInfo.EvictionHint.Priority, cmdInfo.SyncDependency, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.Flag, cmdInfo.ProviderName, cmdInfo.ResyncProviderName, false, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.UpdateCallbackId, cmdInfo.DsItemAddedCallbackId, onAsyncCall, itemUpdated, itemRemove, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString()); } } catch { } } }
//TODO:KeyPackage //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(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); } return; } int count = 0; string keyPackage = null; try { NCache nCache = clientManager.CmdExecuter as NCache; IDictionaryEnumerator dicEnu = (IDictionaryEnumerator)nCache.Cache.GetEnumerator(); //IEnumerator enu = (IEnumerator)nCache.Cache.GetEnumerator(); //KeyPackageBuilder.PackageKeys(dicEnu, out keyPackage, out count); stopWatch.Stop(); //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.GetEnumeratorResponse getEnumeratorResponse = new Alachisoft.NCache.Common.Protobuf.GetEnumeratorResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_ENUMERATOR; response.getEnum = getEnumeratorResponse; Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeys(dicEnu, getEnumeratorResponse.keys); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.GET_ENUMERATOR)); //_resultPacket = clientManager.ReplyPacket("GETENUMRESULT \"" + count + "\"" + cmdInfo.RequestId + "\"" + keyPackage, new byte[0]); } catch (Exception exc) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); //_resultPacket = 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.GetEnumerator.ToLower()); log.GenerateGetEnumeratorAPILogItem(overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); // Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo); } } catch { } } }
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("BulkAddCmd.Exec", "cmd parsed"); } } catch (Exception exc) { _addBulkResult = OperationResult.Failure; //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); return; } byte[] dataPackage = null; try { //PROTOBUF:RESPONSE 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 addResult = (Hashtable)nCache.Cache.Add(cmdInfo.Keys, cmdInfo.Entries, operationContext); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.BulkAddResponse bulkAddResponse = new Alachisoft.NCache.Common.Protobuf.BulkAddResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.intendedRecipient = cmdInfo.IntendedRecipient; bulkAddResponse.keyExceptionPackage = new Alachisoft.NCache.Common.Protobuf.KeyExceptionPackageResponse(); Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysExceptions(addResult, bulkAddResponse.keyExceptionPackage); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.ADD_BULK; response.bulkAdd = bulkAddResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _addBulkResult = OperationResult.Failure; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("BulkAddCmd.Exec", "cmd executed on cache"); } }
//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")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } try { NCache nCache = clientManager.CmdExecuter as NCache; nCache.Cache.UnregisterKeyNotificationCallback(cmdInfo.Key , 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.UnregisterKeyNotifResponse unregisterKeyNotifResponse = new Alachisoft.NCache.Common.Protobuf.UnregisterKeyNotifResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.UNREGISTER_KEY_NOTIF; response.unregisterKeyNotifResponse = unregisterKeyNotifResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { 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.UnRegisterKeyNotificationCallback.ToLower()); log.GenerateKeyNotificationCallback(1, cmdInfo.UpdateCallbackId, cmdInfo.RemoveCallbackId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
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(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } try { CallbackInfo cbUpdate = null; CallbackInfo cbRemove = null; CallbackType callbackType = CallbackType(cmdInfo.callbackType); if (cmdInfo.dataFilter != -1) // Default value in protbuf set to -1 { EventDataFilter datafilter = (EventDataFilter)cmdInfo.dataFilter; cbUpdate = new CallbackInfo(!string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID, cmdInfo.UpdateCallbackId, datafilter, callbackType); cbRemove = new CallbackInfo(!string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID, cmdInfo.RemoveCallbackId, datafilter, cmdInfo.NotifyOnExpiration, callbackType); } else { cbUpdate = new CallbackInfo(!string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID, cmdInfo.UpdateCallbackId, EventDataFilter.None, callbackType); cbRemove = new CallbackInfo(!string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID, cmdInfo.RemoveCallbackId, EventDataFilter.DataWithMetadata, cmdInfo.NotifyOnExpiration, callbackType); } NCache nCache = clientManager.CmdExecuter as NCache; OperationContext context = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); context.Add(OperationContextFieldName.ClientId, !string.IsNullOrEmpty(cmdInfo.SurrogateClientID) ? cmdInfo.SurrogateClientID : clientManager.ClientID); nCache.Cache.RegisterKeyNotificationCallback(cmdInfo.Keys, cbUpdate, cbRemove, context); stopWatch.Stop(); //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.RegisterBulkKeyNotifResponse registerBulkKeyNotifResponse = new Alachisoft.NCache.Common.Protobuf.RegisterBulkKeyNotifResponse(); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.REGISTER_BULK_KEY_NOTIF; response.registerBulkKeyNotifResponse = registerBulkKeyNotifResponse; response.requestId = command.registerBulkKeyNotifCommand.requestId; response.commandID = command.commandID; _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.RegisterKeyNotificationCallback.ToLower()); log.GenerateKeyNotificationCallback(cmdInfo.Keys.Length, cmdInfo.UpdateCallbackId, cmdInfo.RemoveCallbackId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { ClientId = clientManager.ClientID; Hashtable queryInfo = null; ExpirationHint expHint = null; NCache nCache = clientManager.CmdExecuter as NCache; int overload; bool itemUpdated = false; bool itemRemove = false; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { serailizationContext = nCache.CacheId; overload = command.MethodOverload; cmdInfo = base.ParseCommand(command, clientManager, serailizationContext); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("BulkInsCmd.Exec", "cmd parsed"); } } catch (Exception exc) { _insertBulkResult = OperationResult.Failure; exception = exc.ToString(); { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } byte[] dataPackage = null; try { OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); if (!string.IsNullOrEmpty(cmdInfo.IntendedRecipient)) { operationContext.Add(OperationContextFieldName.IntendedRecipient, cmdInfo.IntendedRecipient); } operationContext.Add(OperationContextFieldName.WriteThru, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteThru)); operationContext.Add(OperationContextFieldName.WriteBehind, cmdInfo.Flag.IsBitSet(BitSetConstants.WriteBehind)); if (cmdInfo.ProviderName != null) { operationContext.Add(OperationContextFieldName.WriteThruProviderName, cmdInfo.ProviderName); } queryInfo = cmdInfo.Entries[0].QueryInfo; expHint = cmdInfo.Entries[0].ExpirationHint; IDictionary itemVersions = null; Hashtable insertResult = (Hashtable)nCache.Cache.Insert(cmdInfo.Keys, cmdInfo.Entries, cmdInfo.Flag, cmdInfo.ProviderName, null, out itemVersions, operationContext); stopWatch.Stop(); 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.commandID = command.commandID; response.intendedRecipient = cmdInfo.IntendedRecipient; bulkInsertResponse.keyExceptionPackage = new Alachisoft.NCache.Common.Protobuf.KeyExceptionPackageResponse(); bulkInsertResponse.keyVersionPackage = new Alachisoft.NCache.Common.Protobuf.KeyVersionPackageResponse(); //TODO : Package Key Value Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysExceptions(insertResult, bulkInsertResponse.keyExceptionPackage); if (cmdInfo.returnVersion) { Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysVersion(itemVersions, bulkInsertResponse.keyVersionPackage); } 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, 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.INSERTBULK.ToLower()); Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(expHint, queryInfo); log.GenerateADDInsertBulkAPILogItem(cmdInfo.Keys.Length, cmdInfo.Entries.Length, expirationHint["dependency"] != null ? expirationHint["dependency"] as ArrayList : null, expirationHint["absolute-expiration"] != null ? (long)expirationHint["absolute-expiration"] : -1, expirationHint["sliding-expiration"] != null ? (long)expirationHint["sliding-expiration"] : -1, cmdInfo.Entries[0].Priority, cmdInfo.Entries[0].SyncDependency, expirationHint["tag-info"] != null ? expirationHint["tag-info"] as Hashtable : null, expirationHint["named-tags"] != null ? expirationHint["named-tags"] as Hashtable : null, cmdInfo.Group != null ? cmdInfo.Group : null, cmdInfo.SubGroup != null ? cmdInfo.SubGroup : null, cmdInfo.Entries[0].Flag, cmdInfo.Entries[0].ProviderName, cmdInfo.Entries[0].ResyncProviderName, false, cmdInfo.Entries[0].HasQueryInfo, (long)cmdInfo.Entries[0].Version, cmdInfo.onUpdateCallbackId, cmdInfo.OnDsItemsAddedCallback, false, false, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString()); } } catch { } } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("BulkInsCmd.Exec", "cmd executed on cache"); } }
public override void ProcessCommand(ClientManager clientManager, object cmd, short cmdType, long acknowledgementId, UsageStats stats, bool waitforResponse) { Alachisoft.NCache.Common.Protobuf.Command command = cmd as Alachisoft.NCache.Common.Protobuf.Command; if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "enter"); } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "" + command); } if (SocketServer.Logger.IsDetailedLogsEnabled) { SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " COMMAND to be executed : " + command.type.ToString() + " RequestId :" + command.requestID); } bool clientDisposed = false; CommandBase incommingCmd = null; bool isUnsafeCommand = false; switch (command.type) { case Alachisoft.NCache.Common.Protobuf.Command.Type.INIT: Alachisoft.NCache.Common.Protobuf.InitCommand initCommand = command.initCommand; initCommand.requestId = command.requestID; if (SocketServer.Logger.IsDetailedLogsEnabled) { SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " RequestId :" + command.requestID); } incommingCmd = new ServiceInitializeCommand(base.RequestLogger.RequestLoggingEnabled, acknowledgementId); break; case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_OPTIMAL_SERVER: command.getOptimalServerCommand.requestId = command.requestID; incommingCmd = new ServiceGetOptimalServerCommand(acknowledgementId); break; case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_CACHE_BINDING: command.getCacheBindingCommand.requestId = command.requestID; incommingCmd = new ServiceCacheBindingCommand(acknowledgementId); break; case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_SERVER_MAPPING: command.getServerMappingCommand.requestId = command.requestID; incommingCmd = new GetServerMappingCommand(); break; case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_CACHE_MANAGEMENT_PORT: command.getCacheManagementPortCommand.requestId = command.requestID; incommingCmd = new GetCacheManagementPortCommand(); break; } if (SocketServer.IsServerCounterEnabled) { base.PerfStatsCollector.MsecPerCacheOperationBeginSample(); } try { if (isUnsafeCommand && clientManager.SupportAcknowledgement) { if (clientDisposed) { base.RequestLogger.RemoveClientAccount(clientManager.ClientID); } else { base.RequestLogger.RegisterRequest(clientManager.ClientID, command.requestID, command.commandID, acknowledgementId); } } incommingCmd.ExecuteCommand(clientManager, command); } catch (Exception ex) { if (isUnsafeCommand && clientManager.SupportAcknowledgement) { base.RequestLogger.UpdateRequest(clientManager.ClientID, command.requestID, command.commandID, Alachisoft.NCache.Common.Enum.RequestStatus.RECEIVED_WITH_ERROR, null); } throw; } if (SocketServer.Logger.IsDetailedLogsEnabled) { SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " after executing COMMAND : " + command.type.ToString() + " RequestId :" + command.requestID); } if (SocketServer.IsServerCounterEnabled) { base.PerfStatsCollector.MsecPerCacheOperationEndSample(); } #if SERVER if (clientManager != null && incommingCmd.OperationResult == OperationResult.Success) { if (clientManager.CmdExecuter != null) { clientManager.CmdExecuter.UpdateSocketServerStats(new SocketServerStats(clientManager.ClientsRequests, clientManager.ClientsBytesSent, clientManager.ClientsBytesRecieved)); } } #endif if (isUnsafeCommand && clientManager.SupportAcknowledgement) { if (clientManager != null && clientManager.IsDisposed && incommingCmd.OperationResult == OperationResult.Failure) { base.RequestLogger.UpdateRequest(clientManager.ClientID, command.requestID, command.commandID, Alachisoft.NCache.Common.Enum.RequestStatus.RECEIVED_WITH_ERROR, null); } else { base.RequestLogger.UpdateRequest(clientManager.ClientID, command.requestID, command.commandID, Alachisoft.NCache.Common.Enum.RequestStatus.RECEIVED_AND_EXECUTED, incommingCmd.SerializedResponsePackets); } } if (clientManager != null && incommingCmd.SerializedResponsePackets != null && !clientManager.IsCacheStopped) { if (SocketServer.IsServerCounterEnabled) { base.PerfStatsCollector.IncrementResponsesPerSecStats(1); } foreach (IList reponse in incommingCmd.SerializedResponsePackets) { ConnectionManager.AssureSendSync(clientManager, reponse); } } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "exit"); } }
private CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager) { CommandInfo cmdInfo = new CommandInfo(); Alachisoft.NCache.Common.Protobuf.RegisterCQCommand registerCQCommand = command.registerCQCommand; cmdInfo.Query = registerCQCommand.query; cmdInfo.RequestId = registerCQCommand.requestId.ToString(); cmdInfo.notifyAdd = registerCQCommand.notifyAdd; cmdInfo.notifyUpdate = registerCQCommand.notifyUpdate; cmdInfo.notifyRemove = registerCQCommand.notifyRemove; cmdInfo.clientUniqueId = registerCQCommand.clientUniqueId; cmdInfo.addDataFilter = registerCQCommand.addDataFilter; cmdInfo.removeDataFilter = registerCQCommand.remvoeDataFilter; cmdInfo.updateDataFilter = registerCQCommand.updateDataFilter; { cmdInfo.Values = new Hashtable(); foreach (Alachisoft.NCache.Common.Protobuf.KeyValue searchValue in registerCQCommand.values) { string key = searchValue.key; List <Alachisoft.NCache.Common.Protobuf.ValueWithType> valueWithTypes = searchValue.value; Type type = null; object value = null; foreach (Alachisoft.NCache.Common.Protobuf.ValueWithType valueWithType in valueWithTypes) { string typeStr = valueWithType.type; if (!clientManager.IsDotNetClient) { typeStr = JavaClrTypeMapping.JavaToClr(valueWithType.type); } type = Type.GetType(typeStr, true, true); if (valueWithType.value != null) { try { if (type == typeof(System.DateTime)) { if (clientManager.IsDotNetClient) { System.Globalization.CultureInfo enUs = new System.Globalization.CultureInfo("en-US"); value = Convert.ChangeType(valueWithType.value, type, enUs); } else { // For java client we would be sending ticks instead // of string representation of Date. long ticks = long.Parse(valueWithType.value); value = new DateTime(ticks); } } else { value = Convert.ChangeType(valueWithType.value, type); } } catch (Exception) { throw new System.FormatException("Cannot convert '" + valueWithType.value + "' to " + type.ToString()); } } if (!cmdInfo.Values.Contains(key)) { cmdInfo.Values.Add(key, value); } else { ArrayList list = cmdInfo.Values[key] as ArrayList; // the value is not array list if (list == null) { list = new ArrayList(); list.Add(cmdInfo.Values[key]); // add the already present value in the list cmdInfo.Values.Remove(key); // remove the key from hashtable to avoid key already exists exception list.Add(value); // add the new value in the list cmdInfo.Values.Add(key, list); } else { list.Add(value); } } } } } return(cmdInfo); }
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 { 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; } int count = 0; string keyPackage = null; try { NCache nCache = clientManager.CmdExecuter as NCache; EnumerationDataChunk nextChunk = nCache.Cache.GetNextChunk(cmdInfo.Pointer, cmdInfo.OperationContext); stopWatch.Stop(); 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.commandID = command.commandID; 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) { 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.GetNextChunk.ToLower()); log.GenerateGetEnumeratorAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
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")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } try { NCache nCache = clientManager.CmdExecuter as NCache; System.Collections.Generic.Dictionary <Runtime.Events.EventType, Runtime.Events.EventDataFilter> arr = new System.Collections.Generic.Dictionary <Runtime.Events.EventType, Runtime.Events.EventDataFilter>(); QueryDataFilters datafilters = new QueryDataFilters(cmdInfo.addDataFilter, cmdInfo.updateDataFilter, cmdInfo.removeDataFilter); string queryId = nCache.Cache.RegisterCQ(cmdInfo.Query, cmdInfo.Values, cmdInfo.clientUniqueId, clientManager.ClientID, cmdInfo.notifyAdd, cmdInfo.notifyUpdate, cmdInfo.notifyRemove, new Alachisoft.NCache.Caching.OperationContext(Alachisoft.NCache.Caching.OperationContextFieldName.OperationType, Alachisoft.NCache.Caching.OperationContextOperationType.CacheOperation), datafilters); stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.RegisterCQResponse registerCQResponse = new Alachisoft.NCache.Common.Protobuf.RegisterCQResponse(); registerCQResponse.cqId = queryId; response.registerCQResponse = registerCQResponse; response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.REGISTER_CQ; _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.RegisterCQ.ToLower()); log.GenerateRegisterCQAPILogItem(cmdInfo.Query, cmdInfo.Values, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", clientManager.ClientSocket.RemoteEndPoint.ToString() + " parsing error " + exc.ToString()); } if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithoutType(exc, command.requestID, command.commandID)); } return; } try { clientManager.ClientID = cmdInfo.ClientID; clientManager.IsDotNetClient = cmdInfo.IsDotNetClient; clientManager.SupportAcknowledgement = cmdInfo.CommandVersion >= 2 && requestLoggingEnabled; clientManager.ClientVersion = cmdInfo.clientVersion; clientManager.SecureConnectionEnabled = cmdInfo.SecureConnectionEnabled; cmdInfo.clientInfo.ClientVersion = cmdInfo.clientVersion; GetClientUsage(clientManager, cmdInfo); ClientLedger.Instance.RegisterClientForCache(clientManager.ClientAddress, clientManager.ClientID); //Older client do not send operation timeout clientManager.RequestTimeout = cmdInfo.operationTimeout != -1? cmdInfo.operationTimeout: 90 * 1000; clientManager.CmdExecuter = new NCache(cmdInfo.CacheId, cmdInfo.IsDotNetClient, clientManager, cmdInfo.LicenceCode, cmdInfo.UserName, cmdInfo.Password, cmdInfo.UserNameBinary, cmdInfo.PassworNameBinary, cmdInfo.clientInfo); if (clientManager.PoolManager == null) { var shouldCreateFakePools = (clientManager.CmdExecuter as NCache).Cache.TransactionalPoolManager.IsUsingFakePools; clientManager.ConnectionManager.CreatePools(shouldCreateFakePools); } clientManager.CacheTransactionalPool = ((NCache)clientManager.CmdExecuter).Cache.Context.TransactionalPoolManager; clientManager.CacheFakePool = ((NCache)clientManager.CmdExecuter).Cache.Context.FakeObjectPool; ClientManager cmgr = null; int noOfConnectedClients = 0; lock (ConnectionManager.ConnectionTable) { if (ConnectionManager.ConnectionTable.Contains(clientManager.ClientID)) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", "Another client with same clientID exists. Client ID is " + clientManager.ClientID); } cmgr = ConnectionManager.ConnectionTable[clientManager.ClientID] as ClientManager; ConnectionManager.ConnectionTable.Remove(clientManager.ClientID); } ConnectionManager.ConnectionTable.Add(clientManager.ClientID, clientManager); clientManager.ConnectionManager.PerfStatsColl.ConncetedClients = noOfConnectedClients = ConnectionManager.ConnectionTable.Count; } clientManager.CmdExecuter.OnClientConnected(clientManager.ClientID, cmdInfo.CacheId, cmdInfo.clientInfo, noOfConnectedClients); try { if (cmgr != null) { cmgr.RaiseClientDisconnectEvent = false; cmgr.Dispose(); } } catch (Exception e) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", " an error occurred while forcefully disposing a client. " + e.ToString()); } } clientManager.EventQueue = new EventsQueue(); clientManager.SlaveId = clientManager.ConnectionManager.EventsAndCallbackQueue.RegisterSlaveQueue(clientManager.EventQueue, clientManager.ClientID); // register queue with distributed queue. if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", clientManager.ClientID + " is connected to " + cmdInfo.CacheId); } //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.InitializeCacheResponse initializeCacheResponse = new Alachisoft.NCache.Common.Protobuf.InitializeCacheResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.INIT; response.initCache = initializeCacheResponse; initializeCacheResponse.requestLoggingEnabled = this.requestLoggingEnabled; initializeCacheResponse.isPersistenceEnabled = ((NCache)clientManager.CmdExecuter).Cache.IsPersistEnabled; initializeCacheResponse.persistenceInterval = ((NCache)clientManager.CmdExecuter).Cache.PersistenceInterval; initializeCacheResponse.cacheType = ((NCache)clientManager.CmdExecuter).Cache.CacheType.ToLower(); #if SERVER initializeCacheResponse.targetCacheUniqueID = ((NCache)(clientManager.CmdExecuter)).Cache.TargetCacheUniqueID; #endif //if graceful shutdown is happening on any server node... List <Alachisoft.NCache.Caching.ShutDownServerInfo> shutDownServers = ((NCache)(clientManager.CmdExecuter)).Cache.GetShutDownServers(); if (shutDownServers != null && shutDownServers.Count > 0) { initializeCacheResponse.isShutDownProcessEnabled = true; foreach (Alachisoft.NCache.Caching.ShutDownServerInfo ssInfo in shutDownServers) { Alachisoft.NCache.Common.Protobuf.ShutDownServerInfo server = new Alachisoft.NCache.Common.Protobuf.ShutDownServerInfo(); server.serverIP = ssInfo.RenderedAddress.IpAddress.ToString(); server.port = ssInfo.RenderedAddress.Port; server.uniqueKey = ssInfo.UniqueBlockingId; server.timeoutInterval = ssInfo.BlockInterval; initializeCacheResponse.shutDownServerInfo.Add(server); } } _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); if (SocketServer.Logger.IsDetailedLogsEnabled) { SocketServer.Logger.NCacheLog.Info("InitializeCommand.Execute", clientManager.ClientSocket.RemoteEndPoint.ToString() + " : " + clientManager.ClientID + " connected to " + cmdInfo.CacheId); } } catch (SecurityException sec) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", clientManager.ClientSocket.RemoteEndPoint.ToString() + " : " + clientManager.ClientID + " failed to connect to " + cmdInfo.CacheId + " Error: " + sec.ToString()); } //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithoutType(sec, command.requestID, command.commandID)); } catch (Exception exc) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("InitializeCommand.Execute", clientManager.ClientSocket.RemoteEndPoint.ToString() + " : " + clientManager.ClientID + " failed to connect to " + cmdInfo.CacheId + " Error: " + exc.ToString()); } //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithoutType(exc, command.requestID, command.commandID)); } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo = default(CommandInfo); int overload; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; if (!cmdInfo.DoAsync) { try { Notifications notification = null; if (cmdInfo.DsClearedId != -1) { notification = new Notifications(clientManager.ClientID, -1, -1, -1, -1, cmdInfo.DsClearedId , Runtime.Events.EventDataFilter.None, Runtime.Events.EventDataFilter.None); //DataFilter not required } OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.WriteThruProviderName, cmdInfo.providerName); CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress); nCache.Cache.Clear(cmdInfo.FlagMap, notification, operationContext); stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.ClearResponse clearResponse = new Alachisoft.NCache.Common.Protobuf.ClearResponse(); if (clientManager.ClientVersion >= 5000) { ResponseHelper.SetResponse(clearResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(clearResponse, Common.Protobuf.Response.Type.CLEAR)); } else { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.clearResponse = clearResponse; ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.CLEAR); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { //PROTOBUF:RESPONSE exception = exc.ToString(); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } 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.Clear.ToLower()); log.GenerateClearAPILogItem(cmdInfo.FlagMap, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } } else { OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.WriteThruProviderName, cmdInfo.providerName); nCache.Cache.ClearAsync(cmdInfo.FlagMap, new Notifications(clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), -1, -1, 0, cmdInfo.DsClearedId, EventDataFilter.None, EventDataFilter.None) , operationContext); stopWatch.Stop(); TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.ClearAsync.ToLower()); log.GenerateClearAsyncAPILogItem(cmdInfo.FlagMap, cmdInfo.DsClearedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } } finally { cmdInfo.FlagMap?.MarkFree(NCModulesConstants.SocketServer); } }
//PROTOBUF abstract public void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command);
//PROTOBUF private CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager) { return(new CommandInfo()); }