public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { long requestId; string taskId; Common.Protobuf.TaskProgressCommand taskProgressCommand = command.TaskProgressCommand; taskId = taskProgressCommand.taskId; requestId = command.requestID; try { ICommandExecuter tmpVar = clientManager.CmdExecuter; NCache nCache = (NCache)((tmpVar is NCache) ? tmpVar : null); Runtime.MapReduce.TaskStatus taskStatus = nCache.Cache.TaskStatus(taskId); Common.Protobuf.Response reponse = new Common.Protobuf.Response(); reponse.requestId = requestId; reponse.TaskProgressResponse = new Common.Protobuf.TaskProgressResponse(); reponse.TaskProgressResponse.progresses = Serialization.Formatters.CompactBinaryFormatter.ToByteBuffer(taskStatus, nCache.Cache.Name); reponse.responseType = Common.Protobuf.Response.Type.TASK_PROGRESS; reponse.commandID = command.commandID; _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(reponse)); } catch (Exception ex) { _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, command.requestID, command.commandID)); } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { // int overload; string exception = null; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); long messageCount = 0; try { NCache nCache = clientManager.CmdExecuter as NCache; if (nCache != null) { messageCount = nCache.Cache.GetMessageCount(command.messageCountCommand.topicName); _operationSuccessStatus = true; } stopwatch.Stop(); Common.Protobuf.MessageCountResponse messageCountResponse = new Common.Protobuf.MessageCountResponse(); messageCountResponse.messageCount = messageCount; if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(messageCountResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(messageCountResponse, Common.Protobuf.Response.Type.MESSAGE_COUNT)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.messageCountResponse = messageCountResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.MESSAGE_COUNT); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception e) { exception = e.ToString(); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeExceptionResponseWithType(e, command.requestID, command.commandID, clientManager.ClientVersion)); } finally { TimeSpan executionTime = stopwatch.Elapsed; try { if (Management.APILogging.APILogManager.APILogManger != null && Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.MessageCount.ToLower()); log.GenerateCacheCountAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), messageCount); } } catch { } } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int overload; string exception = null; System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); try { if (clientManager != null) { clientManager._leftGracefully = true; NCache nCache = clientManager.CmdExecuter as NCache; if (nCache != null) { nCache.Dispose(); } stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.DisposeResponse disposeResponse = new Alachisoft.NCache.Common.Protobuf.DisposeResponse(); if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(disposeResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(disposeResponse, Common.Protobuf.Response.Type.DISPOSE)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.disposeResponse = disposeResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.DISPOSE); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } } catch (Exception ex) { exception = ex.ToString(); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.Dispose.ToLower()); log.GenerateDisposeAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); // Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); int overload = 1; string exceptionMessage = null; bool result = false; try { NCache nCache = clientManager.CmdExecuter as NCache; var operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); if (command.commandVersion < 1) { operationContext.Add(OperationContextFieldName.ClientLastViewId, forcedViewId); } else { operationContext.Add(OperationContextFieldName.ClientLastViewId, command.clientLastViewId.ToString(CultureInfo.InvariantCulture)); } if (nCache != null) { _command = command.removeTopicCommand; TopicOperation topicOperation = new TopicOperation(_command.topicName, TopicOperationType.Remove); result = nCache.Cache.TopicOpertion(topicOperation, operationContext); Common.Protobuf.Response response = new Common.Protobuf.Response(); Common.Protobuf.RemoveTopicResponse removeTopicResponse = new Common.Protobuf.RemoveTopicResponse(); response.requestId = _command.requestId; response.commandID = command.commandID; removeTopicResponse.success = result; response.responseType = Common.Protobuf.Response.Type.REMOVE_TOPIC; response.removeTopicResponse = removeTopicResponse; _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { exceptionMessage = exc.ToString(); _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.DeleteTopic); log.GenerateGetCreateOrDeleteTopicAPILogItem(_command.topicName, executionTime, clientManager.ClientID, clientManager.ClientIP, overload, result, exceptionMessage); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { short callbackId; string taskId; int overload; string exception = null; System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); try { NCache nCache = clientManager.CmdExecuter as NCache; stopWatch.Start(); IEnumerable <ClientInfo> connectedClients = nCache.Cache.GetConnectedClientInfos(); Common.Protobuf.GetConnectedClientsResponse clientsResponse = new Common.Protobuf.GetConnectedClientsResponse(); Common.Protobuf.Response response = new Common.Protobuf.Response(); response.getConnectedClientsResponse = clientsResponse; response.requestId = command.getConnectedClientsCommand.requestId; response.commandID = command.commandID; response.responseType = Response.Type.GET_CONNECTED_CLIENTS; if (connectedClients != null) { foreach (var connectedClient in connectedClients) { clientsResponse.connectedClients.Add(new Common.Protobuf.ClientInfo { clientId = connectedClient.ClientID, processId = connectedClient.ProcessID, appName = connectedClient.AppName, ipAddress = connectedClient.IPAddress.ToString(), machineName = connectedClient.MachineName }); } } stopWatch.Stop(); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.GetConnectedClientList.ToLower()); log.GenerateGetConnectedClientsAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { string exception = null; int overload; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } try { NCache nCache = clientManager.CmdExecuter as NCache; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); nCache.Cache.Touch(cmdInfo.Keys, operationContext); stopWatch.Stop(); Common.Protobuf.Response response = new Common.Protobuf.Response(); Common.Protobuf.TouchResponse touchResponse = new Common.Protobuf.TouchResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Common.Protobuf.Response.Type.TOUCH; response.touchResponse = touchResponse; _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { exception = exc.ToString(); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Management.APILogging.APILogManager.APILogManger != null && Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.Touch.ToLower()); log.GenerateTouchCommandAPILogItem(cmdInfo.Keys.Count, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { long requestId; int overload; string exception = null; System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); requestId = command.requestID; try { ICommandExecuter tmpVar = clientManager.CmdExecuter; NCache nCache = (NCache)((tmpVar is NCache) ? tmpVar : null); // the Actual Call. ArrayList runningTasks = nCache.Cache.RunningTasks; // Build response Common.Protobuf.Response reponse = new Common.Protobuf.Response(); reponse.requestId = requestId; reponse.commandID = command.commandID; reponse.RunningTasksResponse = new Common.Protobuf.GetRunningTasksResponse(); List <string> list = new List <string>(runningTasks.Count); foreach (string inst in runningTasks) { list.Add(inst); } reponse.RunningTasksResponse.runningTasks.AddRange(list); reponse.responseType = Common.Protobuf.Response.Type.RUNNING_TASKS; _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(reponse)); } catch (Exception ex) { exception = ex.ToString(); _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, 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.GetRunningTasks.ToLower()); log.GenerateGetRunningTasksAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { long requestId; short callbackId; string taskId; string exception = null; System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); Common.Protobuf.TaskCallbackCommand taskCallbackCommand = command.TaskCallbackCommand; requestId = command.requestID; callbackId = (short)taskCallbackCommand.callbackId; taskId = taskCallbackCommand.taskId; try { stopWatch.Start(); ICommandExecuter tempVar = clientManager.CmdExecuter; NCache nCache = (NCache)((tempVar is NCache) ? tempVar : null); nCache.Cache.RegisterTaskNotificationCallback(taskId, new TaskCallbackInfo(clientManager.ClientID, callbackId), new Caching.OperationContext()); stopWatch.Stop(); Common.Protobuf.Response reponse = new Common.Protobuf.Response(); reponse.requestId = requestId; reponse.commandID = command.commandID; Common.Protobuf.TaskCallbackResponse taskCallbackResp = new Common.Protobuf.TaskCallbackResponse(); reponse.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.TASK_CALLBACK; reponse.TaskCallbackResponse = taskCallbackResp; _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(reponse)); } catch (Exception ex) { exception = exception.ToString(); _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, 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.GetTaskResult.ToLower()); log.GenerateGetTaskResultAPILogItem(taskId.ToString(), 1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } try { Alachisoft.NCache.Common.ProductVersion _currentVersion = Alachisoft.NCache.Common.ProductVersion.ProductInfo; Alachisoft.NCache.Common.Protobuf.GetProductVersionResponse getProductVersionResponse = new Alachisoft.NCache.Common.Protobuf.GetProductVersionResponse(); getProductVersionResponse.productVersion.AddiotionalData = _currentVersion.AdditionalData; getProductVersionResponse.productVersion.EditionID = _currentVersion.EditionID; getProductVersionResponse.productVersion.MajorVersion1 = this.ParseToByteArray(_currentVersion.MajorVersion1); getProductVersionResponse.productVersion.MajorVersion2 = this.ParseToByteArray(_currentVersion.MajorVersion2); getProductVersionResponse.productVersion.MinorVersion1 = this.ParseToByteArray(_currentVersion.MinorVersion1); getProductVersionResponse.productVersion.MinorVersion2 = this.ParseToByteArray(_currentVersion.MinorVersion2); getProductVersionResponse.productVersion.ProductName = _currentVersion.ProductName; if (clientManager.ClientVersion >= 5000) { ResponseHelper.SetResponse(getProductVersionResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(getProductVersionResponse, Common.Protobuf.Response.Type.GET_PRODUCT_VERSION)); } else { Common.Protobuf.Response response = new Common.Protobuf.Response(); response.getProductVersionResponse = getProductVersionResponse; ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.GET_PRODUCT_VERSION); _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)); } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { //_commandBytes = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); //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); nCache.Cache.RegisterPollingNotification(cmdInfo.PollingCallbackId, context); //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.RegisterPollNotifResponse registerNotifResponse = new Alachisoft.NCache.Common.Protobuf.RegisterPollNotifResponse(); if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(registerNotifResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(registerNotifResponse, Common.Protobuf.Response.Type.REGISTER_POLL_NOTIF)); } else { Common.Protobuf.Response response = new Common.Protobuf.Response(); response.registerPollNotifResponse = registerNotifResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.REGISTER_POLL_NOTIF); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } }
public void Process() { ClientManager clientManager = null; lock (ConnectionManager.ConnectionTable) clientManager = (ClientManager)ConnectionManager.ConnectionTable[_clientId]; if (clientManager != null) { Common.Protobuf.Response response = new Common.Protobuf.Response(); response.pollNotifyEventResponse = new Common.Protobuf.PollNotifyEventResponse(); response.pollNotifyEventResponse.callbackId = _callbackId; response.pollNotifyEventResponse.eventType = (int)_eventType; response.responseType = Common.Protobuf.Response.Type.POLL_NOTIFY_CALLBACK; IList serializedResponse = Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.POLL_NOTIFY_CALLBACK); ConnectionManager.AssureSend(clientManager, serializedResponse, false); } }
public void Process() { ClientManager clientManager = null; lock (ConnectionManager.ConnectionTable) clientManager = (ClientManager)ConnectionManager.ConnectionTable[_clientID]; if (clientManager != null) { Common.Protobuf.Response response = new Common.Protobuf.Response(); response.itemRemovedCallback = Util.EventHelper.GetItemRemovedCallbackResponse(_eventContext, _id, _key, _value, _flag, _reason, _dataFilter); response.responseType = Common.Protobuf.Response.Type.ITEM_REMOVED_CALLBACK; byte[] serializedResponse = Common.Util.ResponseHelper.SerializeResponse(response); ConnectionManager.AssureSend(clientManager, serializedResponse, Alachisoft.NCache.Common.Enum.Priority.Low); } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { #if !DEVELOPMENT try { ServerMapping serverMapping = Management.MappingConfiguration.MappingConfigurationManager.GetMappingConfiguration().ClientIPMapping; Mapping[] mappedServers = serverMapping.MappingServers; Common.Protobuf.Response response = new Common.Protobuf.Response(); Common.Protobuf.GetServerMappingResponse getServerMappingResponse = new Common.Protobuf.GetServerMappingResponse(); if (mappedServers != null) { for (int i = 0; i < mappedServers.Length; i++) { Common.Protobuf.ServerMapping mappingObject = new Common.Protobuf.ServerMapping(); //Map the server list to protobuf object mappingObject.privateIp = mappedServers[i].PrivateIP; mappingObject.privatePort = mappedServers[i].PrivatePort; mappingObject.publicIp = mappedServers[i].PublicIP; mappingObject.publicPort = mappedServers[i].PublicPort; //Adding to list to be sent as a response getServerMappingResponse.serverMapping.Add(mappingObject); } } else { SocketServer.Logger.NCacheLog.Error("Server Mapping is null"); } response.getServerMappingResponse = getServerMappingResponse; response.responseType = Common.Protobuf.Response.Type.GET_SERVER_MAPPING; response.requestId = command.requestID; response.commandID = command.commandID; _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithoutType(exc, command.requestID, command.commandID)); } #endif }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { long requestId; string taskId; short callbackId; long clientLastViewId; Common.Protobuf.TaskEnumeratorCommand taskEnumeratorCommand = command.TaskEnumeratorCommand; taskId = taskEnumeratorCommand.TaskId; requestId = command.requestID; callbackId = (short)taskEnumeratorCommand.CallbackId; clientLastViewId = command.clientLastViewId; try { ICommandExecuter tempVar = clientManager.CmdExecuter; NCache nCache = (NCache)((tempVar is NCache) ? tempVar : null); OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.ClientLastViewId, clientLastViewId); List <Common.MapReduce.TaskEnumeratorResult> enumerators = nCache.Cache.GetTaskEnumerator(new Common.MapReduce.TaskEnumeratorPointer( clientManager.ClientID, taskId, callbackId), operationContext); Common.Protobuf.Response reponse = new Common.Protobuf.Response(); reponse.requestId = requestId; reponse.commandID = command.commandID; Common.Protobuf.TaskEnumeratorResponse taskEnumResponse = new Common.Protobuf.TaskEnumeratorResponse(); foreach (Common.MapReduce.TaskEnumeratorResult rslt in enumerators) { taskEnumResponse.TaskEnumeratorResult.Add(Serialization.Formatters.CompactBinaryFormatter.ToByteBuffer(rslt, nCache.Cache.Name)); } reponse.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.TASK_ENUMERATOR; reponse.TaskEnumeratorResponse = taskEnumResponse; _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(reponse)); } catch (Exception ex) { _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, command.requestID, command.commandID)); } }
public static void BuildExecuteReaderResponse(ClusteredList <ReaderResultSet> resultSetList, string RequestId, IList <byte[]> _serializedResponse) { if (resultSetList == null) { return; } long requestId = Convert.ToInt64(RequestId); int sequenceId = 1; Common.Protobuf.Response response = new Common.Protobuf.Response(); response.requestId = requestId; response.responseType = Common.Protobuf.Response.Type.EXECUTE_READER; ClusteredArrayList responseChunks = new ClusteredArrayList(); foreach (ReaderResultSet resultSet in resultSetList) { if (resultSet != null) { responseChunks.AddRange(ToProtobufReaderResultSet(resultSet)); } } if (responseChunks != null && responseChunks.Count > 0) { foreach (Common.Protobuf.ReaderResultSet readerResult in responseChunks) { response.sequenceId = sequenceId++; response.numberOfChuncks = responseChunks.Count; Common.Protobuf.ExecuteReaderResponse executeReaderResponse = new Common.Protobuf.ExecuteReaderResponse(); executeReaderResponse.readerResultSets.Add(readerResult); response.executeReaderResponse = executeReaderResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } else { Alachisoft.NCache.Common.Protobuf.ExecuteReaderResponse executeReaderResponse = new Common.Protobuf.ExecuteReaderResponse(); response.executeReaderResponse = executeReaderResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { string taskId = null; long requestId; try { Common.Protobuf.TaskCancelCommand comm = command.TaskCancelCommand; if (comm.taskId != null || !string.IsNullOrEmpty(comm.taskId)) { taskId = comm.taskId; } requestId = command.requestID; } catch (Exception ex) { if (base.immatureId != "-2") { _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, command.requestID, command.commandID)); } return; } try { ICommandExecuter tmpVar = clientManager.CmdExecuter; NCache nCache = (NCache)((tmpVar is NCache) ? tmpVar : null); nCache.Cache.CancelTask(taskId); Common.Protobuf.Response reponse = new Common.Protobuf.Response(); reponse.requestId = requestId; reponse.commandID = command.commandID; reponse.TaskCallbackResponse = new Common.Protobuf.TaskCallbackResponse(); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(reponse)); } catch (Exception ex) { _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, command.requestID, command.commandID)); } }
public void Process() { ClientManager clientManager = null; lock (ConnectionManager.ConnectionTable) clientManager = (ClientManager)ConnectionManager.ConnectionTable[_clientId]; if (clientManager != null) { Common.Protobuf.Response response = new Common.Protobuf.Response(); Common.Protobuf.OperationModeChangeEventResponse operationModeResponse = new Common.Protobuf.OperationModeChangeEventResponse(); operationModeResponse.serverIP = clientManager.ClientIP.ToString(); response.operationModeChangeEventResponse = operationModeResponse; response.responseType = Common.Protobuf.Response.Type.OPERATIONCHANGEDEVNET; IList serializedResponse = Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.OPERATIONCHANGEDEVNET); ConnectionManager.AssureSend(clientManager, serializedResponse, false); } }
public object Dequeue() { object eventItem; QueuedItem item; Alachisoft.NCache.Common.Protobuf.Response response = null; Alachisoft.NCache.Common.Protobuf.BulkEventResponse bulkEvent = new Common.Protobuf.BulkEventResponse(); lock (this) { item = new QueuedItem(); for (int i = 1; i <= _eventBulkCount && _queue.Count > 0; i++) { eventItem = null; { eventItem = _queue.Dequeue(); item.Count = i; } if (eventItem == null) { break; } bulkEvent.eventList.Add((Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse)eventItem); } if (bulkEvent.eventList.Count > 0) { response = new Common.Protobuf.Response(); response.bulkEventResponse = bulkEvent; response.responseType = Common.Protobuf.Response.Type.BULK_EVENT; } item.Item = (object)response; return(item); } }
public object Dequeue() { object eventItem; QueuedItem item; Alachisoft.NCache.Common.Protobuf.Response response = null; Alachisoft.NCache.Common.Protobuf.BulkEventResponse bulkEvent = new Common.Protobuf.BulkEventResponse(); lock (this) { item = new QueuedItem(); for (int i = 1; i <= _eventBulkCount && _queue.Count>0 ; i++) { eventItem = null; { eventItem = _queue.Dequeue(); item.Count = i; } if (eventItem == null) break; bulkEvent.eventList.Add((Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse)eventItem); } if (bulkEvent.eventList.Count > 0) { response = new Common.Protobuf.Response(); response.bulkEventResponse = bulkEvent; response.responseType = Common.Protobuf.Response.Type.BULK_EVENT; } item.Item = (object)response; return item; } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { #if !DEVELOPMENT try { int bucketSize = 0; byte[] buffer = new byte[0]; NCache nCache = clientManager.CmdExecuter as NCache; NewHashmap hashmap = nCache.Cache.GetOwnerHashMap(out bucketSize); Common.Protobuf.Response response = new Common.Protobuf.Response(); Common.Protobuf.GetHashmapResponse getHashmapResponse = new Common.Protobuf.GetHashmapResponse(); response.responseType = Common.Protobuf.Response.Type.GET_HASHMAP; response.getHashmap = getHashmapResponse; response.requestId = command.requestID; response.commandID = command.commandID; if (hashmap != null) { getHashmapResponse.viewId = hashmap.LastViewId; getHashmapResponse.bucketSize = bucketSize; foreach (string member in hashmap.Members) { getHashmapResponse.members.Add(member); } foreach (DictionaryEntry entry in hashmap.Map) { Common.Protobuf.KeyValuePair keyValue = new Common.Protobuf.KeyValuePair(); keyValue.key = entry.Key.ToString(); keyValue.value = entry.Value.ToString(); //nCache.Cache.NCacheLog.CriticalInfo("GetHashmapCommand", string.Format("Bucket id : {0} , Server : {1}", keyValue.key, keyValue.value)); getHashmapResponse.keyValuePair.Add(keyValue); } } if (clientManager.ClientVersion >= 5000) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.GET_HASHMAP)); } else { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("GetHashmapCommand.Execute", clientManager.ClientSocket.RemoteEndPoint.ToString() + " : " + exc.ToString()); } //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc)); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } #endif }
public static IList BuildResponse(List <Event> events, string requestId, IList serializedResponse, string clientId, int commandID, Caching.Cache cache, ClientManager clientManager) { long requestID = Convert.ToInt64(requestId); // Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.SyncEventsResponse syncEventResponse = new Alachisoft.NCache.Common.Protobuf.SyncEventsResponse(); foreach (Event evt in events) { Alachisoft.NCache.Common.Protobuf.EventInfo evtInfo = new Alachisoft.NCache.Common.Protobuf.EventInfo(); evtInfo.eventId = new Common.Protobuf.EventId(); evtInfo.eventId.eventUniqueId = evt.PersistedEventId.EventUniqueID; evtInfo.eventId.eventCounter = evt.PersistedEventId.EventCounter; evtInfo.eventId.operationCounter = evt.PersistedEventId.OperationCounter; switch (evt.PersistedEventId.EventType) { case EventType.CACHE_CLEARED_EVENT: evtInfo.eventType = Alachisoft.NCache.Common.Protobuf.EventInfo.EventType.CACHE_CLEARED_EVENT; break; case EventType.ITEM_ADDED_EVENT: evtInfo.key = evt.PersistedEventInfo.Key; evtInfo.eventType = Alachisoft.NCache.Common.Protobuf.EventInfo.EventType.ITEM_ADDED_EVENT; break; case EventType.ITEM_REMOVED_CALLBACK: evtInfo.key = evt.PersistedEventInfo.Key; evtInfo.flag = evt.PersistedEventInfo.Flag.Data; foreach (CallbackInfo cbInfo in evt.PersistedEventInfo.CallBackInfoList) { if (cbInfo.Client.Equals(clientId)) { evtInfo.callbackId = (short)cbInfo.Callback; } } evtInfo.value.AddRange((List <byte[]>)evt.PersistedEventInfo.Value); evtInfo.itemRemoveReason = (int)evt.PersistedEventInfo.Reason; evtInfo.eventType = Alachisoft.NCache.Common.Protobuf.EventInfo.EventType.ITEM_REMOVED_CALLBACK; break; case EventType.ITEM_REMOVED_EVENT: evtInfo.key = evt.PersistedEventInfo.Key; evtInfo.eventType = Alachisoft.NCache.Common.Protobuf.EventInfo.EventType.ITEM_REMOVED_EVENT; break; case EventType.ITEM_UPDATED_CALLBACK: evtInfo.key = evt.PersistedEventInfo.Key; foreach (CallbackInfo cbInfo in evt.PersistedEventInfo.CallBackInfoList) { if (cbInfo.Client.Equals(clientId)) { evtInfo.callbackId = (short)cbInfo.Callback; } } evtInfo.eventType = Alachisoft.NCache.Common.Protobuf.EventInfo.EventType.ITEM_UPDATED_CALLBACK; break; case EventType.ITEM_UPDATED_EVENT: evtInfo.key = evt.PersistedEventInfo.Key; evtInfo.eventType = Alachisoft.NCache.Common.Protobuf.EventInfo.EventType.ITEM_UPDATED_EVENT; break; } if (clientManager.ClientVersion >= 5000) { syncEventResponse.eventInfo.Add(evtInfo); Common.Util.ResponseHelper.SetResponse(syncEventResponse, requestID, commandID); serializedResponse.Add(Common.Util.ResponseHelper.SerializeResponse(syncEventResponse, Common.Protobuf.Response.Type.SYNC_EVENTS)); } else { Common.Protobuf.Response response = new Common.Protobuf.Response(); response.syncEventsResponse.eventInfo.Add(evtInfo); response.syncEventsResponse = syncEventResponse; Common.Util.ResponseHelper.SetResponse(response, requestID, commandID, Common.Protobuf.Response.Type.SYNC_EVENTS); serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } //response.syncEventsResponse.eventInfo.Add(evtInfo); } //serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response,Common.Protobuf.Response.Type.SYNC_EVENTS)); return(serializedResponse); }
//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(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("UnlockCmd.Exec", "cmd parsed"); } } catch (ArgumentOutOfRangeException arEx) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("UnlockCommand", "command: " + command + " Error" + arEx); } _unlockResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(arEx, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } catch (Exception exc) { _unlockResult = 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; } try { NCache nCache = clientManager.CmdExecuter as NCache; var operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress); nCache.Cache.Unlock(cmdInfo.Key, cmdInfo.lockId, cmdInfo.isPreemptive, operationContext); stopWatch.Stop(); //PROTOBUF:RESPONSE // Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.UnlockResponse unlockResponse = new Alachisoft.NCache.Common.Protobuf.UnlockResponse(); if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(unlockResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(unlockResponse, Common.Protobuf.Response.Type.UNLOCK)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.unlockResponse = unlockResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.UNLOCK); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { exception = exc.ToString(); _unlockResult = OperationResult.Failure; _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.Unlock.ToLower()); log.GeneratUnlockAPILogItem(cmdInfo.Key, cmdInfo.lockId != null?cmdInfo.lockId.ToString() :null, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("UnlockCmd.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")) { //_commandBytes = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); //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; 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,Common.Protobuf.Response.Type.UNREGISTER_KEY_NOTIF)); //_commandBytes = clientManager.ReplyPacket("UNREGKEYNOTIFRESULT \"" + cmdInfo.RequestId + "\"", new byte[0]); if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(unregisterKeyNotifResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(unregisterKeyNotifResponse, Common.Protobuf.Response.Type.UNREGISTER_KEY_NOTIF)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.unregisterKeyNotifResponse = unregisterKeyNotifResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.UNREGISTER_KEY_NOTIF); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { exception = exc.ToString(); //_commandBytes = clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc)); //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.UnRegisterKeyNotificationCallback.ToLower()); log.GenerateKeyNotificationCallback(1, cmdInfo.UpdateCallbackId, cmdInfo.RemoveCallbackId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); // Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo); } } catch { } } }
internal Alachisoft.NCache.Common.Protobuf.Response GetEvents(out bool hasMessages) { object eventItem; try { bool removeMessageFromQueue = false; if (_eventsQueue.Count > _eventBulkCount) { removeMessageFromQueue = true; } else { if ((DateTime.Now - _lastEventCollectionTime).TotalMilliseconds > _bulkEventCollectionInterval) { removeMessageFromQueue = true; } } if (removeMessageFromQueue) { if (_eventsQueue.Count > 0) { Alachisoft.NCache.Common.Protobuf.Response response = null; Alachisoft.NCache.Common.Protobuf.BulkEventResponse bulkEvent = new Common.Protobuf.BulkEventResponse(); for (int i = 0; i < _eventBulkCount; i++) { eventItem = null; lock (_eventsQueue) { if (_eventsQueue.Count > 0) { eventItem = _eventsQueue.Dequeue(); if (SocketServer.IsServerCounterEnabled) _connectionManager.PerfStatsColl.DecrementEventQueueCountStats(); } } if (eventItem == null) break; bulkEvent.eventList.Add((Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse)eventItem); } if (bulkEvent.eventList.Count > 0) { _lastEventCollectionTime = DateTime.Now; response = new Common.Protobuf.Response(); response.bulkEventResponse = bulkEvent; response.responseType = Common.Protobuf.Response.Type.BULK_EVENT; } hasMessages = _eventsQueue.Count > _eventBulkCount; return response; } } } catch (Exception ex) { if (SocketServer.IsServerCounterEnabled) SocketServer.Logger.NCacheLog.Error("ClientManager.GetEvents", ex.ToString()); } hasMessages = _eventsQueue.Count > _eventBulkCount; return null; }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); int overload = 1; bool isTopicCreated = false; string exceptionMessage = null; try { NCache nCache = clientManager.CmdExecuter as NCache; var operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); if (command.commandVersion < 1) { operationContext.Add(OperationContextFieldName.ClientLastViewId, forcedViewId); } else //NCache 4.1 SP1 or later { operationContext.Add(OperationContextFieldName.ClientLastViewId, command.clientLastViewId.ToString(CultureInfo.InvariantCulture)); } if (nCache != null) { Common.Protobuf.GetTopicCommand getTopicCommand = command.getTopicCommand; _command = getTopicCommand; TopicOperation topicOperation = new TopicOperation(getTopicCommand.topicName, (TopicOperationType)getTopicCommand.type); isTopicCreated = nCache.Cache.TopicOpertion(topicOperation, operationContext); stopWatch.Stop(); Common.Protobuf.Response response = new Common.Protobuf.Response(); Common.Protobuf.GetTopicResponse getTopicResponse = new Common.Protobuf.GetTopicResponse(); getTopicResponse.success = isTopicCreated; if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(getTopicResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(getTopicResponse, Common.Protobuf.Response.Type.GET_TOPIC)); } else { //PROTOBUF:RESPONSE response.getTopicResponse = getTopicResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.GET_TOPIC); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } } catch (Exception exc) { exceptionMessage = exc.ToString(); _serializedResponsePackets.Add(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 methodName = null; if ((TopicOperationType)_command.type == TopicOperationType.Get) { methodName = MethodsName.GetTopic; } else { methodName = MethodsName.CreateTopic; } APILogItemBuilder log = new APILogItemBuilder(methodName); log.GenerateGetCreateOrDeleteTopicAPILogItem(_command.topicName, executionTime, clientManager.ClientID, clientManager.ClientIP, overload, isTopicCreated, exceptionMessage); // Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo); } } catch { } } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (ArgumentOutOfRangeException arEx) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("IsLockedCommand", "command: " + command + " Error" + arEx); } if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(arEx, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } 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; object lockId = cmdInfo.LockId; DateTime lockDate = new DateTime(); bool res = nCache.Cache.IsLocked(cmdInfo.Key, ref lockId, ref lockDate, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.IsLockedResponse isLockedResponse = new Alachisoft.NCache.Common.Protobuf.IsLockedResponse(); isLockedResponse.isLocked = res; isLockedResponse.lockId = lockId != null?lockId.ToString() : cmdInfo.LockId.ToString(); isLockedResponse.lockTime = lockDate != null ? lockDate.Ticks : new DateTime().Ticks; if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(isLockedResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(isLockedResponse, Common.Protobuf.Response.Type.ISLOCKED)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.isLockedResponse = isLockedResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.ISLOCKED); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } }
internal Alachisoft.NCache.Common.Protobuf.Response GetEvents(out bool hasMessages) { object eventItem; try { bool removeMessageFromQueue = false; if (_eventsQueue.Count > ServiceConfiguration.EventBulkCount) { removeMessageFromQueue = true; } else { if ((DateTime.Now - _lastEventCollectionTime).TotalMilliseconds > ServiceConfiguration.BulkEventCollectionInterval) { removeMessageFromQueue = true; } } if (removeMessageFromQueue) { if (_eventsQueue.Count > 0) { Alachisoft.NCache.Common.Protobuf.Response response = null; Alachisoft.NCache.Common.Protobuf.BulkEventResponse bulkEvent = new Common.Protobuf.BulkEventResponse(); for (int i = 0; i < ServiceConfiguration.EventBulkCount; i++) { eventItem = null; lock (_eventsQueue) { if (_eventsQueue.Count > 0) { eventItem = _eventsQueue.Dequeue(); if (SocketServer.IsServerCounterEnabled) { _connectionManager.PerfStatsColl.DecrementEventQueueCountStats(); } } } if (eventItem == null) { break; } bulkEvent.eventList.Add((Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse)eventItem); } if (bulkEvent.eventList.Count > 0) { _lastEventCollectionTime = DateTime.Now; response = new Common.Protobuf.Response(); response.bulkEventResponse = bulkEvent; response.responseType = Common.Protobuf.Response.Type.BULK_EVENT; } hasMessages = _eventsQueue.Count > ServiceConfiguration.EventBulkCount; return(response); } } } catch (Exception ex) { if (SocketServer.IsServerCounterEnabled) { SocketServer.Logger.NCacheLog.Error("ClientManager.GetEvents", ex.ToString()); } } hasMessages = _eventsQueue.Count > ServiceConfiguration.EventBulkCount; return(null); }
//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")) { //_commandBytes = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } 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(clientManager.ClientID, cmdInfo.UpdateCallbackId, datafilter, callbackType); cbRemove = new CallbackInfo(clientManager.ClientID, cmdInfo.RemoveCallbackId, datafilter, cmdInfo.NotifyOnExpiration, callbackType); } else { cbUpdate = new CallbackInfo(clientManager.ClientID, cmdInfo.UpdateCallbackId, EventDataFilter.None, callbackType); cbRemove = new CallbackInfo(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, clientManager.ClientID); if (command.commandVersion < 1) { context.Add(OperationContextFieldName.ClientLastViewId, forcedViewId); } else //NCache 4.1 SP1 or later { context.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.clientLastViewId.ToString(CultureInfo.InvariantCulture)); } nCache.Cache.RegisterKeyNotificationCallback(cmdInfo.Key, cbUpdate, cbRemove , context); stopWatch.Stop(); if (clientManager.ClientVersion < 5000 && !clientManager.CreateEventSubscription) { Util.EventHelper.SubscribeEvents(clientManager.ClientID, TopicConstant.ItemLevelEventsTopic, nCache, context); clientManager.CreateEventSubscription = true; } //PROTOBUF:RESPONSE // Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.RegisterKeyNotifResponse registerKeyNotifResponse = new Alachisoft.NCache.Common.Protobuf.RegisterKeyNotifResponse(); //response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.REGISTER_KEY_NOTIF; //response.registerKeyNotifResponse = registerKeyNotifResponse; //response.requestId = command.registerKeyNotifCommand.requestId; //response.commandID = command.commandID; //_serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response,Common.Protobuf.Response.Type.REGISTER_KEY_NOTIF)); if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(registerKeyNotifResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(registerKeyNotifResponse, Common.Protobuf.Response.Type.REGISTER_KEY_NOTIF)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.registerKeyNotifResponse = registerKeyNotifResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.REGISTER_KEY_NOTIF); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } //_commandBytes = clientManager.ReplyPacket("REGKEYNOTIFRESULT \"" + cmdInfo.RequestId + "\"", new byte[0]); } catch (Exception exc) { exception = exc.ToString(); //_commandBytes = clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc)); //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(1, cmdInfo.UpdateCallbackId, cmdInfo.RemoveCallbackId, 1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); // Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo); } } 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; CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress); 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, Common.Protobuf.Command command) { CommandInfo cmdInfo; string exception = null; int updateCount = 0; int removeCount = 0; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { cmdInfo = ParseCommand(command, clientManager); } catch (System.Exception exc) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); return; } try { NCache cmdExecuter = clientManager.CmdExecuter as NCache; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); if (cmdInfo.CommandVersion < 1) { operationContext.Add(OperationContextFieldName.ClientLastViewId, forcedViewId); } else //NCache 4.1 or later { operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); } operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); operationContext.Add(OperationContextFieldName.ClientId, clientManager.ClientID); PollingResult result = cmdExecuter.Cache.Poll(operationContext); stopWatch.Stop(); PollResponse pollResponse = new PollResponse(); pollResponse.removedKeys.AddRange(result.RemovedKeys); pollResponse.updatedKeys.AddRange(result.UpdatedKeys); updateCount = result.UpdatedKeys.Count; removeCount = result.RemovedKeys.Count; if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(pollResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(pollResponse, Common.Protobuf.Response.Type.POLL)); } else { Common.Protobuf.Response response = new Common.Protobuf.Response(); response.pollResponse = pollResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.POLL); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (System.Exception exc) { 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 (Management.APILogging.APILogManager.APILogManger != null && Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.Poll.ToLower()); log.GeneratePollCommandAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), updateCount, removeCount); } } catch { } } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; byte[] data = null; int overload; string exception = null; Stopwatch stopWatch = new 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)); //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); } return; } Alachisoft.NCache.Common.Protobuf.RaiseCustomEventCommand notifcommand = command.raiseCustomEventCommand; try { NCache nCache = clientManager.CmdExecuter as NCache; nCache.Cache.SendNotification(notifcommand.notifIf, notifcommand.data); Alachisoft.NCache.Common.Protobuf.RaiseCustomEventResponse raiseCustomEventResponse = new Alachisoft.NCache.Common.Protobuf.RaiseCustomEventResponse(); if (clientManager.ClientVersion >= 5000) { ResponseHelper.SetResponse(raiseCustomEventResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(raiseCustomEventResponse, Common.Protobuf.Response.Type.RAISE_CUSTOM_EVENT)); } else { Common.Protobuf.Response response = new Common.Protobuf.Response(); response.raiseCustomEventResponse = raiseCustomEventResponse; ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.RAISE_CUSTOM_EVENT); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { exception = exc.ToString(); //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } finally { 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.RaiseCustomEvent.ToLower()); log.GenerateraiseCustomAPILogItem(notifcommand.notifIf.Length, notifcommand.data.Length, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { CommandInfo cmdInfo; NCache nCache = clientManager.CmdExecuter as NCache; //TODO byte[] data = null; try { //cmdInfo = ParseCommand(command, clientManager); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("ContCmd.Exec", "cmd parsed"); } } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } try { //data = new byte[1]; //data[0] = (byte)(nCache.Cache.Contains(cmdInfo.Key) ? 49 : 48); RequestStatus requestStatus; if (command.inquiryRequestCommand.serverIP.Equals(ConnectionManager.ServerIpAddress)) { requestStatus = _bookie.GetRequestStatus(clientManager.ClientID, command.inquiryRequestCommand.inquiryRequestId, command.inquiryRequestCommand.inquiryCommandId); } else { requestStatus = nCache.Cache.GetClientRequestStatus(clientManager.ClientID, command.inquiryRequestCommand.inquiryRequestId, command.inquiryRequestCommand.inquiryCommandId, command.inquiryRequestCommand.serverIP); if (requestStatus == null) { requestStatus = new RequestStatus(Common.Enum.RequestStatus.NODE_DOWN); } } Common.Protobuf.InquiryRequestResponse inquiryResponse = new Common.Protobuf.InquiryRequestResponse(); inquiryResponse.status = requestStatus.Status; if (inquiryResponse.status == Common.Enum.RequestStatus.RECEIVED_AND_EXECUTED) { IList existingResponse = requestStatus.RequestResult; foreach (byte[] extRes in existingResponse) { inquiryResponse.value.Add(extRes); } } inquiryResponse.expirationInterval = _bookie.CleanInterval; if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(inquiryResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(inquiryResponse, Common.Protobuf.Response.Type.INQUIRY_REQUEST_RESPONSE)); } else { Common.Protobuf.Response response = new Common.Protobuf.Response(); response.inquiryRequestResponse = inquiryResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.INQUIRY_REQUEST_RESPONSE); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc)); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("ContCmd.Exec", "cmd executed on cache"); } }