public InsertCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, Hashtable queryInfo, BitSet flagMap, object lockId, LockAccessType accessType, string cacheId, EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter) { base.name = "InsertCommand"; base.key = key; _insertCommand = new Alachisoft.NCache.Common.Protobuf.InsertCommand(); _insertCommand.key = key; Alachisoft.NCache.Caching.UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(value); _insertCommand.data.AddRange(ubObject.DataList); _insertCommand.requestId = base.RequestId; _insertCommand.removeCallbackId = removeCallback; _insertCommand.updateCallbackId = updateCallback; _insertCommand.updateDataFilter = (short)updateCallbackFilter; _insertCommand.removeDataFilter = (short)removeCallabackFilter; _insertCommand.priority = (int)priority; _insertCommand.flag = flagMap.Data; if(lockId != null) _insertCommand.lockId = lockId.ToString(); _insertCommand.lockAccessType = (int)accessType; if (absoluteExpiration != Web.Caching.Cache.NoAbsoluteExpiration) _insertCommand.absExpiration = absoluteExpiration.Ticks; if (slidingExpiration != Web.Caching.Cache.NoSlidingExpiration) _insertCommand.sldExpiration = slidingExpiration.Ticks; ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo(); if (queryInfo["query-info"] != null) objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(queryInfo["query-info"] as Hashtable); _insertCommand.objectQueryInfo = objectQueryInfo; }
public InsertCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, Hashtable queryInfo, BitSet flagMap, object lockId, LockAccessType accessType, string cacheId, EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter) { base.name = "InsertCommand"; base.key = key; _insertCommand = new Alachisoft.NCache.Common.Protobuf.InsertCommand(); _insertCommand.key = key; Alachisoft.NCache.Caching.UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(value); _insertCommand.data.AddRange(ubObject.DataList); _insertCommand.requestId = base.RequestId; _insertCommand.removeCallbackId = removeCallback; _insertCommand.updateCallbackId = updateCallback; _insertCommand.updateDataFilter = (short)updateCallbackFilter; _insertCommand.removeDataFilter = (short)removeCallabackFilter; _insertCommand.priority = (int)priority; _insertCommand.flag = flagMap.Data; if (lockId != null) { _insertCommand.lockId = lockId.ToString(); } _insertCommand.lockAccessType = (int)accessType; if (absoluteExpiration != Web.Caching.Cache.NoAbsoluteExpiration) { _insertCommand.absExpiration = absoluteExpiration.Ticks; } if (slidingExpiration != Web.Caching.Cache.NoSlidingExpiration) { _insertCommand.sldExpiration = slidingExpiration.Ticks; } ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo(); if (queryInfo["query-info"] != null) { objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(queryInfo["query-info"] as Hashtable); } _insertCommand.objectQueryInfo = objectQueryInfo; }
public BulkInsertCommand(string[] keys, CacheItem[] items, Cache parent, string cacheId) { base.name = "BulkInsertCommand"; _parent = parent; base.BulkKeys = keys; _bulkInsertCommand = new Alachisoft.NCache.Common.Protobuf.BulkInsertCommand(); _bulkInsertCommand.requestId = base.RequestId; for (int i = 0; i < keys.Length; i++) { CacheItem item = items[i]; _insertCommand = new Alachisoft.NCache.Common.Protobuf.InsertCommand(); _insertCommand.key = keys[i]; Alachisoft.NCache.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject((byte[])item.Value); _insertCommand.data.AddRange(ubObject.DataList); if (item.AbsoluteExpiration != Cache.NoAbsoluteExpiration) { _insertCommand.absExpiration = item.AbsoluteExpiration.Ticks; } if (item.SlidingExpiration != Cache.NoSlidingExpiration) { _insertCommand.sldExpiration = item.SlidingExpiration.Ticks; } _insertCommand.flag = item.FlagMap.Data; _insertCommand.priority = (int)item.Priority; // Updated in Version 4.2 [Dated 20-Nov-2013; Author: Sami] ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo(); if (item.QueryInfo["query-info"] != null) { objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(item.QueryInfo["query-info"] as Hashtable); } _insertCommand.objectQueryInfo = objectQueryInfo; short removeCallbackId = -1; short updateCallbackId = -1; EventDataFilter itemUpdateDataFilter = EventDataFilter.None; EventDataFilter itemRemovedDataFilter = EventDataFilter.None; if (item.CacheItemRemovedCallback != null) { itemRemovedDataFilter = item.ItemRemovedCallabackDataFilter; short[] callabackIds = _parent.EventManager.RegisterSelectiveEvent(item.CacheItemRemovedCallback, EventType.ItemRemoved, itemRemovedDataFilter); removeCallbackId = callabackIds[1]; } if (item.CacheItemUpdatedCallback != null) { itemUpdateDataFilter = item.ItemUpdatedCallabackDataFilter; short[] callabackIds = _parent.EventManager.RegisterSelectiveEvent(item.CacheItemUpdatedCallback, EventType.ItemUpdated, itemUpdateDataFilter); updateCallbackId = callabackIds[0]; } _insertCommand.removeCallbackId = removeCallbackId; _insertCommand.updateCallbackId = updateCallbackId; _insertCommand.updateDataFilter = (short)itemUpdateDataFilter; _insertCommand.removeDataFilter = (short)itemRemovedDataFilter; _bulkInsertCommand.insertCommand.Add(_insertCommand); } }
public BulkInsertCommand(string[] keys, CacheItem[] items, Cache parent, string cacheId) { base.name = "BulkInsertCommand"; _parent = parent; base.BulkKeys = keys; _bulkInsertCommand = new Alachisoft.NCache.Common.Protobuf.BulkInsertCommand(); _bulkInsertCommand.requestId = base.RequestId; for (int i = 0; i < keys.Length; i++) { CacheItem item = items[i]; _insertCommand = new Alachisoft.NCache.Common.Protobuf.InsertCommand(); _insertCommand.key = keys[i]; Alachisoft.NCache.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject((byte[])item.Value); _insertCommand.data.AddRange(ubObject.DataList); if (item.AbsoluteExpiration != Cache.NoAbsoluteExpiration) _insertCommand.absExpiration = item.AbsoluteExpiration.Ticks; if (item.SlidingExpiration != Cache.NoSlidingExpiration) _insertCommand.sldExpiration = item.SlidingExpiration.Ticks; _insertCommand.flag = item.FlagMap.Data; _insertCommand.priority = (int)item.Priority; // Updated in Version 4.2 [Dated 20-Nov-2013; Author: Sami] ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo(); if (item.QueryInfo["query-info"] != null) objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(item.QueryInfo["query-info"] as Hashtable); _insertCommand.objectQueryInfo = objectQueryInfo; short removeCallbackId = -1; short updateCallbackId = -1; EventDataFilter itemUpdateDataFilter = EventDataFilter.None; EventDataFilter itemRemovedDataFilter = EventDataFilter.None; if (item.CacheItemRemovedCallback != null) { itemRemovedDataFilter = item.ItemRemovedCallabackDataFilter; short[] callabackIds = _parent.EventManager.RegisterSelectiveEvent(item.CacheItemRemovedCallback, EventType.ItemRemoved, itemRemovedDataFilter); removeCallbackId = callabackIds[1]; } if (item.CacheItemUpdatedCallback != null) { itemUpdateDataFilter = item.ItemUpdatedCallabackDataFilter; short[] callabackIds = _parent.EventManager.RegisterSelectiveEvent(item.CacheItemUpdatedCallback, EventType.ItemUpdated, itemUpdateDataFilter); updateCallbackId = callabackIds[0]; } _insertCommand.removeCallbackId = removeCallbackId; _insertCommand.updateCallbackId = updateCallbackId; _insertCommand.updateDataFilter = (short)itemUpdateDataFilter; _insertCommand.removeDataFilter = (short)itemRemovedDataFilter; _bulkInsertCommand.insertCommand.Add(_insertCommand); } }
//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); }
//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); }
//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; string version = string.Empty; switch (command.type) { case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD: Alachisoft.NCache.Common.Protobuf.AddCommand addCommand = command.addCommand; cmdInfo.Key = addCommand.key; cmdInfo.EvictionHint = new PriorityEvictionHint((CacheItemPriority)addCommand.priority); cmdInfo.ExpirationHint = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(addCommand.absExpiration, addCommand.sldExpiration, serializationContext); cmdInfo.Flag = new BitSet((byte)addCommand.flag); cmdInfo.queryInfo = new Hashtable(); version = command.version; //version added in 4.2 [Dated: 18-Nov-2013; Author: Sami] if (string.IsNullOrEmpty(version)) { queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(addCommand.queryInfo); } else { ObjectQueryInfo objectQueryInfo; objectQueryInfo = addCommand.objectQueryInfo; queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(objectQueryInfo.queryInfo); } 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 = (int)addCommand.removeDataFilter; } else { cmdInfo.RemoveDataFilter = (int)Runtime.Events.EventDataFilter.DataWithMetadata; } cmdInfo.RequestId = addCommand.requestId.ToString(); cmdInfo.UpdateCallbackId = (short)addCommand.updateCallbackId; if (addCommand.updateDataFilter != -1) { cmdInfo.UpdateDataFilter = addCommand.updateDataFilter; } else { cmdInfo.UpdateDataFilter = (int)Runtime.Events.EventDataFilter.None; } cmdInfo.value = UserBinaryObject.CreateUserBinaryObject(addCommand.data.ToArray()); break; case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT: Alachisoft.NCache.Common.Protobuf.InsertCommand insertCommand = command.insertCommand; cmdInfo.Key = insertCommand.key; cmdInfo.EvictionHint = new PriorityEvictionHint((CacheItemPriority)insertCommand.priority); cmdInfo.ExpirationHint = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetExpirationHintObj(insertCommand.absExpiration, insertCommand.sldExpiration, serializationContext); cmdInfo.Flag = new BitSet((byte)insertCommand.flag); version = command.version; //version added in 4.2 [Dated: 18-Nov-2013; Author: Sami] if (string.IsNullOrEmpty(version)) { queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(insertCommand.queryInfo); } else { ObjectQueryInfo objectQueryInfo; objectQueryInfo = insertCommand.objectQueryInfo; queryInfoHashtable = Alachisoft.NCache.Caching.Util.ProtobufHelper.GetHashtableFromQueryInfoObj(objectQueryInfo.queryInfo); } if (queryInfoHashtable != null) { if (cmdInfo.queryInfo == null) { cmdInfo.queryInfo = new Hashtable(); } cmdInfo.queryInfo.Add("query-info", queryInfoHashtable); } 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.UpdateCallbackId = (short)insertCommand.updateCallbackId; if (insertCommand.updateDataFilter != -1) { cmdInfo.UpdateDataFilter = insertCommand.updateDataFilter; } else { cmdInfo.UpdateDataFilter = (int)Runtime.Events.EventDataFilter.None; } cmdInfo.LockAccessType = (LockAccessType)insertCommand.lockAccessType; cmdInfo.LockId = insertCommand.lockId; cmdInfo.value = UserBinaryObject.CreateUserBinaryObject(insertCommand.data.ToArray()); break; } return(cmdInfo); }
public InsertCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, short dsItemsUpdateCallbackId, bool isResyncExpiredItems, short itemUpdated, bool isAsync, Hashtable queryInfo, BitSet flagMap, object lockId, ulong version, LockAccessType accessType, string providerName, string resyncProviderName, bool encryption, string cacheId, EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter, int methodOverload, string clientId, string typeName, CallbackType callbackType = Runtime.Events.CallbackType.PushBasedNotification) { base.name = "InsertCommand"; base.asyncCallbackSpecified = isAsync && itemUpdated != -1 ? true : false; base.isAsync = isAsync; base.key = key; _itemUpdated = itemUpdated; _insertCommand = new Alachisoft.NCache.Common.Protobuf.InsertCommand(); _insertCommand.key = key; Alachisoft.NCache.Common.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Common.Caching.UserBinaryObject.CreateUserBinaryObject(value); _insertCommand.data.AddRange(ubObject.DataList); _methodOverload = methodOverload; _insertCommand.requestId = base.RequestId; _insertCommand.removeCallbackId = removeCallback; _insertCommand.updateCallbackId = updateCallback; _insertCommand.updateDataFilter = (short)updateCallbackFilter; _insertCommand.removeDataFilter = (short)removeCallabackFilter; _insertCommand.datasourceUpdatedCallbackId = dsItemsUpdateCallbackId; _insertCommand.isAsync = isAsync; _insertCommand.priority = (int)priority; _insertCommand.flag = flagMap.Data; _insertCommand.itemVersion = version; if (lockId != null) { _insertCommand.lockId = lockId.ToString(); } _insertCommand.lockAccessType = (int)accessType == 0 ? (int)LockAccessType.IGNORE_LOCK : (int)accessType; _insertCommand.providerName = providerName; _insertCommand.resyncProviderName = resyncProviderName; // Client ID: Must not have value except ClientCache. _insertCommand.clientID = clientId; _insertCommand.CallbackType = CallbackType(callbackType); if (absoluteExpiration.Equals(Cache.DefaultAbsolute.ToUniversalTime())) { _insertCommand.absExpiration = 1; } else if (absoluteExpiration.Equals(Cache.DefaultAbsoluteLonger.ToUniversalTime())) { _insertCommand.absExpiration = 2; } else if (absoluteExpiration != Cache.NoAbsoluteExpiration) { _insertCommand.absExpiration = absoluteExpiration.Ticks; } if (slidingExpiration.Equals(Cache.DefaultSliding)) { _insertCommand.sldExpiration = 1; } else if (slidingExpiration.Equals(Cache.DefaultSlidingLonger)) { _insertCommand.sldExpiration = 2; } else if (slidingExpiration != Cache.NoSlidingExpiration) { _insertCommand.sldExpiration = slidingExpiration.Ticks; } _insertCommand.isResync = isResyncExpiredItems; }
public InsertCommand(string key, byte[] value, CacheDependency dependency, CacheSyncDependency syncDependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, short dsItemsUpdateCallbackId, bool isResyncExpiredItems, string group, string subGroup, short itemUpdated, bool isAsync, Hashtable queryInfo, BitSet flagMap, object lockId, ulong version, LockAccessType accessType, string providerName, string resyncProviderName, string cacheId, EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter, int methodOverload, string clientId, CallbackType callbackType = Runtime.Events.CallbackType.PushBasedNotification) { base.name = "InsertCommand"; base.asyncCallbackSpecified = isAsync && itemUpdated != -1 ? true : false; base.isAsync = isAsync; base.key = key; _itemUpdated = itemUpdated; _insertCommand = new Alachisoft.NCache.Common.Protobuf.InsertCommand(); _insertCommand.key = key; Alachisoft.NCache.Caching.UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(value); _insertCommand.data.AddRange(ubObject.DataList); _methodOverload = methodOverload; _insertCommand.requestId = base.RequestId; _insertCommand.removeCallbackId = removeCallback; _insertCommand.updateCallbackId = updateCallback; _insertCommand.updateDataFilter = (short)updateCallbackFilter; _insertCommand.removeDataFilter = (short)removeCallabackFilter; _insertCommand.datasourceUpdatedCallbackId = dsItemsUpdateCallbackId; _insertCommand.isAsync = isAsync; _insertCommand.priority = (int)priority; _insertCommand.flag = flagMap.Data; _insertCommand.itemVersion = version; if (lockId != null) { _insertCommand.lockId = lockId.ToString(); } _insertCommand.lockAccessType = (int)accessType; _insertCommand.providerName = providerName; _insertCommand.resyncProviderName = resyncProviderName; _insertCommand.clientID = clientId; _insertCommand.CallbackType = CallbackType(callbackType); if (syncDependency != null) { _insertCommand.syncDependency = new Alachisoft.NCache.Common.Protobuf.SyncDependency(); _insertCommand.syncDependency.cacheId = syncDependency.CacheId; _insertCommand.syncDependency.key = syncDependency.Key; _insertCommand.syncDependency.server = syncDependency.Server; _insertCommand.syncDependency.port = syncDependency.Port; } if (absoluteExpiration.Equals(Caching.Cache.DefaultAbsolute.ToUniversalTime())) { _insertCommand.absExpiration = 1; } else if (absoluteExpiration.Equals(Caching.Cache.DefaultAbsoluteLonger.ToUniversalTime())) { _insertCommand.absExpiration = 2; } else if (absoluteExpiration != Caching.Cache.NoAbsoluteExpiration) { _insertCommand.absExpiration = absoluteExpiration.Ticks; } if (slidingExpiration.Equals(Caching.Cache.DefaultSliding)) { _insertCommand.sldExpiration = 1; } else if (slidingExpiration.Equals(Caching.Cache.DefaultSlidingLonger)) { _insertCommand.sldExpiration = 2; } else if (slidingExpiration != Caching.Cache.NoSlidingExpiration) { _insertCommand.sldExpiration = slidingExpiration.Ticks; } _insertCommand.isResync = isResyncExpiredItems; _insertCommand.group = group; _insertCommand.subGroup = subGroup; ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo(); if (queryInfo["query-info"] != null) { objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(queryInfo["query-info"] as Hashtable); } if (queryInfo["tag-info"] != null) { objectQueryInfo.tagInfo = ProtobufHelper.GetTagInfoObj(queryInfo["tag-info"] as Hashtable); } if (queryInfo["named-tag-info"] != null) { objectQueryInfo.namedTagInfo = ProtobufHelper.GetNamedTagInfoObj(queryInfo["named-tag-info"] as Hashtable, true); } _insertCommand.objectQueryInfo = objectQueryInfo; if (dependency != null) { _insertCommand.dependency = Alachisoft.NCache.Common.Util.DependencyHelper.GetProtoBufDependency(dependency); } }
public BulkInsertCommand(string[] keys, CacheItem[] items, short onDataSourceItemUpdateCallbackId, Alachisoft.NCache.Web.Caching.Cache parent, string providerName, string cacheId, int methodOverload, string clientId, short updateCallbackId, short removeCallbackId, EventDataFilter updateCallbackDataFilter, EventDataFilter removeCallbackDataFilter, bool returnVersions, CallbackType callbackType = Runtime.Events.CallbackType.PushBasedNotification) { base.name = "BulkInsertCommand"; _parent = parent; base.BulkKeys = keys; _bulkInsertCommand = new Alachisoft.NCache.Common.Protobuf.BulkInsertCommand(); _bulkInsertCommand.datasourceUpdatedCallbackId = onDataSourceItemUpdateCallbackId; _bulkInsertCommand.providerName = providerName; _bulkInsertCommand.returnVersions = returnVersions; _bulkInsertCommand.requestId = base.RequestId; _methodOverload = methodOverload; for (int i = 0; i < keys.Length; i++) { CacheItem item = items[i]; _insertCommand = new Alachisoft.NCache.Common.Protobuf.InsertCommand(); _insertCommand.key = keys[i]; Alachisoft.NCache.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject((byte[])item.Value); _insertCommand.data.AddRange(ubObject.DataList); if (item.AbsoluteExpiration.Equals(Caching.Cache.DefaultAbsolute.ToUniversalTime())) { _insertCommand.absExpiration = 1; } else if (item.AbsoluteExpiration.Equals(Caching.Cache.DefaultAbsoluteLonger.ToUniversalTime())) { _insertCommand.absExpiration = 2; } else if (item.AbsoluteExpiration != Caching.Cache.NoAbsoluteExpiration) { _insertCommand.absExpiration = item.AbsoluteExpiration.Ticks; } if (item.SlidingExpiration.Equals(Caching.Cache.DefaultSliding)) { _insertCommand.sldExpiration = 1; } else if (item.SlidingExpiration.Equals(Caching.Cache.DefaultSlidingLonger)) { _insertCommand.sldExpiration = 2; } else if (item.SlidingExpiration != Caching.Cache.NoSlidingExpiration) { _insertCommand.sldExpiration = item.SlidingExpiration.Ticks; } _insertCommand.flag = item.FlagMap.Data; _insertCommand.group = item.Group; _insertCommand.subGroup = item.SubGroup; _insertCommand.isResync = item.IsResyncExpiredItems; _insertCommand.priority = (int)item.Priority; _insertCommand.dependency = item.Dependency == null ? null : Alachisoft.NCache.Common.Util.DependencyHelper.GetProtoBufDependency(item.Dependency); _insertCommand.clientID = clientId; _insertCommand.CallbackType = CallbackType(callbackType); ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo(); if (item.QueryInfo["query-info"] != null) { objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(item.QueryInfo["query-info"] as Hashtable); } if (item.QueryInfo["tag-info"] != null) { objectQueryInfo.tagInfo = ProtobufHelper.GetTagInfoObj(item.QueryInfo["tag-info"] as Hashtable); } if (item.QueryInfo["named-tag-info"] != null) { objectQueryInfo.namedTagInfo = ProtobufHelper.GetNamedTagInfoObj(item.QueryInfo["named-tag-info"] as Hashtable, true); } _insertCommand.objectQueryInfo = objectQueryInfo; EventDataFilter itemUpdateDataFilter = updateCallbackDataFilter; EventDataFilter itemRemovedDataFilter = removeCallbackDataFilter; if (item.CacheItemRemovedCallback != null) { itemRemovedDataFilter = item.ItemRemovedCallabackDataFilter; short[] callabackIds = _parent.EventManager.RegisterSelectiveEvent(item.CacheItemRemovedCallback, EventType.ItemRemoved, itemRemovedDataFilter); removeCallbackId = callabackIds[1]; } else if (item.ItemRemoveCallback != null) { removeCallbackId = _parent.GetCallbackId(item.ItemRemoveCallback); itemRemovedDataFilter = EventDataFilter.DataWithMetadata; } if (item.CacheItemUpdatedCallback != null) { itemUpdateDataFilter = item.ItemUpdatedCallabackDataFilter; short[] callabackIds = _parent.EventManager.RegisterSelectiveEvent(item.CacheItemUpdatedCallback, EventType.ItemUpdated, itemUpdateDataFilter); updateCallbackId = callabackIds[0]; } else if (item.ItemUpdateCallback != null) { updateCallbackId = _parent.GetCallbackId(item.ItemUpdateCallback); itemUpdateDataFilter = EventDataFilter.None; } _insertCommand.removeCallbackId = removeCallbackId; _insertCommand.updateCallbackId = updateCallbackId; _insertCommand.updateDataFilter = (short)itemUpdateDataFilter; _insertCommand.removeDataFilter = (short)itemRemovedDataFilter; _insertCommand.resyncProviderName = item.ResyncProviderName; if (item.SyncDependency != null) { _insertCommand.syncDependency = new Alachisoft.NCache.Common.Protobuf.SyncDependency(); _insertCommand.syncDependency.key = item.SyncDependency.Key; _insertCommand.syncDependency.cacheId = item.SyncDependency.CacheId; _insertCommand.syncDependency.server = item.SyncDependency.Server; _insertCommand.syncDependency.port = item.SyncDependency.Port; } _bulkInsertCommand.insertCommand.Add(_insertCommand); } }