public CommandResponse RecieveCommandResponse(Socket client) { byte[] value = null; CommandResponse cmdRespose = null; try { value = AssureRecieve(client); ///Deserialize the response Alachisoft.NCache.Common.Protobuf.Response response = null; using (MemoryStream stream = new MemoryStream(value)) { response = ProtoBuf.Serializer.Deserialize <Alachisoft.NCache.Common.Protobuf.Response>(stream); stream.Close(); } if (response != null && response.responseType == Alachisoft.NCache.Common.Protobuf.Response.Type.RESPONSE_FRAGMENT) { response = _responseIntegrator.AddResponseFragment(this._serverAddress, response.getResponseFragment); } if (response != null) { cmdRespose = new CommandResponse(false, new Address()); cmdRespose.CacheId = this._cacheId; cmdRespose.Result = response; } } catch (SocketException e) { throw new ConnectionException(e.Message, this._serverAddress.IpAddress, this._serverAddress.Port); } return(cmdRespose); }
public void Process() { object[] package = null; package = (object[])SerializationUtil.CompactDeserialize(_result, _cacheContext); string key = (string)package[0]; AsyncCallbackInfo cbInfo = (AsyncCallbackInfo)package[1]; object opResult = package[2]; ClientManager clientManager = null; lock (ConnectionManager.ConnectionTable) clientManager = (ClientManager)ConnectionManager.ConnectionTable[cbInfo.Client]; if (clientManager != null) { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.requestId = cbInfo.RequestID; response.asyncOpCompletedCallback = Alachisoft.NCache.SocketServer.Util.EventHelper.GetAsyncOpCompletedResponse(clientManager, cbInfo, opResult, _opCode, key); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.ASYNC_OP_COMPLETED_CALLBACK; IList serializedResponse = Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.ASYNC_OP_COMPLETED_CALLBACK); ConnectionManager.AssureSend(clientManager, serializedResponse, false); } }
public static byte[] SerializeExceptionResponse(Exception exc, long requestId) { Alachisoft.NCache.Common.Protobuf.Exception ex = GetExceptionResponse(exc); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.requestId = requestId; response.exception = ex; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION; return(SerializeResponse(response)); }
public static byte[] SerializeExceptionResponse(Exception exc, long requestId) { Alachisoft.NCache.Common.Protobuf.Exception ex = new Alachisoft.NCache.Common.Protobuf.Exception(); ex.message = exc.Message; ex.exception = exc.ToString(); if (exc is InvalidReaderException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.INVALID_READER_EXCEPTION; } else if (exc is OperationFailedException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.OPERATIONFAILED; } else if (exc is Runtime.Exceptions.AggregateException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.AGGREGATE; } else if (exc is ConfigurationException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.CONFIGURATION; } else if (exc is OperationNotSupportedException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.NOTSUPPORTED; } else if (exc is TypeIndexNotDefined) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.TYPE_INDEX_NOT_FOUND; } else if (exc is AttributeIndexNotDefined) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.ATTRIBUTE_INDEX_NOT_FOUND; } else if (exc is StateTransferInProgressException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.STATE_TRANSFER_EXCEPTION; } else { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.GENERALFAILURE; } Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.requestId = requestId; response.exception = ex; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION; return(SerializeResponse(response)); }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager).clone(); } catch (System.Exception exc) { if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponseWithoutType(exc, command.requestID, command.commandID)); } return; } try { if (!CacheProvider.Provider.IsRunning(cmdInfo.CacheId)) { throw new System.Exception("Specified cache is not running."); } int port = 0; #if NETCORE port = CacheProvider.Provider.GetCacheInfo(cmdInfo.CacheId).ManagementPort; #else port = CacheProvider.Provider.Renderer.Port; #endif string bindIP = ServiceConfiguration.BindToIP.ToString(); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); GetCacheManagementPortResponse getCacheManagementPortResponse = new GetCacheManagementPortResponse(); getCacheManagementPortResponse.isRunning = true; getCacheManagementPortResponse.port = port; getCacheManagementPortResponse.server = bindIP; response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_CACHE_MANAGEMENT_PORT; response.getCacheManagementPortResponse = getCacheManagementPortResponse; _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(response)); } catch (System.Exception ex) { _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponseWithoutType(ex, command.requestID, command.commandID)); } }
public static byte[] SerializeResponse(Alachisoft.NCache.Common.Protobuf.Response command) { using (MemoryStream stream = new MemoryStream()) { byte[] size = new byte[10]; stream.Write(size, 0, size.Length); Serializer.Serialize <Alachisoft.NCache.Common.Protobuf.Response>(stream, command); int messageLen = (int)stream.Length - size.Length; size = UTF8Encoding.UTF8.GetBytes(messageLen.ToString()); stream.Position = 0; stream.Write(size, 0, size.Length); byte[] result = stream.ToArray(); stream.Close(); return(result); } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager).clone(); } catch (System.Exception exc) { if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } try { int port = 0; port = ServiceConfiguration.Port; bool isRunning = CacheProvider.Provider.IsRunning(cmdInfo.CacheId); string bindIP = ServiceConfiguration.BindToIP.ToString(); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); GetCacheBindingResponse getCacheBindingResponse = new GetCacheBindingResponse(); getCacheBindingResponse.isRunning = isRunning; getCacheBindingResponse.port = port; getCacheBindingResponse.server = bindIP; response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_CACHE_BINDING; response.getCacheBindingResponse = getCacheBindingResponse; _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(response)); } catch (System.Exception ex) { _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, command.requestID)); } }
public static IList SerializeResponse(Alachisoft.NCache.Common.Protobuf.Response command) { using (ClusteredMemoryStream stream = new ClusteredMemoryStream()) { //TODO byte[] size = new byte[10]; stream.Write(size, 0, size.Length); Serializer.Serialize <Alachisoft.NCache.Common.Protobuf.Response>(stream, command); int messageLen = (int)stream.Length - size.Length; size = UTF8Encoding.UTF8.GetBytes(messageLen.ToString()); stream.Position = 0; stream.Write(size, 0, size.Length); ClusteredArrayList byteList = stream.GetInternalBuffer(); return(byteList); } }
public static byte[] SerializeExceptionResponse(Exception exc, long requestId) { Alachisoft.NCache.Common.Protobuf.Exception ex = GetExceptionResponse(exc); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.requestId = requestId; response.exception = ex; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION; return SerializeResponse(response); }
public static IList SerializeExceptionResponse(Exception exc, long requestId, int commandID) { Alachisoft.NCache.Common.Protobuf.Exception ex = new Alachisoft.NCache.Common.Protobuf.Exception(); ex.message = exc.Message; ex.exception = exc.ToString(); if (exc is InvalidReaderException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.INVALID_READER_EXCEPTION; } else if (exc is OperationFailedException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.OPERATIONFAILED; } else if (exc is Runtime.Exceptions.AggregateException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.AGGREGATE; } else if (exc is ConfigurationException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.CONFIGURATION; } else if (exc is VersionException) { VersionException tempEx = (VersionException)exc; ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.CONFIGURATON_EXCEPTION; ex.errorCode = tempEx.ErrorCode; } else if (exc is OperationNotSupportedException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.NOTSUPPORTED; } else if (exc is StreamAlreadyLockedException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.STREAM_ALREADY_LOCKED; } else if (exc is StreamCloseException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.STREAM_CLOSED; } else if (exc is StreamInvalidLockException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.STREAM_INVALID_LOCK; } else if (exc is StreamNotFoundException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.STREAM_NOT_FOUND; } else if (exc is StreamException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.STREAM_EXC; } else if (exc is TypeIndexNotDefined) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.TYPE_INDEX_NOT_FOUND; } else if (exc is AttributeIndexNotDefined) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.ATTRIBUTE_INDEX_NOT_FOUND; } else if (exc is StateTransferInProgressException) { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.STATE_TRANSFER_EXCEPTION; } else { ex.type = Alachisoft.NCache.Common.Protobuf.Exception.Type.GENERALFAILURE; } Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.requestId = requestId; response.commandID = commandID; response.exception = ex; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION; return(SerializeResponse(response)); }