/// <summary> /// Initializes the SyncCache. /// </summary> public void Initialize() { try { CacheInitParams initParams = new CacheInitParams(); initParams.Server = _server; initParams.Port = _port; initParams.LoadBalance = true; _syncCache = Caching.NCache.InitializeCache(_cacheId, initParams, false); _updateCallback = new CacheDataNotificationCallback(OnItemChangedCallback); _removedCallback = new CacheDataNotificationCallback(OnItemRemovedCallback); _cacheClearCallback = new CacheClearedCallback(OnCacheClear); _cacheStoppedCallback = new CacheStoppedCallback(OnCacheStopped); _synEventListeners = new ArrayList(); if (_syncCache != null) { _syncCache.ExceptionsEnabled = true; _syncCache.CacheCleared += _cacheClearCallback; _syncCache.CacheStopped += _cacheStoppedCallback; } } catch (Exception ex) { throw new Exception("Unable to initialize " + _cacheId + " while creating CacheSyncDependency", ex); } }
private CommandInfo ParseCommand(Caching.Cache cache, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo = new CommandInfo(); Alachisoft.NCache.Common.Protobuf.AddAttributeCommand addAttributeCommand = command.addAttributeCommand; cmdInfo.ExpHint = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(cache.Configuration.ExpirationPolicy, addAttributeCommand.dependency, addAttributeCommand.absExpiration, 0, false, serializationContext); cmdInfo.Key = addAttributeCommand.key; cmdInfo.RequestId = addAttributeCommand.requestId.ToString(); return(cmdInfo); }
public CosmosContext(CosmosConfig config) { _cache = new Caching.Cache("Cosmos", config.CacheMb); var retriesOn429Throttling = 1; // Number of retries before failing processing when provisioned RU/s limit in CosmosDb is breached var timeout = TimeSpan.FromSeconds(5); // Timeout applied per request to CosmosDb, including retry attempts var discovery = Discovery.FromConnectionString(config.ConnectionStringWithUriAndKey); _connect = async() => { var gateway = await Connect("App", config.Mode, discovery, timeout, retriesOn429Throttling, (int)timeout.TotalSeconds); var collectionMapping = new EqxCollections(config.Database, config.Collection); _store = new EqxStore(gateway, collectionMapping); }; }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { CommandInfo commandInfo; try { commandInfo = ParseCommand(command); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; Caching.Cache cache = nCache.Cache; Alachisoft.NCache.Config.Dom.ExpirationPolicy policy = null; policy = cache.Configuration.ExpirationPolicy; Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.GetExpirationResponse getExpirationResponse = new Alachisoft.NCache.Common.Protobuf.GetExpirationResponse(); getExpirationResponse.absDefault = policy.AbsoluteExpiration.Default; getExpirationResponse.absDefaultEnabled = policy.AbsoluteExpiration.DefaultEnabled; getExpirationResponse.sldDefault = policy.SlidingExpiration.Default; getExpirationResponse.sldDefaultEnabled = policy.SlidingExpiration.DefaultEnabled; getExpirationResponse.absLonger = policy.AbsoluteExpiration.Longer; getExpirationResponse.absLongerEnabled = policy.AbsoluteExpiration.LongerEnabled; getExpirationResponse.sldLonger = policy.SlidingExpiration.Longer; getExpirationResponse.sldLongerEnabled = policy.SlidingExpiration.LongerEnabled; response.getExpirationResponse = getExpirationResponse; response.requestId = Convert.ToInt64(commandInfo.requestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.EXPIRATION_RESPONSE; //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { CommandInfo commandInfo; try { commandInfo = ParseCommand(command); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; Caching.Cache cache = nCache.Cache; Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.requestId = Convert.ToInt64(commandInfo.requestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.EXPIRATION_RESPONSE; //PROTOBUF:RESPONSE if (clientManager.ClientVersion >= 5000) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.EXPIRATION_RESPONSE)); } else { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } }
public static IList BuildResponse(HashVector getTagResult, int commandVersion, string RequestId, IList _serializedResponse, int commandID, Caching.Cache cache, ClientManager clientManager, Int64 requestID) { Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.Cache = cache; long requestId = Convert.ToInt64(RequestId); switch (commandVersion) { case 0: //Versions earlier than NCache 4.1 because all of them expect responses as one chunck { } break; case 1: //Verion 4.1 or later break; } return(_serializedResponse); }
private Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse PopulateResponse(CacheEntry entry, Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse response, ClientManager clientManager, Caching.Cache cache) { if (entry.ExpirationHint is AggregateExpirationHint) { IList <ExpirationHint> hints = ((AggregateExpirationHint)entry.ExpirationHint).Hints; ///All hints are on same level now. There will be no AggregateExpirationHint within an AggregateExpirationHint for (int i = 0; i < hints.Count; i++) { if (hints[i] is FixedExpiration) { response.absExp = ((FixedExpiration)hints[i]).AbsoluteTime.Ticks; } else if (hints[i] is IdleExpiration) { response.sldExp = ((IdleExpiration)hints[i]).SlidingTime.Ticks; } } } else { if (entry.ExpirationHint is FixedExpiration) { response.absExp = ((FixedExpiration)entry.ExpirationHint).AbsoluteTime.Ticks; } else if (entry.ExpirationHint is IdleExpiration) { response.sldExp = ((IdleExpiration)entry.ExpirationHint).SlidingTime.Ticks; } } response.itemType = MiscUtil.EntryTypeToProtoItemType(entry.Type);// (Alachisoft.NCache.Common.Protobuf.CacheItemType.ItemType)entry.Type; response.priority = (int)entry.Priority; if (entry.QueryInfo != null) { } if (entry.ExpirationHint != null) { response.hasExpired = entry.ExpirationHint.HasExpired; response.needsResync = entry.ExpirationHint.NeedsReSync; } response.version = entry.Version; response.creationTime = entry.CreationTime.Ticks; response.lastModifiedTime = entry.LastModifiedTime.Ticks; //response.lockId = (entry.LockId != null ? entry.LockId.ToString() : null); //response.lockTicks = entry.LockDate.Ticks; response.ResyncProviderName = entry.ResyncProviderName; object userValue = entry.Value; BitSet flag = entry.Flag; object data = cache.SocketServerDataService.GetClientData(userValue, ref flag, LanguageContext.DOTNET); if (data != null) { response.value.AddRange(((UserBinaryObject)(data)).DataList); } response.flag = flag.Data; return(response); }
//public override void ExecuteCommand(ClientManager clientManager, string command, byte[] data) //{ //} //PROTOBUF protected virtual CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager, string cacheId) { //if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("AddInsertCmd.Parse", "enter"); CommandInfo cmdInfo = new CommandInfo(); Hashtable queryInfoHashtable = null; Hashtable tagHashtable = null; Hashtable namedTagHashtable = null; string version = string.Empty; NCache nCache = clientManager.CmdExecuter as NCache; Caching.Cache cache = nCache.Cache; switch (command.type) { case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD: Alachisoft.NCache.Common.Protobuf.AddCommand addCommand = command.addCommand; if (clientManager.ClientVersion < 5000 && !clientManager.CreateEventSubscription) { if (addCommand.removeCallbackId != -1 || addCommand.updateCallbackId != -1) { Util.EventHelper.SubscribeEvents(clientManager.ClientID, TopicConstant.ItemLevelEventsTopic, nCache, null); clientManager.CreateEventSubscription = true; } } cmdInfo.Key = clientManager.CacheTransactionalPool.StringPool.GetString(addCommand.key); cmdInfo.DoAsync = addCommand.isAsync; cmdInfo.DsItemAddedCallbackId = (short)addCommand.datasourceItemAddedCallbackId; cmdInfo.EvictionHint = _priorityEvictionHint; cmdInfo.EvictionHint.Priority = (CacheItemPriority)addCommand.priority; cmdInfo.ExpirationHint = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(clientManager.CacheTransactionalPool, null, addCommand.absExpiration, addCommand.sldExpiration, addCommand.isResync, serializationContext); BitSet bitset = _bitSet; bitset.Data = ((byte)addCommand.flag); cmdInfo.Flag = bitset; cmdInfo.ProviderName = addCommand.providerName.Length == 0 ? null : addCommand.providerName; cmdInfo.queryInfo = new Hashtable(); cmdInfo.ClientID = addCommand.clientID; version = command.version; if (queryInfoHashtable != null) { if (cmdInfo.queryInfo == null) { cmdInfo.queryInfo = new Hashtable(); } cmdInfo.queryInfo.Add("query-info", queryInfoHashtable); } cmdInfo.RemoveCallbackId = (short)addCommand.removeCallbackId; //for old clients data fitler information will be missing if (addCommand.removeDataFilter != -1) { cmdInfo.RemoveDataFilter = (EventDataFilter)addCommand.removeDataFilter; } else { cmdInfo.RemoveDataFilter = Runtime.Events.EventDataFilter.None; } cmdInfo.RequestId = addCommand.requestId; cmdInfo.ResyncProviderName = addCommand.resyncProviderName.Length == 0 ? null : addCommand.resyncProviderName; if (addCommand.subGroup != null) { cmdInfo.SubGroup = addCommand.subGroup.Length == 0 ? null : addCommand.subGroup; } cmdInfo.UpdateCallbackId = (short)addCommand.updateCallbackId; if (addCommand.updateDataFilter != -1) { cmdInfo.UpdateDataFilter = (EventDataFilter)addCommand.updateDataFilter; } else { cmdInfo.UpdateDataFilter = (int)Runtime.Events.EventDataFilter.None; } cmdInfo.value = cache.SocketServerDataService.GetCacheData(addCommand.data.ToArray(), cmdInfo.Flag); try { for (int count = 0; count < addCommand.data.Count; count++) { cmdInfo.DataFormatValue = cmdInfo.DataFormatValue + addCommand.data[count].Length; } } catch { } break; case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT: Alachisoft.NCache.Common.Protobuf.InsertCommand insertCommand = command.insertCommand; if (clientManager.ClientVersion < 5000 && !clientManager.CreateEventSubscription) { if (insertCommand.removeCallbackId != -1 || insertCommand.updateCallbackId != -1) { Util.EventHelper.SubscribeEvents(clientManager.ClientID, TopicConstant.ItemLevelEventsTopic, nCache, null); clientManager.CreateEventSubscription = true; } } cmdInfo.Key = clientManager.CacheTransactionalPool.StringPool.GetString(insertCommand.key); cmdInfo.DoAsync = insertCommand.isAsync; cmdInfo.DsItemAddedCallbackId = (short)insertCommand.datasourceUpdatedCallbackId; cmdInfo.EvictionHint = _priorityEvictionHint; cmdInfo.EvictionHint.Priority = (CacheItemPriority)insertCommand.priority; cmdInfo.ExpirationHint = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(clientManager.CacheTransactionalPool, null, insertCommand.absExpiration, insertCommand.sldExpiration, insertCommand.isResync, serializationContext); bitset = _bitSet; bitset.Data = ((byte)insertCommand.flag); cmdInfo.Flag = bitset; cmdInfo.ProviderName = insertCommand.providerName.Length == 0 ? null : insertCommand.providerName; cmdInfo.ClientID = insertCommand.clientID; cmdInfo.CallbackType = insertCommand.CallbackType; version = command.version; //version added in 4.2 [Dated: 18-Nov-2013; Author: Sami] if (tagHashtable != null) { if (cmdInfo.queryInfo == null) { cmdInfo.queryInfo = new Hashtable(); } cmdInfo.queryInfo.Add("tag-info", tagHashtable); } cmdInfo.RemoveCallbackId = (short)insertCommand.removeCallbackId; if (insertCommand.removeDataFilter != -1) { cmdInfo.RemoveDataFilter = (EventDataFilter)insertCommand.removeDataFilter; } else { cmdInfo.RemoveDataFilter = Runtime.Events.EventDataFilter.None; } cmdInfo.RequestId = insertCommand.requestId; cmdInfo.ResyncProviderName = insertCommand.resyncProviderName.Length == 0 ? null : insertCommand.resyncProviderName; cmdInfo.UpdateCallbackId = (short)insertCommand.updateCallbackId; if (insertCommand.updateDataFilter != -1) { cmdInfo.UpdateDataFilter = (EventDataFilter)insertCommand.updateDataFilter; } else { cmdInfo.UpdateDataFilter = (int)Runtime.Events.EventDataFilter.None; } cmdInfo.ItemVersion = insertCommand.itemVersion; cmdInfo.LockAccessType = (LockAccessType)insertCommand.lockAccessType; cmdInfo.LockId = insertCommand.lockId; cmdInfo.value = cache.SocketServerDataService.GetCacheData(insertCommand.data, cmdInfo.Flag); try { for (int count = 0; count < insertCommand.data.Count; count++) { cmdInfo.DataFormatValue = cmdInfo.DataFormatValue + insertCommand.data[count].Length; } } catch { } break; } return(cmdInfo); }
public static IList BuildResponse(HashVector getResult, int commandVersion, string RequestId, IList _serializedResponse, string intendedRecepient, int commandID, ClientManager clientManager, Caching.Cache cache) { Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.Cache = cache; long requestId = Convert.ToInt64(RequestId); switch (commandVersion) { case 0: //Versions earlier than NCache 4.1 because all of them expect responses as one chunck { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.BulkGetResponse bulkGetResponse = new Alachisoft.NCache.Common.Protobuf.BulkGetResponse(); response.requestId = requestId; response.commandID = commandID; response.intendedRecipient = intendedRecepient; bulkGetResponse.keyValuePackage = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(getResult, bulkGetResponse.keyValuePackage); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_BULK; response.bulkGet = bulkGetResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.GET_BULK)); } break; case 1: //Verion 4.1 or later { IList keyValuesPackageChuncks = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(getResult); int sequenceId = 1; Alachisoft.NCache.Common.Protobuf.BulkGetResponse bulkGetResponse = new Alachisoft.NCache.Common.Protobuf.BulkGetResponse(); if (clientManager.ClientVersion >= 5000) { bulkGetResponse.requestId = requestId; bulkGetResponse.commandID = commandID; bulkGetResponse.numberOfChuncks = keyValuesPackageChuncks.Count; foreach (Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse package in keyValuesPackageChuncks) { bulkGetResponse.sequenceId = sequenceId++; bulkGetResponse.keyValuePackage = package; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(bulkGetResponse, Common.Protobuf.Response.Type.GET_BULK)); } } else { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.numberOfChuncks = keyValuesPackageChuncks.Count; Common.Util.ResponseHelper.SetResponse(response, requestId, commandID, Common.Protobuf.Response.Type.GET_BULK); foreach (Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse package in keyValuesPackageChuncks) { response.sequenceId = sequenceId++; bulkGetResponse.keyValuePackage = package; response.bulkGet = bulkGetResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } } break; } return(_serializedResponse); }
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); }
public static IList BuildResponse(HashVector getTagResult, int commandVersion, string RequestId, IList _serializedResponse, int commandID, Caching.Cache cache) { Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.Cache = cache; long requestId = Convert.ToInt64(RequestId); switch (commandVersion) { case 0: // Versions earlier than NCache 4.1 because all of them expect responses as one chunck { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.GetTagResponse getTagResponse = new Alachisoft.NCache.Common.Protobuf.GetTagResponse(); response.requestId = requestId; response.commandID = commandID; getTagResponse.keyValuePackage = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(getTagResult, getTagResponse.keyValuePackage); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_TAG; response.getTag = getTagResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } break; case 1: // Verion 4.1 or later { IList keyValuesPackageChuncks = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(getTagResult); int sequenceId = 1; Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.GetTagResponse getTagResponse = new Alachisoft.NCache.Common.Protobuf.GetTagResponse(); response.requestId = requestId; response.commandID = commandID; response.numberOfChuncks = keyValuesPackageChuncks.Count; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_TAG; foreach (Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse package in keyValuesPackageChuncks) { response.sequenceId = sequenceId++; getTagResponse.keyValuePackage = package; response.getTag = getTagResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } break; } return(_serializedResponse); }
private Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse PopulateResponse(CacheEntry entry, Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse response, ClientManager clientManager, Caching.Cache cache) { if (entry.ExpirationHint is AggregateExpirationHint) { IList <ExpirationHint> hints = ((AggregateExpirationHint)entry.ExpirationHint).Hints; // All hints are on same level now. There will be no AggregateExpirationHint within an AggregateExpirationHint for (int i = 0; i < hints.Count; i++) { if (hints[i] is FixedExpiration) { response.absExp = ((FixedExpiration)hints[i]).AbsoluteTime.Ticks; } else if (hints[i] is IdleExpiration) { response.sldExp = ((IdleExpiration)hints[i]).SlidingTime.Ticks; } } } else { if (entry.ExpirationHint is FixedExpiration) { response.absExp = ((FixedExpiration)entry.ExpirationHint).AbsoluteTime.Ticks; } else if (entry.ExpirationHint is IdleExpiration) { response.sldExp = ((IdleExpiration)entry.ExpirationHint).SlidingTime.Ticks; } } // Fixed and Idle expiration hints are not included in making of protobuf dependency object response.dependency = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetDependencyObj(entry.ExpirationHint); response.priority = (int)entry.Priority; if (entry.QueryInfo != null) { if (entry.QueryInfo["tag-info"] != null) { response.tagInfo = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetTagInfoObj(entry.QueryInfo["tag-info"] as Hashtable); } if (entry.QueryInfo["named-tag-info"] != null) { response.namedTagInfo = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetNamedTagInfoObj(entry.QueryInfo["named-tag-info"] as Hashtable, clientManager.IsDotNetClient); } } if (entry.ExpirationHint != null) { response.hasExpired = entry.ExpirationHint.HasExpired; response.needsResync = entry.ExpirationHint.NeedsReSync; } response.version = entry.Version; response.creationTime = entry.CreationTime.Ticks; response.lastModifiedTime = entry.LastModifiedTime.Ticks; if (entry.GroupInfo != null) { response.group = entry.GroupInfo.Group; response.subGroup = entry.GroupInfo.SubGroup; } object userValue = entry.Value; if (userValue is CallbackEntry) { userValue = ((CallbackEntry)userValue).Value; } BitSet flag = entry.Flag; response.value.AddRange(((UserBinaryObject)cache.SocketServerDataService.GetClientData(userValue, ref flag, LanguageContext.DOTNET)).DataList); response.flag = flag.Data; return(response); }
//PROTOBUF protected virtual CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager, string cacheId) { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("AddInsertCmd.Parse", "enter"); } CommandInfo cmdInfo = new CommandInfo(); Hashtable queryInfoHashtable = null; Hashtable tagHashtable = null; Hashtable namedTagHashtable = null; string version = string.Empty; NCache nCache = clientManager.CmdExecuter as NCache; Caching.Cache cache = nCache.Cache; bool expEnabled = cache.Configuration.ExpirationPolicy.IsExpirationEnabled; switch (command.type) { case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD: Alachisoft.NCache.Common.Protobuf.AddCommand addCommand = command.addCommand; cmdInfo.Key = addCommand.key; cmdInfo.DoAsync = addCommand.isAsync; cmdInfo.DsItemAddedCallbackId = (short)addCommand.datasourceItemAddedCallbackId; cmdInfo.EvictionHint = new PriorityEvictionHint((CacheItemPriority)addCommand.priority); cmdInfo.ExpirationHint = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(cache.Configuration.ExpirationPolicy, addCommand.dependency, addCommand.absExpiration, addCommand.sldExpiration, addCommand.isResync, serializationContext); cmdInfo.Flag = new BitSet((byte)addCommand.flag); if (addCommand.group != null) { cmdInfo.Group = addCommand.group.Length == 0 ? null : addCommand.group; } cmdInfo.ProviderName = addCommand.providerName.Length == 0 ? null : addCommand.providerName; cmdInfo.queryInfo = new Hashtable(); cmdInfo.ClientID = addCommand.clientID; version = command.version; // version added in 4.2 [Dated: 18-Nov-2013] if (string.IsNullOrEmpty(version)) { queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(addCommand.queryInfo); tagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromTagInfoObj(addCommand.tagInfo); if (clientManager.IsDotNetClient) { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromDotNet(addCommand.namedTagInfo); } else { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromJava(addCommand.namedTagInfo); } } else { ObjectQueryInfo objectQueryInfo = addCommand.objectQueryInfo; queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(objectQueryInfo.queryInfo); tagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromTagInfoObj(objectQueryInfo.tagInfo); if (clientManager.IsDotNetClient) { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromDotNet(objectQueryInfo.namedTagInfo); } else { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromJava(objectQueryInfo.namedTagInfo); } } if (queryInfoHashtable != null) { if (cmdInfo.queryInfo == null) { cmdInfo.queryInfo = new Hashtable(); } cmdInfo.queryInfo.Add("query-info", queryInfoHashtable); } if (tagHashtable != null) { if (cmdInfo.queryInfo == null) { cmdInfo.queryInfo = new Hashtable(); } cmdInfo.queryInfo.Add("tag-info", tagHashtable); } if (namedTagHashtable != null) { if (cmdInfo.queryInfo == null) { cmdInfo.queryInfo = new Hashtable(); } cmdInfo.queryInfo.Add("named-tag-info", namedTagHashtable); } cmdInfo.RemoveCallbackId = (short)addCommand.removeCallbackId; // for old clients data fitler information will be missing if (addCommand.removeDataFilter != -1) { cmdInfo.RemoveDataFilter = (int)addCommand.removeDataFilter; } else { cmdInfo.RemoveDataFilter = (int)Runtime.Events.EventDataFilter.DataWithMetadata; } cmdInfo.RequestId = addCommand.requestId.ToString(); cmdInfo.ResyncProviderName = addCommand.resyncProviderName.Length == 0 ? null : addCommand.resyncProviderName; if (addCommand.subGroup != null) { cmdInfo.SubGroup = addCommand.subGroup.Length == 0 ? null : addCommand.subGroup; } cmdInfo.SyncDependency = base.GetCacheSyncDependencyObj(addCommand.syncDependency); cmdInfo.UpdateCallbackId = (short)addCommand.updateCallbackId; if (addCommand.updateDataFilter != -1) { cmdInfo.UpdateDataFilter = addCommand.updateDataFilter; } else { cmdInfo.UpdateDataFilter = (int)Runtime.Events.EventDataFilter.None; } cmdInfo.value = cache.SocketServerDataService.GetCacheData(addCommand.data.ToArray(), cmdInfo.Flag); try { for (int count = 0; count < addCommand.data.Count; count++) { cmdInfo.DataFormatValue = cmdInfo.DataFormatValue + addCommand.data[count].Length; } } catch { } break; case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT: Alachisoft.NCache.Common.Protobuf.InsertCommand insertCommand = command.insertCommand; cmdInfo.Key = insertCommand.key; cmdInfo.DoAsync = insertCommand.isAsync; cmdInfo.DsItemAddedCallbackId = (short)insertCommand.datasourceUpdatedCallbackId; cmdInfo.EvictionHint = new PriorityEvictionHint((CacheItemPriority)insertCommand.priority); cmdInfo.ExpirationHint = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(cache.Configuration.ExpirationPolicy, insertCommand.dependency, insertCommand.absExpiration, insertCommand.sldExpiration, insertCommand.isResync, serializationContext); cmdInfo.Flag = new BitSet((byte)insertCommand.flag); if (insertCommand.group != null) { cmdInfo.Group = insertCommand.group.Length == 0 ? null : insertCommand.group; } cmdInfo.ProviderName = insertCommand.providerName.Length == 0 ? null : insertCommand.providerName; cmdInfo.ClientID = insertCommand.clientID; cmdInfo.CallbackType = insertCommand.CallbackType; version = command.version; // version added in 4.2 [Dated: 18-Nov-2013] if (string.IsNullOrEmpty(version)) { if (insertCommand.queryInfo != null) { queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(insertCommand.queryInfo); } if (insertCommand.tagInfo != null) { tagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromTagInfoObj(insertCommand.tagInfo); } if (insertCommand.namedTagInfo != null) { if (clientManager.IsDotNetClient) { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromDotNet(insertCommand.namedTagInfo); } else { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromJava(insertCommand.namedTagInfo); } } } else { ObjectQueryInfo objectQueryInfo = insertCommand.objectQueryInfo; if (objectQueryInfo.queryInfo != null) { queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(objectQueryInfo.queryInfo); } if (objectQueryInfo.tagInfo != null) { tagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromTagInfoObj(objectQueryInfo.tagInfo); } if (objectQueryInfo.namedTagInfo != null) { if (clientManager.IsDotNetClient) { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromDotNet(objectQueryInfo.namedTagInfo); } else { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromJava(objectQueryInfo.namedTagInfo); } } } if (queryInfoHashtable != null) { if (cmdInfo.queryInfo == null) { cmdInfo.queryInfo = new Hashtable(); } cmdInfo.queryInfo.Add("query-info", queryInfoHashtable); } if (tagHashtable != null) { if (cmdInfo.queryInfo == null) { cmdInfo.queryInfo = new Hashtable(); } cmdInfo.queryInfo.Add("tag-info", tagHashtable); } if (namedTagHashtable != null) { if (cmdInfo.queryInfo == null) { cmdInfo.queryInfo = new Hashtable(); } cmdInfo.queryInfo.Add("named-tag-info", namedTagHashtable); } cmdInfo.RemoveCallbackId = (short)insertCommand.removeCallbackId; if (insertCommand.removeDataFilter != -1) { cmdInfo.RemoveDataFilter = insertCommand.removeDataFilter; } else { cmdInfo.RemoveDataFilter = (int)Runtime.Events.EventDataFilter.DataWithMetadata; } cmdInfo.RequestId = insertCommand.requestId.ToString(); cmdInfo.ResyncProviderName = insertCommand.resyncProviderName.Length == 0 ? null : insertCommand.resyncProviderName; if (insertCommand.subGroup != null) { cmdInfo.SubGroup = insertCommand.subGroup.Length == 0 ? null : insertCommand.subGroup; } if (insertCommand.syncDependency != null) { cmdInfo.SyncDependency = base.GetCacheSyncDependencyObj(insertCommand.syncDependency); } cmdInfo.UpdateCallbackId = (short)insertCommand.updateCallbackId; if (insertCommand.updateDataFilter != -1) { cmdInfo.UpdateDataFilter = insertCommand.updateDataFilter; } else { cmdInfo.UpdateDataFilter = (int)Runtime.Events.EventDataFilter.None; } cmdInfo.ItemVersion = insertCommand.itemVersion; cmdInfo.LockAccessType = (LockAccessType)insertCommand.lockAccessType; cmdInfo.LockId = insertCommand.lockId; cmdInfo.value = cache.SocketServerDataService.GetCacheData(insertCommand.data.ToArray(), cmdInfo.Flag); try { for (int count = 0; count < insertCommand.data.Count; count++) { cmdInfo.DataFormatValue = cmdInfo.DataFormatValue + insertCommand.data[count].Length; } } catch { } break; } return(cmdInfo); }
protected CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager, string cacheId) { CommandInfo cmdInfo = new CommandInfo(); int packageSize = 0; int index = 0; string version = string.Empty; NCache nCache = clientManager.CmdExecuter as NCache; Caching.Cache cache = nCache.Cache; Hashtable queryInfoHashtable = null; Hashtable tagHashtable = null; Hashtable namedTagHashtable = null; try { switch (command.type) { case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD_BULK: Alachisoft.NCache.Common.Protobuf.BulkAddCommand bulkAddCommand = command.bulkAddCommand; packageSize = bulkAddCommand.addCommand.Count; cmdInfo.Keys = new string[packageSize]; cmdInfo.Entries = new CacheEntry[packageSize]; cmdInfo.OnDsItemsAddedCallback = (short)bulkAddCommand.datasourceItemAddedCallbackId; cmdInfo.ProviderName = bulkAddCommand.providerName.Length == 0 ? null : bulkAddCommand.providerName; cmdInfo.RequestId = bulkAddCommand.requestId; cmdInfo.ClientLastViewId = command.clientLastViewId; cmdInfo.IntendedRecipient = command.intendedRecipient; cmdInfo.returnVersion = bulkAddCommand.returnVersions; foreach (Alachisoft.NCache.Common.Protobuf.AddCommand addCommand in bulkAddCommand.addCommand) { cmdInfo.Keys[index] = addCommand.key; cmdInfo.ClientID = addCommand.clientID; BitSet flag = BitSet.CreateAndMarkInUse(clientManager.CacheFakePool, NCModulesConstants.SocketServer); flag.Data = ((byte)addCommand.flag); if (index == 0) { cmdInfo.Flag = flag; } object value = cache.SocketServerDataService.GetCacheData(addCommand.data.ToArray(), cmdInfo.Flag); cmdInfo.Entries[index] = CacheEntry.CreateCacheEntry(clientManager.CacheTransactionalPool, value, Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(clientManager.CacheTransactionalPool, null, addCommand.absExpiration, addCommand.sldExpiration, addCommand.isResync, serailizationContext), PriorityEvictionHint.Create(clientManager.CacheTransactionalPool, (CacheItemPriority)addCommand.priority)); cmdInfo.Entries[index].Flag.Data |= flag.Data; Notifications notification = null; if ((short)addCommand.updateCallbackId != -1 || (short)addCommand.removeCallbackId != -1 || cmdInfo.OnDsItemsAddedCallback != -1) { notification = new Notifications(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), (short)addCommand.removeCallbackId, (short)addCommand.updateCallbackId, (short)(cmdInfo.RequestId == -1 ? -1 : 0), cmdInfo.OnDsItemsAddedCallback, (EventDataFilter)(addCommand.updateDataFilter != -1 ? (int)addCommand.updateDataFilter : (int)EventDataFilter.None), (EventDataFilter)(addCommand.removeDataFilter != -1 ? (int)addCommand.removeDataFilter : (int)EventDataFilter.None) ); cmdInfo.Entries[index].Notifications = notification; } cmdInfo.onUpdateCallbackId = (short)addCommand.updateCallbackId; if (!String.IsNullOrEmpty(cmdInfo.Group)) { cmdInfo.Entries[index].GroupInfo = new GroupInfo(cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.type); } version = command.version; if (queryInfoHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("query-info", queryInfoHashtable); } cmdInfo.Entries[index].MarkInUse(NCModulesConstants.SocketServer); index++; if (addCommand?.PoolManager != null) { addCommand.PoolManager.GetProtobufAddCommandPool()?.Return(addCommand); } } break; case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT_BULK: Alachisoft.NCache.Common.Protobuf.BulkInsertCommand bulkInsertCommand = command.bulkInsertCommand; packageSize = bulkInsertCommand.insertCommand.Count; cmdInfo.Keys = new string[packageSize]; cmdInfo.Entries = new CacheEntry[packageSize]; cmdInfo.OnDsItemsAddedCallback = (short)bulkInsertCommand.datasourceUpdatedCallbackId; cmdInfo.ProviderName = bulkInsertCommand.providerName.Length == 0 ? null : bulkInsertCommand.providerName; cmdInfo.RequestId = bulkInsertCommand.requestId; cmdInfo.ClientLastViewId = command.clientLastViewId; cmdInfo.IntendedRecipient = command.intendedRecipient; cmdInfo.returnVersion = bulkInsertCommand.returnVersions; foreach (Alachisoft.NCache.Common.Protobuf.InsertCommand insertCommand in bulkInsertCommand.insertCommand) { cmdInfo.Keys[index] = insertCommand.key; cmdInfo.ClientID = insertCommand.clientID; BitSet flag = BitSet.CreateAndMarkInUse(clientManager.CacheFakePool, NCModulesConstants.SocketServer); flag.Data = ((byte)insertCommand.flag); if (index == 0) { cmdInfo.Flag = flag; } object value = cache.SocketServerDataService.GetCacheData(insertCommand.data.ToArray(), cmdInfo.Flag); cmdInfo.Entries[index] = CacheEntry.CreateCacheEntry(clientManager.CacheTransactionalPool, value, Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(clientManager.CacheTransactionalPool, null, insertCommand.absExpiration, insertCommand.sldExpiration, insertCommand.isResync, serailizationContext), PriorityEvictionHint.Create(clientManager.CacheTransactionalPool, (CacheItemPriority)insertCommand.priority)); cmdInfo.Entries[index].Flag.Data |= flag.Data; Notifications notification = null; if (insertCommand.updateCallbackId != -1 || insertCommand.removeCallbackId != -1 || cmdInfo.OnDsItemsAddedCallback != -1) { notification = new Notifications(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), (short)insertCommand.removeCallbackId, (short)insertCommand.updateCallbackId, (short)(cmdInfo.RequestId == -1 ? -1 : 0), cmdInfo.OnDsItemsAddedCallback, (EventDataFilter)(insertCommand.updateDataFilter != -1 ? (int)insertCommand.updateDataFilter : (int)EventDataFilter.None), (EventDataFilter)(insertCommand.removeDataFilter != -1 ? (int)insertCommand.removeDataFilter : (int)EventDataFilter.None) ); cmdInfo.Entries[index].Notifications = notification; } cmdInfo.onUpdateCallbackId = (short)insertCommand.updateCallbackId; if (!String.IsNullOrEmpty(cmdInfo.Group)) { cmdInfo.Entries[index].GroupInfo = new GroupInfo(cmdInfo.Group, cmdInfo.SubGroup, cmdInfo.type); } version = command.version; if (queryInfoHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("query-info", queryInfoHashtable); } if (tagHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("tag-info", tagHashtable); } cmdInfo.Entries[index].MarkInUse(NCModulesConstants.SocketServer); index++; if (insertCommand?.PoolManager != null) { insertCommand.PoolManager.GetProtobufInsertCommandPool()?.Return(insertCommand); } } break; } } finally { } return(cmdInfo); }
public static void BuildResponse(QueryResultSet resultSet, int commandVersion, string RequestId, IList _serializedResponse, int commandID, Caching.Cache cache, out int resultCount) { Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.Cache = cache; long requestId = Convert.ToInt64(RequestId); resultCount = 0; try { switch (commandVersion) { case 0: // Version from NCache 3.8 to NCache 3.8 SP3 { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse(); response.requestId = requestId; response.commandID = commandID; searchEntriesResponse.keyValuePackage = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(resultSet.SearchEntriesResult, searchEntriesResponse.keyValuePackage); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES; response.searchEntries = searchEntriesResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } break; case 1: // From Version 3.8 SP4 onwards // Offically announcing support in 4.1 // So not supporting 3.8 SP4 clients in case of aggregate functions with 4.1 Cache Server case 2: // NCache 4.1 SP1 { switch (resultSet.Type) { case QueryType.AggregateFunction: { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse(); searchEntriesResponse.queryResultSet = new Alachisoft.NCache.Common.Protobuf.QueryResultSet(); response.requestId = requestId; response.commandID = commandID; searchEntriesResponse.queryResultSet.queryType = Alachisoft.NCache.Common.Protobuf.QueryType.AGGREGATE_FUNCTIONS; searchEntriesResponse.queryResultSet.aggregateFunctionType = (Alachisoft.NCache.Common.Protobuf.AggregateFunctionType)(int) resultSet.AggregateFunctionType; searchEntriesResponse.queryResultSet.aggregateFunctionResult = new Alachisoft.NCache.Common.Protobuf.DictionaryItem(); searchEntriesResponse.queryResultSet.aggregateFunctionResult.key = resultSet.AggregateFunctionResult.Key.ToString(); searchEntriesResponse.queryResultSet.aggregateFunctionResult.value = resultSet.AggregateFunctionResult.Value != null?CompactBinaryFormatter.ToByteBuffer(resultSet.AggregateFunctionResult.Value, null) : null; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES; response.searchEntries = searchEntriesResponse; resultCount = 1; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } break; case QueryType.SearchEntries: { int sequenceId = 1; IList keyValuesPackageChuncks = (ClusteredArrayList)Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(resultSet.SearchEntriesResult); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse(); searchEntriesResponse.queryResultSet = new Alachisoft.NCache.Common.Protobuf.QueryResultSet(); response.requestId = requestId; response.commandID = commandID; searchEntriesResponse.queryResultSet.queryType = Alachisoft.NCache.Common.Protobuf.QueryType.SEARCH_ENTRIES; response.numberOfChuncks = keyValuesPackageChuncks.Count; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES; foreach (Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse package in keyValuesPackageChuncks) { response.sequenceId = sequenceId++; searchEntriesResponse.queryResultSet.searchKeyEnteriesResult = package; response.searchEntries = searchEntriesResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } if (resultSet != null && resultSet.SearchEntriesResult != null) { resultCount = resultSet.SearchEntriesResult.Count; } } break; case QueryType.GroupByAggregateFunction: { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse(); searchEntriesResponse.queryResultSet = new Alachisoft.NCache.Common.Protobuf.QueryResultSet(); searchEntriesResponse.queryResultSet.queryType = Alachisoft.NCache.Common.Protobuf.QueryType.GROUPBY_AGGREGATE_FUNCTIONS; Common.Protobuf.RecordSet groupByResult = new Common.Protobuf.RecordSet(); searchEntriesResponse.queryResultSet.groupByAggregateFunctionResult = groupByResult; response.requestId = requestId; response.commandID = commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES; response.searchEntries = searchEntriesResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); resultCount = 1; } break; } } break; default: { throw new Exception("Unsupported Command Version " + commandVersion); } } } catch (Exception ex) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error(ex.ToString()); if (resultSet == null) { SocketServer.Logger.NCacheLog.Error("QueryResultSet is null"); } else if (resultSet.AggregateFunctionResult.Key == null) { SocketServer.Logger.NCacheLog.Error("QueryResultSet.AggregateFunctionResult.Key is null"); } else if (resultSet.AggregateFunctionResult.Value == null) { SocketServer.Logger.NCacheLog.Error("QueryResultSet.AggregateFunctionResult.Value is null"); } } throw; } }
protected CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager, string cacheId) { CommandInfo cmdInfo = new CommandInfo(); int packageSize = 0; int index = 0; string version = string.Empty; NCache nCache = clientManager.CmdExecuter as NCache; Caching.Cache cache = nCache.Cache; Hashtable queryInfoHashtable = null; Hashtable tagHashtable = null; Hashtable namedTagHashtable = null; switch (command.type) { case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD_BULK: Alachisoft.NCache.Common.Protobuf.BulkAddCommand bulkAddCommand = command.bulkAddCommand; packageSize = bulkAddCommand.addCommand.Count; cmdInfo.Keys = new string[packageSize]; cmdInfo.Entries = new CacheEntry[packageSize]; cmdInfo.OnDsItemsAddedCallback = (short)bulkAddCommand.datasourceItemAddedCallbackId; cmdInfo.ProviderName = bulkAddCommand.providerName.Length == 0 ? null : bulkAddCommand.providerName; cmdInfo.RequestId = bulkAddCommand.requestId.ToString(); cmdInfo.ClientLastViewId = command.clientLastViewId; cmdInfo.IntendedRecipient = command.intendedRecipient; cmdInfo.returnVersion = bulkAddCommand.returnVersions; foreach (Alachisoft.NCache.Common.Protobuf.AddCommand addCommand in bulkAddCommand.addCommand) { cmdInfo.Keys[index] = addCommand.key; cmdInfo.ClientID = addCommand.clientID; if (index == 0) { cmdInfo.Flag = new BitSet((byte)addCommand.flag); } object value = cache.SocketServerDataService.GetCacheData(addCommand.data.ToArray(), cmdInfo.Flag); cmdInfo.Entries[index] = new CacheEntry(value, Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(cache.Configuration.ExpirationPolicy, addCommand.dependency, addCommand.absExpiration, addCommand.sldExpiration, addCommand.isResync, serailizationContext), new PriorityEvictionHint((CacheItemPriority)addCommand.priority)); CallbackEntry cbEntry = null; if ((short)addCommand.updateCallbackId != -1 || (short)addCommand.removeCallbackId != -1 || cmdInfo.OnDsItemsAddedCallback != -1) { cbEntry = new CallbackEntry(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), value, (short)addCommand.removeCallbackId, (short)addCommand.updateCallbackId, (short)(cmdInfo.RequestId.Equals("-1") ? -1 : 0), cmdInfo.OnDsItemsAddedCallback, new BitSet((byte)addCommand.flag), (EventDataFilter)(addCommand.updateDataFilter != -1 ? (int)addCommand.updateDataFilter : (int)EventDataFilter.None), (EventDataFilter)(addCommand.removeDataFilter != -1 ? (int)addCommand.removeDataFilter : (int)EventDataFilter.DataWithMetadata) ); cmdInfo.Entries[index].Value = cbEntry.Clone(); } cmdInfo.onUpdateCallbackId = (short)addCommand.updateCallbackId; if (addCommand.group != null) { cmdInfo.Group = addCommand.group.Length == 0 ? null : addCommand.group; } if (addCommand.subGroup != null) { cmdInfo.SubGroup = addCommand.subGroup.Length == 0 ? null : addCommand.subGroup; } if (!String.IsNullOrEmpty(cmdInfo.Group)) { cmdInfo.Entries[index].GroupInfo = new GroupInfo(cmdInfo.Group, cmdInfo.SubGroup); } version = command.version; if (string.IsNullOrEmpty(version)) { queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(addCommand.queryInfo); tagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromTagInfoObj(addCommand.tagInfo); if (clientManager.IsDotNetClient) { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromDotNet(addCommand.namedTagInfo); } else { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromJava(addCommand.namedTagInfo); } } else { ObjectQueryInfo objectQueryInfo = addCommand.objectQueryInfo; queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(objectQueryInfo.queryInfo); tagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromTagInfoObj(objectQueryInfo.tagInfo); if (clientManager.IsDotNetClient) { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromDotNet(objectQueryInfo.namedTagInfo); } else { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromJava(objectQueryInfo.namedTagInfo); } } if (queryInfoHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("query-info", queryInfoHashtable); } if (tagHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("tag-info", tagHashtable); } if (namedTagHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("named-tag-info", namedTagHashtable); } cmdInfo.Entries[index].SyncDependency = base.GetCacheSyncDependencyObj(addCommand.syncDependency); index++; } break; case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT_BULK: Alachisoft.NCache.Common.Protobuf.BulkInsertCommand bulkInsertCommand = command.bulkInsertCommand; packageSize = bulkInsertCommand.insertCommand.Count; cmdInfo.Keys = new string[packageSize]; cmdInfo.Entries = new CacheEntry[packageSize]; cmdInfo.OnDsItemsAddedCallback = (short)bulkInsertCommand.datasourceUpdatedCallbackId; cmdInfo.ProviderName = bulkInsertCommand.providerName.Length == 0 ? null : bulkInsertCommand.providerName; cmdInfo.RequestId = bulkInsertCommand.requestId.ToString(); cmdInfo.ClientLastViewId = command.clientLastViewId; cmdInfo.IntendedRecipient = command.intendedRecipient; cmdInfo.returnVersion = bulkInsertCommand.returnVersions; foreach (Alachisoft.NCache.Common.Protobuf.InsertCommand insertCommand in bulkInsertCommand.insertCommand) { cmdInfo.Keys[index] = insertCommand.key; cmdInfo.ClientID = insertCommand.clientID; if (index == 0) { cmdInfo.Flag = new BitSet((byte)insertCommand.flag); } object value = cache.SocketServerDataService.GetCacheData(insertCommand.data.ToArray(), cmdInfo.Flag); cmdInfo.Entries[index] = new CacheEntry(value, Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(cache.Configuration.ExpirationPolicy, insertCommand.dependency, insertCommand.absExpiration, insertCommand.sldExpiration, insertCommand.isResync, serailizationContext), new PriorityEvictionHint((CacheItemPriority)insertCommand.priority)); CallbackEntry cbEntry = null; if (insertCommand.updateCallbackId != -1 || insertCommand.removeCallbackId != -1 || cmdInfo.OnDsItemsAddedCallback != -1) { cbEntry = new CallbackEntry(!string.IsNullOrEmpty(cmdInfo.ClientID) ? cmdInfo.ClientID : clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), value, (short)insertCommand.removeCallbackId, (short)insertCommand.updateCallbackId, (short)(cmdInfo.RequestId.Equals("-1") ? -1 : 0), cmdInfo.OnDsItemsAddedCallback, new BitSet((byte)insertCommand.flag), (EventDataFilter)(insertCommand.updateDataFilter != -1 ? (int)insertCommand.updateDataFilter : (int)EventDataFilter.None), (EventDataFilter)(insertCommand.removeDataFilter != -1 ? (int)insertCommand.removeDataFilter : (int)EventDataFilter.None) ); cmdInfo.Entries[index].Value = cbEntry.Clone(); } cmdInfo.onUpdateCallbackId = (short)insertCommand.updateCallbackId; if (insertCommand.group != null) { cmdInfo.Group = insertCommand.group.Length == 0 ? null : insertCommand.group; } if (insertCommand.subGroup != null) { cmdInfo.SubGroup = insertCommand.subGroup.Length == 0 ? null : insertCommand.subGroup; } if (!String.IsNullOrEmpty(cmdInfo.Group)) { cmdInfo.Entries[index].GroupInfo = new GroupInfo(cmdInfo.Group, cmdInfo.SubGroup); } version = command.version; if (string.IsNullOrEmpty(version)) { queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(insertCommand.queryInfo); tagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromTagInfoObj(insertCommand.tagInfo); if (clientManager.IsDotNetClient) { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromDotNet(insertCommand.namedTagInfo); } else { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromJava(insertCommand.namedTagInfo); } } else { ObjectQueryInfo objectQueryInfo = insertCommand.objectQueryInfo; queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(objectQueryInfo.queryInfo); tagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromTagInfoObj(objectQueryInfo.tagInfo); if (clientManager.IsDotNetClient) { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromDotNet(objectQueryInfo.namedTagInfo); } else { namedTagHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromNamedTagInfoObjFromJava(objectQueryInfo.namedTagInfo); } } if (queryInfoHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("query-info", queryInfoHashtable); } if (tagHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("tag-info", tagHashtable); } if (namedTagHashtable != null) { if (cmdInfo.Entries[index].QueryInfo == null) { cmdInfo.Entries[index].QueryInfo = new Hashtable(); } cmdInfo.Entries[index].QueryInfo.Add("named-tag-info", namedTagHashtable); } cmdInfo.Entries[index].SyncDependency = base.GetCacheSyncDependencyObj(insertCommand.syncDependency); index++; } break; } return(cmdInfo); }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { Alachisoft.NCache.Common.Protobuf.OpenStreamCommand openStreamCommand = command.openStreamCommand; NCache nCache = clientManager.CmdExecuter as NCache; Caching.Cache cache = nCache.Cache; int overload; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); overload = command.MethodOverload; string lockHandle = null; ExpirationHint expHint = null; try { if (clientManager != null) { expHint = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(cache.Configuration.ExpirationPolicy, openStreamCommand.dependency, openStreamCommand.absoluteExpiration, openStreamCommand.slidingExpiration, false, ((NCache)clientManager.CmdExecuter).CacheId); int pr = (int)openStreamCommand.priority; EvictionHint evictionHint = new PriorityEvictionHint((CacheItemPriority)pr); if (openStreamCommand.group != null) { openStreamCommand.group = openStreamCommand.group.Length == 0 ? null : openStreamCommand.group; } if (openStreamCommand.subGroup != null) { openStreamCommand.subGroup = openStreamCommand.subGroup.Length == 0 ? null : openStreamCommand.subGroup; } lockHandle = ((NCache)clientManager.CmdExecuter).Cache.OpenStream(openStreamCommand.key, (Alachisoft.NCache.Common.Enum.StreamModes)openStreamCommand.streamMode, openStreamCommand.group, openStreamCommand.subGroup, expHint, evictionHint, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); stopWatch.Stop(); } } catch (Exception e) { //PROTOBUF:RESPONSE exception = e.ToString(); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(e, command.requestID, command.commandID)); return; } 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.GetCacheStream.ToLower()); Hashtable expirationHint = log.GetDependencyExpirationAndQueryInfo(expHint, null); log.GenerateOpenStreamAPILogItem(openStreamCommand.key, openStreamCommand.streamMode, openStreamCommand.group, openStreamCommand.subGroup, openStreamCommand.priority, expirationHint["dependency"] != null ? expirationHint["dependency"] as ArrayList : null, expirationHint["absolute-expiration"] != null ? (long)expirationHint["absolute-expiration"] : -1, expirationHint["sliding-expiration"] != null ? (long)expirationHint["sliding-expiration"] : -1, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.OpenStreamResponse openStreamResponse = new Alachisoft.NCache.Common.Protobuf.OpenStreamResponse(); response.requestId = openStreamCommand.requestId; response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.OPEN_STREAM; response.openStreamResponse = openStreamResponse; openStreamResponse.lockHandle = lockHandle; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); }
public static IList BuildResponse(QueryResultSet resultSet, string RequestId, IList _serializedResponse, int commandID, Caching.Cache cache, out int resultCount) { Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.Cache = cache; long requestId = Convert.ToInt64(RequestId); resultCount = 0; try { int sequenceId = 1; Alachisoft.NCache.Common.Protobuf.SearchEntriesCQResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesCQResponse(); searchEntriesResponse.queryResultSet = new Alachisoft.NCache.Common.Protobuf.CQResultSet(); searchEntriesResponse.queryResultSet.CQUniqueId = resultSet.CQUniqueId; searchEntriesResponse.queryResultSet.queryType = Alachisoft.NCache.Common.Protobuf.CQType.SEARCH_CQ_ENTRIES; Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); response.requestId = requestId; response.commandID = commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES_CQ; IList keyValuesPackageChuncks = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(resultSet.SearchEntriesResult); response.numberOfChuncks = keyValuesPackageChuncks.Count; foreach (Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse package in keyValuesPackageChuncks) { response.sequenceId = sequenceId++; searchEntriesResponse.queryResultSet.searchKeyEnteriesResult = package; response.searchEntriesCQResponse = searchEntriesResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } if (resultSet != null && resultSet.SearchEntriesResult != null) { resultCount = resultSet.SearchEntriesResult.Count; } } catch (Exception ex) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error(ex.ToString()); if (resultSet == null) { SocketServer.Logger.NCacheLog.Error("QueryResultSet is null"); } } } return(_serializedResponse); }
public static IList BuildResponse(int removeResult, int commandVersion, string RequestId, IList _serializedResponse, int commandID, Caching.Cache cache) { long requestId = Convert.ToInt64(RequestId); int removedKeyCount = Convert.ToInt32(removeResult); int sequenceId = 1; Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.RemoveQueryResponse removeQueryResponse = new Alachisoft.NCache.Common.Protobuf.RemoveQueryResponse(); response.requestId = requestId; response.commandID = commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.REMOVE_QUERY; { response.sequenceId = sequenceId++; removeQueryResponse.removedKeyCount = removedKeyCount; response.removeQueryResponse = removeQueryResponse; _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } return(_serializedResponse); }
public EventStoreContext(EventStoreConfig config) { _cache = new Caching.Cache("Es", config.CacheMb); _connect = async() => _gateway = await Connect(config); }