public EnumerationDataChunk GetNextChunk(Alachisoft.NCache.Common.DataStructures.EnumerationPointer pointer) { int count = 0; EnumerationDataChunk chunk = new EnumerationDataChunk(); chunk.Data = new List <string>(); int currentIndex = pointer.ChunkId; while (currentIndex < _snapshot.Length - 1 && count < ServiceConfiguration.EnumeratorChunkSize) { currentIndex++; chunk.Data.Add(_snapshot.GetValue(currentIndex).ToString()); count++; } if (currentIndex == _snapshot.Length - 1) { _pointer.ChunkId = -1; } else { _pointer.ChunkId = currentIndex; //Set the chunkId to strating index of the next chunk to fetch. } chunk.Pointer = _pointer; return(chunk); }
internal EnumerationDataChunk GetNextChunk(EnumerationPointer pointer) { EnumerationDataChunk nextChunk = null; IEnumerationProvider provider = GetProvider(pointer); if (pointer.isDisposable && provider != null) { provider.Dispose(); if (_index.ContainsKey(pointer)) { _index.Remove(pointer); } nextChunk = new EnumerationDataChunk(); nextChunk.Pointer = pointer; } else if (provider != null) { nextChunk = provider.GetNextChunk(pointer); //Dispose the provider if this is the last chunk for it if (nextChunk.IsLastChunk) { provider.Dispose(); if (_index.ContainsKey(pointer)) { _index.Remove(pointer); } } } return(nextChunk); }
/// <summary> /// Advance the enumerator to the next element of the collection /// </summary> /// <returns></returns> public bool MoveNext() { bool result = false; if (_currentChunkEnumerator != null) { result = _currentChunkEnumerator.MoveNext(); if (!result) { if (_currentChunk != null && !_currentChunk.IsLastChunk) { _currentChunk = _cache.GetNextChunk(_currentChunk.Pointer, new OperationContext()); if (_currentChunk != null && _currentChunk.Data != null) { _currentChunkEnumerator = _currentChunk.Data.GetEnumerator(); result = _currentChunkEnumerator.MoveNext(); } } } } if (result) { _currentValue = _cache.Get(Key); } return(result); }
/// <summary> /// Returns the next enumeration data chunk from the set of chunks returned by multiple nodes /// </summary> /// <param name="results"></param> /// <returns></returns> public static EnumerationDataChunk FindAtomicEnumerationDataChunkReplicated(RspList results) { EnumerationDataChunk nextChunk = null; if (results == null) { return(nextChunk); } for (int i = 0; i < results.size(); i++) { Rsp rsp = (Rsp)results.elementAt(i); if (!rsp.wasReceived() || rsp.wasSuspected()) { continue; } nextChunk = (EnumerationDataChunk)rsp.Value; if (nextChunk != null) { return(nextChunk); } } return(nextChunk); }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; int overload; string exception = null; System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } try { NCache nCache = clientManager.CmdExecuter as NCache; EnumerationDataChunk nextChunk = nCache.Cache.GetNextChunk(cmdInfo.Pointer, cmdInfo.OperationContext); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.GetGroupNextChunkResponse getNextChunkResponse = new Alachisoft.NCache.Common.Protobuf.GetGroupNextChunkResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_GROUP_NEXT_CHUNK; response.getGroupNextChunkResponse = getNextChunkResponse; getNextChunkResponse.keys.AddRange(nextChunk.Data); getNextChunkResponse.groupEnumerationPointer = EnumerationPointerConversionUtil.ConvertToProtobufGroupEnumerationPointer(nextChunk.Pointer as GroupEnumerationPointer); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { exception = exception.ToString(); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.GetGroupNextChunk.ToLower()); log.GenerateGetEnumeratorAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } int count = 0; string keyPackage = null; try { NCache nCache = clientManager.CmdExecuter as NCache; EnumerationDataChunk nextChunk = nCache.Cache.GetNextChunk(cmdInfo.Pointer, cmdInfo.OperationContext); if (!clientManager.EnumerationPointers.ContainsKey(cmdInfo.Pointer.Id)) { clientManager.EnumerationPointers.Add(cmdInfo.Pointer.Id, cmdInfo.Pointer); } else { clientManager.EnumerationPointers[cmdInfo.Pointer.Id] = cmdInfo.Pointer; } Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.GetNextChunkResponse getNextChunkResponse = new Alachisoft.NCache.Common.Protobuf.GetNextChunkResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.intendedRecipient = cmdInfo.OperationContext.GetValueByField(OperationContextFieldName.IntendedRecipient).ToString(); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK; response.getNextChunkResponse = getNextChunkResponse; if (nextChunk.Data != null) { getNextChunkResponse.keys.AddRange(nextChunk.Data); } getNextChunkResponse.enumerationPointer = EnumerationPointerConversionUtil.ConvertToProtobufEnumerationPointer(nextChunk.Pointer); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } }
public override EnumerationDataChunk GetNextChunk(EnumerationPointer pointer, OperationContext operationContext) { if (_enumerationIndex == null) { _enumerationIndex = new EnumerationIndex(this); } EnumerationDataChunk nextChunk = _enumerationIndex.GetNextChunk(pointer); return(nextChunk); }
public void Initialize(string group, string subGroup) { EnumerationPointer pointer = null; if (!String.IsNullOrEmpty(group)) { pointer = new GroupEnumerationPointer(group, subGroup); } else { pointer = new EnumerationPointer(); } _currentChunk = _cache.GetNextChunk(pointer, new OperationContext()); if (_currentChunk != null && _currentChunk.Data != null) { List <string> data = _currentChunk.Data; _currentChunkEnumerator = data.GetEnumerator(); } }
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.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } int count = 0; string keyPackage = null; try { NCache nCache = clientManager.CmdExecuter as NCache; CommandsUtil.PopulateClientIdInContext(ref cmdInfo.OperationContext, clientManager.ClientAddress); 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; } if (clientManager.ClientVersion >= 5000) { Alachisoft.NCache.Common.Protobuf.GetNextChunkResponse getNextChunkResponse = new Alachisoft.NCache.Common.Protobuf.GetNextChunkResponse(); getNextChunkResponse.requestId = Convert.ToInt64(cmdInfo.RequestId); getNextChunkResponse.commandID = command.commandID; getNextChunkResponse.intendedRecipient = cmdInfo.OperationContext.GetValueByField(OperationContextFieldName.IntendedRecipient).ToString(); if (nextChunk.Data != null) { getNextChunkResponse.keys.AddRange(nextChunk.Data); } getNextChunkResponse.enumerationPointer = EnumerationPointerConversionUtil.ConvertToProtobufEnumerationPointer(nextChunk.Pointer); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(getNextChunkResponse, Common.Protobuf.Response.Type.GET_NEXT_CHUNK)); } else { 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 = 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.GetNextChunk.ToLower()); log.GenerateGetEnumeratorAPILogItem(1, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); // Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpirationHint, cmdInfo.queryInfo); } } catch { } } }
internal void MergeResponse(Common.Net.Address address, CommandResponse response) { if (_finalResponse == null && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK) { _finalResponse = response; if (response.IsBrokerReset) { MergeFailedResponse(response); } } else { if (response.IsBrokerReset) { MergeFailedResponse(response); } else { IDictionaryEnumerator ide = null; switch (response.Type) { case Alachisoft.NCache.Common.Protobuf.Response.Type.ADD_BULK: case Alachisoft.NCache.Common.Protobuf.Response.Type.INSERT_BULK: case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_BULK: case Alachisoft.NCache.Common.Protobuf.Response.Type.REMOVE_BULK: ide = response.KeyValueDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyValueDic[ide.Key] = ide.Value; } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH: if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) || (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND)) { _finalResponse = response; break; } switch (response.ResultSet.AggregateFunctionType) { case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE: _finalResponse.KeyList.AddRange(response.KeyList); break; default: if (!_finalResponse.ResultSet.IsInitialized) { SetAggregateFunctionResult(); _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet); } _finalResponse.ResultSet.Compile(response.ResultSet); break; } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES: if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) || (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND)) { _finalResponse = response; break; } switch (response.ResultSet.AggregateFunctionType) { case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE: ide = response.KeyValueDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyValueDic[ide.Key] = ide.Value; } break; default: if (!_finalResponse.ResultSet.IsInitialized) { SetAggregateFunctionResult(); _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet); } _finalResponse.ResultSet.Compile(response.ResultSet); break; } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK: if (_finalResponse == null) { _finalResponse = response; } EnumerationDataChunk chunk = null; if (_chunks.ContainsKey(address)) { chunk = _chunks[address]; } else { chunk = new EnumerationDataChunk(); chunk.Data = new List <string>(); _chunks.Add(address, chunk); } for (int i = 0; i < response.NextChunk.Count; i++) { chunk.Data.AddRange(response.NextChunk[i].Data); chunk.Pointer = response.NextChunk[i].Pointer; if (chunk.Pointer.NodeIpAddress == null) { chunk.Pointer.NodeIpAddress = address; } } _finalResponse.NextChunk = new List <EnumerationDataChunk>(_chunks.Values); break; case Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION: if (response.ExceptionType == Common.Enum.ExceptionType.STATE_TRANSFER_EXCEPTION) { _finalResponse = response; } break; default: break; } } } }
internal void MergeResponse(Common.Net.Address address, CommandResponse response) { if (_finalResponse == null && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.GET_READER_CHUNK && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.EXECUTE_READER) { _finalResponse = response; if (response.IsBrokerReset) { MergeFailedResponse(response); } } else { if (response.IsBrokerReset) { MergeFailedResponse(response); } else { IDictionaryEnumerator ide = null; switch (response.Type) { case Alachisoft.NCache.Common.Protobuf.Response.Type.ADD_BULK: case Alachisoft.NCache.Common.Protobuf.Response.Type.INSERT_BULK: case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_BULK: case Alachisoft.NCache.Common.Protobuf.Response.Type.REMOVE_BULK: ide = response.KeyValueDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyValueDic[ide.Key] = ide.Value; } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH: if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) || (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND)) { _finalResponse = response; break; } switch (response.ResultSet.AggregateFunctionType) { case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE: _finalResponse.KeyList.AddRange(response.KeyList); break; default: if (!_finalResponse.ResultSet.IsInitialized) { SetAggregateFunctionResult(); _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet); } _finalResponse.ResultSet.Compile(response.ResultSet); break; } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES: if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) || (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND)) { _finalResponse = response; break; } switch (response.ResultSet.AggregateFunctionType) { case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE: ide = response.KeyValueDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyValueDic[ide.Key] = ide.Value; } break; default: if (!_finalResponse.ResultSet.IsInitialized) { SetAggregateFunctionResult(); _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet); } _finalResponse.ResultSet.Compile(response.ResultSet); break; } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK: if (_finalResponse == null) { _finalResponse = response; } EnumerationDataChunk chunk = null; if (_chunks.ContainsKey(address)) { chunk = _chunks[address]; } else { chunk = new EnumerationDataChunk(); chunk.Data = new List <string>(); _chunks.Add(address, chunk); } for (int i = 0; i < response.NextChunk.Count; i++) { chunk.Data.AddRange(response.NextChunk[i].Data); chunk.Pointer = response.NextChunk[i].Pointer; if (chunk.Pointer.NodeIpAddress == null) { chunk.Pointer.NodeIpAddress = address; } } _finalResponse.NextChunk = new List <EnumerationDataChunk>(_chunks.Values); break; case Alachisoft.NCache.Common.Protobuf.Response.Type.EXECUTE_READER: if (_finalResponse == null) { _finalResponse = response; } if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) || (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND)) { _finalResponse = response; break; } List <ReaderResultSet> protoReaders = response.ProtobufResponse.executeReaderResponse.readerResultSets; if (protoReaders != null && protoReaders.Count > 0) { foreach (ReaderResultSet protoReaderResultSet in protoReaders) { Common.DataReader.ReaderResultSet readerResultSet = null; foreach (Common.DataReader.ReaderResultSet set in _finalResponse.ReaderResultSets) { if (protoReaderResultSet.readerId == set.ReaderID && protoReaderResultSet.nodeAddress == set.NodeAddress) { readerResultSet = set; break; } } if (readerResultSet != null) { PopulateRows((Common.DataReader.RecordSet)readerResultSet.RecordSet, protoReaderResultSet.recordSet.rows); } else { readerResultSet = ConvertToReaderResult(protoReaderResultSet); _finalResponse.ReaderResultSets.Add(readerResultSet); } } } break; case Common.Protobuf.Response.Type.GET_READER_CHUNK: if (_finalResponse == null) { _finalResponse = response; } ReaderResultSet protoReaderChunkResultSet = response.ProtobufResponse.getReaderChunkResponse.readerResultSets; Common.DataReader.ReaderResultSet readerChunkResultSet = _finalResponse.ReaderNextChunk; if (readerChunkResultSet != null) { PopulateRows((Common.DataReader.RecordSet)readerChunkResultSet.RecordSet, protoReaderChunkResultSet.recordSet.rows); } else { readerChunkResultSet = ConvertToReaderResult(protoReaderChunkResultSet); _finalResponse.ReaderNextChunk = readerChunkResultSet; } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION: if (response.ExceptionType == Common.Enum.ExceptionType.STATE_TRANSFER_EXCEPTION) { _finalResponse = response; } break; default: break; } } } }
internal void MergeResponse(Common.Net.Address address, CommandResponse response) { if (_finalResponse == null && (response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.GET_READER_CHUNK && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.EXECUTE_READER && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.EXECUTE_READER_CQ)) { _finalResponse = response; if (response.IsBrokerReset) { MergeFailedResponse(response); } } else { if (response.IsBrokerReset) { MergeFailedResponse(response); } else { IDictionaryEnumerator ide = null; switch (response.Type) { case Common.Protobuf.Response.Type.POLL: _finalResponse.PollingResult.RemovedKeys.AddRange(response.PollingResult.RemovedKeys); _finalResponse.PollingResult.UpdatedKeys.AddRange(response.PollingResult.UpdatedKeys); break; case Common.Protobuf.Response.Type.ADD_BULK: case Common.Protobuf.Response.Type.INSERT_BULK: case Common.Protobuf.Response.Type.GET_BULK: case Common.Protobuf.Response.Type.BULK_GET_CACHEITEM: case Common.Protobuf.Response.Type.REMOVE_BULK: case Common.Protobuf.Response.Type.MESSAGE_ACKNOWLEDGEMENT: ide = response.KeyValueDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyValueDic[ide.Key] = ide.Value; } ide = response.KeyVersionDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyVersionDic[ide.Key] = ide.Value; } break; case Common.Protobuf.Response.Type.CONTAINS_BULK: ide = response.KeyValueDic.GetEnumerator(); while (ide.MoveNext()) { if (_finalResponse.KeyValueDic.ContainsKey(ide.Key)) { ((ArrayList)_finalResponse.KeyValueDic[ide.Key]).AddRange((ArrayList)ide.Value); } else { _finalResponse.KeyValueDic[ide.Key] = ide.Value; } } break; case Common.Protobuf.Response.Type.GET_MESSAGE: foreach (var item in response.MessageDic) { if (!_finalResponse.MessageDic.ContainsKey(item.Key)) { _finalResponse.MessageDic.Add(item.Key, item.Value); } else { foreach (var message in item.Value) { _finalResponse.MessageDic[item.Key].Add(message); } } } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_SERVER_MAPPING: _finalResponse.ServerMappingList = response.ServerMappingList; break; case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK: if (_finalResponse == null) { _finalResponse = response; } if (_chunks == null) { _chunks = new Dictionary <Common.Net.Address, EnumerationDataChunk>(); } EnumerationDataChunk chunk = null; if (_chunks.ContainsKey(address)) { chunk = _chunks[address]; } else { chunk = new EnumerationDataChunk(); chunk.Data = new List <string>(); _chunks.Add(address, chunk); } for (int i = 0; i < response.NextChunk.Count; i++) { chunk.Data.AddRange(response.NextChunk[i].Data); chunk.Pointer = response.NextChunk[i].Pointer; if (chunk.Pointer.NodeIpAddress == null) { chunk.Pointer.NodeIpAddress = address; } } _finalResponse.NextChunk = new List <EnumerationDataChunk>(_chunks.Values); break; case Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION: if (response.ExceptionType == Common.Enum.ExceptionType.STATE_TRANSFER_EXCEPTION) { _finalResponse = response; } break; default: break; } } } }
internal void MergeResponse(Common.Net.Address address, CommandResponse response) { if (_finalResponse == null && (response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.GET_READER_CHUNK && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.EXECUTE_READER && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.EXECUTE_READER_CQ)) { _finalResponse = response; if (response.IsBrokerReset) { MergeFailedResponse(response); } } else { if (response.IsBrokerReset) { MergeFailedResponse(response); } else { IDictionaryEnumerator ide = null; switch (response.Type) { case Common.Protobuf.Response.Type.POLL: _finalResponse.PollingResult.RemovedKeys.AddRange(response.PollingResult.RemovedKeys); _finalResponse.PollingResult.UpdatedKeys.AddRange(response.PollingResult.UpdatedKeys); break; case Common.Protobuf.Response.Type.ADD_BULK: case Common.Protobuf.Response.Type.INSERT_BULK: case Common.Protobuf.Response.Type.GET_BULK: case Common.Protobuf.Response.Type.REMOVE_BULK: case Common.Protobuf.Response.Type.GET_GROUP_DATA: case Common.Protobuf.Response.Type.GET_TAG: case Common.Protobuf.Response.Type.HYBRID_BULK: case Common.Protobuf.Response.Type.INVOKE_ENTRY_PROCESSOR: case Common.Protobuf.Response.Type.MESSAGE_ACKNOWLEDGEMENT: ide = response.KeyValueDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyValueDic[ide.Key] = ide.Value; } ide = response.KeyVersionDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyVersionDic[ide.Key] = ide.Value; } break; case Common.Protobuf.Response.Type.GET_MESSAGE: foreach (var item in response.MessageDic) { if (!_finalResponse.MessageDic.ContainsKey(item.Key)) { _finalResponse.MessageDic.Add(item.Key, item.Value); } else { foreach (var message in item.Value) { _finalResponse.MessageDic[item.Key].Add(message); } } } break; case Common.Protobuf.Response.Type.GET_GROUP_KEYS: case Common.Protobuf.Response.Type.GET_KEYS_TAG: _finalResponse.KeyList.AddRange(response.KeyList); break; case Common.Protobuf.Response.Type.EXECUTE_READER: case Common.Protobuf.Response.Type.EXECUTE_READER_CQ: if (_finalResponse == null) { _finalResponse = response; } if ((_finalResponse.ExceptionType == Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) || (_finalResponse.ExceptionType == Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND)) { _finalResponse = response; break; } List <ReaderResultSet> protoReaders = response.Type == Common.Protobuf.Response.Type.EXECUTE_READER ? response.ProtobufResponse.executeReaderResponse.readerResultSets : response.ProtobufResponse.executeReaderCQResponse.readerResultSets; if (protoReaders != null && protoReaders.Count > 0) { foreach (ReaderResultSet protoReaderResultSet in protoReaders) { Common.DataReader.ReaderResultSet readerResultSet = null; foreach (Common.DataReader.ReaderResultSet set in _finalResponse.ReaderResultSets) { if (protoReaderResultSet.readerId == set.ReaderID && protoReaderResultSet.nodeAddress == set.NodeAddress) { readerResultSet = set; break; } } if (readerResultSet != null) { PopulateRows((Common.DataReader.RecordSet)readerResultSet.RecordSet, protoReaderResultSet.recordSet.rows); } else { readerResultSet = ConvertToReaderResult(protoReaderResultSet); _finalResponse.ReaderResultSets.Add(readerResultSet); } } } break; case Common.Protobuf.Response.Type.GET_READER_CHUNK: if (_finalResponse == null) { _finalResponse = response; } ReaderResultSet protoReaderChunkResultSet = response.ProtobufResponse.getReaderChunkResponse.readerResultSets; Common.DataReader.ReaderResultSet readerChunkResultSet = _finalResponse.ReaderNextChunk; if (readerChunkResultSet != null) { PopulateRows((Common.DataReader.RecordSet)readerChunkResultSet.RecordSet, protoReaderChunkResultSet.recordSet.rows); } else { readerChunkResultSet = ConvertToReaderResult(protoReaderChunkResultSet); _finalResponse.ReaderNextChunk = readerChunkResultSet; } break; case Common.Protobuf.Response.Type.DELETE_QUERY: case Common.Protobuf.Response.Type.REMOVE_QUERY: if ((_finalResponse.ExceptionType == Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) || (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType .ATTRIBUTE_INDEX_NOT_FOUND)) { if ((response.ExceptionType != Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND) || (response.ExceptionType != Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND)) { _finalResponse = response; } } else if (_finalResponse != null && (response.ExceptionType != Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND) || (response.ExceptionType != Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND)) { _finalResponse.RemovedKeyCount += response.RemovedKeyCount; } break; case Common.Protobuf.Response.Type.SEARCH_CQ: _finalResponse.KeyList.AddRange(response.KeyList); if (response.ResultSet != null && !string.IsNullOrEmpty(response.ResultSet.CQUniqueId)) { string uniqueID = response.ResultSet.CQUniqueId; if (!string.IsNullOrEmpty(uniqueID) && uniqueID != "-1") { if (_finalResponse.ResultSet != null && string.IsNullOrEmpty(_finalResponse.ResultSet.CQUniqueId)) { _finalResponse.ResultSet.CQUniqueId = uniqueID; } } } break; case Common.Protobuf.Response.Type.SEARCH_ENTRIES: if ((_finalResponse.ExceptionType == Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) || (_finalResponse.ExceptionType == Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND)) { _finalResponse = response; break; } switch (response.ResultSet.Type) { case NCache.Caching.Queries.QueryType.GroupByAggregateFunction: break; default: switch (response.ResultSet.AggregateFunctionType) { case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE: ide = response.KeyValueDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyValueDic[ide.Key] = ide.Value; } break; default: if (!_finalResponse.ResultSet.IsInitialized) { SetAggregateFunctionResult(); _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet); } _finalResponse.ResultSet.Compile(response.ResultSet); break; } break; } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH: if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND) || (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType .ATTRIBUTE_INDEX_NOT_FOUND)) { _finalResponse = response; break; } switch (response.ResultSet.AggregateFunctionType) { case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE: _finalResponse.KeyList.AddRange(response.KeyList); break; default: if (!_finalResponse.ResultSet.IsInitialized) { SetAggregateFunctionResult(); _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet); } _finalResponse.ResultSet.Compile(response.ResultSet); break; } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_SERVER_MAPPING: _finalResponse.ServerMappingList = response.ServerMappingList; break; case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES_CQ: ide = response.KeyValueDic.GetEnumerator(); while (ide.MoveNext()) { _finalResponse.KeyValueDic[ide.Key] = ide.Value; } if (response.ResultSet != null && response.ResultSet.CQUniqueId != null) { string uniqueID = response.ResultSet.CQUniqueId; if (!string.IsNullOrEmpty(uniqueID) && uniqueID != null) { if (_finalResponse.ResultSet != null && string.IsNullOrEmpty(_finalResponse.ResultSet.CQUniqueId)) { _finalResponse.ResultSet.CQUniqueId = response.ResultSet.CQUniqueId; } } } break; case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK: if (_finalResponse == null) { _finalResponse = response; } EnumerationDataChunk chunk = null; if (_chunks.ContainsKey(address)) { chunk = _chunks[address]; } else { chunk = new EnumerationDataChunk(); chunk.Data = new List <string>(); _chunks.Add(address, chunk); } for (int i = 0; i < response.NextChunk.Count; i++) { chunk.Data.AddRange(response.NextChunk[i].Data); chunk.Pointer = response.NextChunk[i].Pointer; if (chunk.Pointer.NodeIpAddress == null) { chunk.Pointer.NodeIpAddress = address; } } _finalResponse.NextChunk = new List <EnumerationDataChunk>(_chunks.Values); break; case Common.Protobuf.Response.Type.TASK_ENUMERATOR: _finalResponse.TaskEnumerator.AddRange(response.TaskEnumerator); break; case Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION: if (response.ExceptionType == Common.Enum.ExceptionType.STATE_TRANSFER_EXCEPTION) { _finalResponse = response; } break; default: break; } } } }