Esempio n. 1
0
        internal AddCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, Hashtable queryInfo, BitSet flagMap, string cacheId,EventDataFilter updateDataFilter,EventDataFilter removeDataFilter)
        {
            base.name = "AddCommand";
            base.key = key;

            _addCommand = new Alachisoft.NCache.Common.Protobuf.AddCommand();

            if (absoluteExpiration != Cache.NoAbsoluteExpiration)
                _addCommand.absExpiration = absoluteExpiration.Ticks;

            if (slidingExpiration != Cache.NoSlidingExpiration)
                _addCommand.sldExpiration = slidingExpiration.Ticks;

            Alachisoft.NCache.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject(value);

            _addCommand.key = key;
            _addCommand.data.AddRange(ubObject.DataList);
            _addCommand.requestId = base.RequestId;
            _addCommand.updateCallbackId = updateCallback;
            _addCommand.removeCallbackId = removeCallback;
            _addCommand.priority = (int)priority;
            _addCommand.flag = flagMap.Data;
            _addCommand.updateDataFilter = (short)updateDataFilter;
            _addCommand.removeDataFilter = (short)removeDataFilter;

            // Changes made to send Queries, Tags and NamgedTags in a single object
            ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo();

            if (queryInfo["query-info"] != null)
                objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(queryInfo["query-info"] as Hashtable);

                _addCommand.objectQueryInfo = objectQueryInfo;
        }
Esempio n. 2
0
        internal AddCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, short dsItemAddedCallback, bool isResyncExpiredItems, short itemAdded, bool isAsync, Hashtable queryInfo, BitSet flagMap, string providerName, string resyncProviderName, bool encryption, string cacheId, EventDataFilter updateDataFilter, EventDataFilter removeDataFilter, int methodOverload, string clientId, string typeName)
        {
            base.name = "AddCommand";
            base.asyncCallbackSpecified = isAsync && itemAdded != -1 ? true : false;
            base.isAsync = isAsync;
            base.key     = key;

            _itemAdded = itemAdded;

            _addCommand = new Alachisoft.NCache.Common.Protobuf.AddCommand();

            if (absoluteExpiration.Equals(Cache.DefaultAbsolute.ToUniversalTime()))
            {
                _addCommand.absExpiration = 1;
            }
            else if (absoluteExpiration.Equals(Cache.DefaultAbsoluteLonger.ToUniversalTime()))
            {
                _addCommand.absExpiration = 2;
            }
            else if (absoluteExpiration != Cache.NoAbsoluteExpiration)
            {
                _addCommand.absExpiration = absoluteExpiration.Ticks;
            }

            if (slidingExpiration.Equals(Cache.DefaultSliding))
            {
                _addCommand.sldExpiration = 1;
            }
            else if (slidingExpiration.Equals(Cache.DefaultSlidingLonger))
            {
                _addCommand.sldExpiration = 2;
            }
            else if (slidingExpiration != Cache.NoSlidingExpiration)
            {
                _addCommand.sldExpiration = slidingExpiration.Ticks;
            }

            UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(value);

            _addCommand.key = key;
            _addCommand.data.AddRange(ubObject.DataList);
            _addCommand.requestId        = base.RequestId;
            _addCommand.updateCallbackId = updateCallback;
            _addCommand.removeCallbackId = removeCallback;
            _addCommand.datasourceItemAddedCallbackId = dsItemAddedCallback;
            _addCommand.isAsync            = isAsync;
            _addCommand.priority           = (int)priority;
            _addCommand.isResync           = isResyncExpiredItems;
            _addCommand.flag               = flagMap.Data;
            _addCommand.providerName       = providerName;
            _addCommand.resyncProviderName = resyncProviderName;
            _addCommand.updateDataFilter   = (short)updateDataFilter;
            _addCommand.removeDataFilter   = (short)removeDataFilter;

            // Client ID: Must not have value except ClientCache.
            _addCommand.clientID = clientId;
            _methodOverload      = methodOverload;
        }
Esempio n. 3
0
        internal AddCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, Hashtable queryInfo, BitSet flagMap, string cacheId, EventDataFilter updateDataFilter, EventDataFilter removeDataFilter)
        {
            base.name = "AddCommand";
            base.key  = key;


            _addCommand = new Alachisoft.NCache.Common.Protobuf.AddCommand();

            if (absoluteExpiration != Cache.NoAbsoluteExpiration)
            {
                _addCommand.absExpiration = absoluteExpiration.Ticks;
            }

            if (slidingExpiration != Cache.NoSlidingExpiration)
            {
                _addCommand.sldExpiration = slidingExpiration.Ticks;
            }

            Alachisoft.NCache.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject(value);

            _addCommand.key = key;
            _addCommand.data.AddRange(ubObject.DataList);
            _addCommand.requestId        = base.RequestId;
            _addCommand.updateCallbackId = updateCallback;
            _addCommand.removeCallbackId = removeCallback;
            _addCommand.priority         = (int)priority;
            _addCommand.flag             = flagMap.Data;
            _addCommand.updateDataFilter = (short)updateDataFilter;
            _addCommand.removeDataFilter = (short)removeDataFilter;

            // Changes made to send Queries, Tags and NamgedTags in a single object
            ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo();

            if (queryInfo["query-info"] != null)
            {
                objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(queryInfo["query-info"] as Hashtable);
            }


            _addCommand.objectQueryInfo = objectQueryInfo;
        }
Esempio n. 4
0
        internal AddCommand(string key, byte[] value, CacheDependency dependency, CacheSyncDependency syncDependency,
                            DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback,
                            short updateCallback, short dsItemAddedCallback, bool isResyncExpiredItems, string group, string subGroup,
                            short itemAdded, bool isAsync, Hashtable queryInfo, BitSet flagMap, string providerName,
                            string resyncProviderName, string cacheId, EventDataFilter updateDataFilter,
                            EventDataFilter removeDataFilter, int methodOverload, string clientId)
        {
            base.name = "AddCommand";
            base.asyncCallbackSpecified = isAsync && itemAdded != -1 ? true : false;
            base.isAsync = isAsync;
            base.key     = key;

            _itemAdded = itemAdded;


            _addCommand = new Alachisoft.NCache.Common.Protobuf.AddCommand();

            if (absoluteExpiration.Equals(Caching.Cache.DefaultAbsolute.ToUniversalTime()))
            {
                _addCommand.absExpiration = 1;
            }
            else if (absoluteExpiration.Equals(Caching.Cache.DefaultAbsoluteLonger.ToUniversalTime()))
            {
                _addCommand.absExpiration = 2;
            }
            else if (absoluteExpiration != Caching.Cache.NoAbsoluteExpiration)
            {
                _addCommand.absExpiration = absoluteExpiration.Ticks;
            }

            if (slidingExpiration.Equals(Caching.Cache.DefaultSliding))
            {
                _addCommand.sldExpiration = 1;
            }
            else if (slidingExpiration.Equals(Caching.Cache.DefaultSlidingLonger))
            {
                _addCommand.sldExpiration = 2;
            }
            else if (slidingExpiration != Caching.Cache.NoSlidingExpiration)
            {
                _addCommand.sldExpiration = slidingExpiration.Ticks;
            }
            Alachisoft.NCache.Caching.UserBinaryObject ubObject =
                Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject(value);

            _addCommand.key = key;
            _addCommand.data.AddRange(ubObject.DataList);
            _addCommand.requestId        = base.RequestId;
            _addCommand.updateCallbackId = updateCallback;
            _addCommand.removeCallbackId = removeCallback;
            _addCommand.datasourceItemAddedCallbackId = dsItemAddedCallback;
            _addCommand.isAsync            = isAsync;
            _addCommand.priority           = (int)priority;
            _addCommand.isResync           = isResyncExpiredItems;
            _addCommand.group              = group;
            _addCommand.subGroup           = subGroup;
            _addCommand.flag               = flagMap.Data;
            _addCommand.providerName       = providerName;
            _addCommand.resyncProviderName = resyncProviderName;
            _addCommand.updateDataFilter   = (short)updateDataFilter;
            _addCommand.removeDataFilter   = (short)removeDataFilter;

            _addCommand.clientID = clientId;

            if (syncDependency != null)
            {
                _addCommand.syncDependency         = new SyncDependency();
                _addCommand.syncDependency.cacheId = syncDependency.CacheId;
                _addCommand.syncDependency.key     = syncDependency.Key;
                _addCommand.syncDependency.server  = syncDependency.Server;
                _addCommand.syncDependency.port    = syncDependency.Port;
            }

            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);
            }


            _addCommand.objectQueryInfo = objectQueryInfo;

            if (dependency != null)
            {
                _addCommand.dependency =
                    Alachisoft.NCache.Common.Util.DependencyHelper.GetProtoBufDependency(dependency);
            }
            _methodOverload = methodOverload;
        }
Esempio n. 5
0
        public BulkAddCommand(string[] keys, CacheItem[] items, Cache parent, string cacheId)
        {
            base.name = "BulkAddCommand";
            _parent   = parent;

            _bulkAddCommand           = new Alachisoft.NCache.Common.Protobuf.BulkAddCommand();
            _bulkAddCommand.requestId = base.RequestId;
            base.BulkKeys             = keys;

            for (int i = 0; i < keys.Length; i++)
            {
                CacheItem item = items[i];

                _addCommand     = new Alachisoft.NCache.Common.Protobuf.AddCommand();
                _addCommand.key = keys[i];

                Alachisoft.NCache.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject((byte[])item.Value);
                _addCommand.data.AddRange(ubObject.DataList);

                if (item.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                {
                    _addCommand.absExpiration = item.AbsoluteExpiration.Ticks;
                }

                if (item.SlidingExpiration != Cache.NoSlidingExpiration)
                {
                    _addCommand.sldExpiration = item.SlidingExpiration.Ticks;
                }

                _addCommand.flag = item.FlagMap.Data;

                _addCommand.priority = (int)item.Priority;

                ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo();

                if (item.QueryInfo["query-info"] != null)
                {
                    objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(item.QueryInfo["query-info"] as Hashtable);
                }

                _addCommand.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];
                }


                _addCommand.removeCallbackId = removeCallbackId;
                _addCommand.updateCallbackId = updateCallbackId;
                _addCommand.updateDataFilter = (short)itemUpdateDataFilter;
                _addCommand.removeDataFilter = (short)itemRemovedDataFilter;

                _bulkAddCommand.addCommand.Add(_addCommand);
            }
        }
Esempio n. 6
0
        //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);
        }
Esempio n. 7
0
        public BulkAddCommand(string[] keys, CacheItem[] items, short onDsItemsAddedCallback,
                              Alachisoft.NCache.Web.Caching.Cache parent, string providerName, string cacheId, int methodOverload,
                              string clientId, short updateCallbackId, short removedCallbackId, EventDataFilter updateCallbackFilter,
                              EventDataFilter removeCallabackFilter, bool returnVersions,
                              CallbackType callbackType = Runtime.Events.CallbackType.PushBasedNotification)
        {
            base.name       = "BulkAddCommand";
            _parent         = parent;
            _methodOverload = methodOverload;
            _bulkAddCommand = new Alachisoft.NCache.Common.Protobuf.BulkAddCommand();
            _bulkAddCommand.datasourceItemAddedCallbackId = onDsItemsAddedCallback;
            _bulkAddCommand.providerName   = providerName;
            _bulkAddCommand.returnVersions = returnVersions;
            _bulkAddCommand.requestId      = base.RequestId;
            base.BulkKeys = keys;

            for (int i = 0; i < keys.Length; i++)
            {
                CacheItem item = items[i];

                _addCommand     = new Alachisoft.NCache.Common.Protobuf.AddCommand();
                _addCommand.key = keys[i];

                Alachisoft.NCache.Caching.UserBinaryObject ubObject =
                    Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject((byte[])item.Value);
                _addCommand.data.AddRange(ubObject.DataList);

                if (item.AbsoluteExpiration.Equals(Caching.Cache.DefaultAbsolute.ToUniversalTime()))
                {
                    _addCommand.absExpiration = 1;
                }
                else if (item.AbsoluteExpiration.Equals(Caching.Cache.DefaultAbsoluteLonger.ToUniversalTime()))
                {
                    _addCommand.absExpiration = 2;
                }
                else if (item.AbsoluteExpiration != Caching.Cache.NoAbsoluteExpiration)
                {
                    _addCommand.absExpiration = item.AbsoluteExpiration.Ticks;
                }

                if (item.SlidingExpiration.Equals(Caching.Cache.DefaultSliding))
                {
                    _addCommand.sldExpiration = 1;
                }
                else if (item.SlidingExpiration.Equals(Caching.Cache.DefaultSlidingLonger))
                {
                    _addCommand.sldExpiration = 2;
                }
                else if (item.SlidingExpiration != Caching.Cache.NoSlidingExpiration)
                {
                    _addCommand.sldExpiration = item.SlidingExpiration.Ticks;
                }

                _addCommand.flag       = item.FlagMap.Data;
                _addCommand.group      = item.Group;
                _addCommand.subGroup   = item.SubGroup;
                _addCommand.isResync   = item.IsResyncExpiredItems;
                _addCommand.priority   = (int)item.Priority;
                _addCommand.dependency = item.Dependency == null
                    ? null
                    : Alachisoft.NCache.Common.Util.DependencyHelper.GetProtoBufDependency(item.Dependency);

                _addCommand.clientID     = clientId;
                _addCommand.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);
                }


                _addCommand.objectQueryInfo = objectQueryInfo;


                EventDataFilter itemUpdateDataFilter  = updateCallbackFilter;
                EventDataFilter itemRemovedDataFilter = removeCallabackFilter;


                if (item.CacheItemRemovedCallback != null)
                {
                    itemRemovedDataFilter = item.ItemRemovedCallabackDataFilter;
                    short[] callabackIds = _parent.EventManager.RegisterSelectiveEvent(item.CacheItemRemovedCallback,
                                                                                       EventType.ItemRemoved, itemRemovedDataFilter);
                    removedCallbackId = callabackIds[1];
                }
                else if (item.ItemRemoveCallback != null)
                {
                    removedCallbackId     = _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;
                }


                _addCommand.removeCallbackId = removedCallbackId;
                _addCommand.updateCallbackId = updateCallbackId;
                _addCommand.updateDataFilter = (short)itemUpdateDataFilter;
                _addCommand.removeDataFilter = (short)itemRemovedDataFilter;

                _addCommand.resyncProviderName = item.ResyncProviderName;

                if (item.SyncDependency != null)
                {
                    _addCommand.syncDependency         = new Alachisoft.NCache.Common.Protobuf.SyncDependency();
                    _addCommand.syncDependency.key     = item.SyncDependency.Key;
                    _addCommand.syncDependency.cacheId = item.SyncDependency.CacheId;
                    _addCommand.syncDependency.server  = item.SyncDependency.Server;
                    _addCommand.syncDependency.port    = item.SyncDependency.Port;
                }

                _bulkAddCommand.addCommand.Add(_addCommand);
            }
        }
Esempio n. 8
0
        public BulkAddCommand(string[] keys, CacheItem[] items, Cache parent, string cacheId)
        {
            base.name = "BulkAddCommand";
            _parent = parent;

            _bulkAddCommand = new Alachisoft.NCache.Common.Protobuf.BulkAddCommand();
            _bulkAddCommand.requestId = base.RequestId;
            base.BulkKeys = keys;

            for (int i = 0; i < keys.Length; i++)
            {
                CacheItem item = items[i];

                _addCommand = new Alachisoft.NCache.Common.Protobuf.AddCommand();
                _addCommand.key = keys[i];

                Alachisoft.NCache.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject((byte[])item.Value);
                _addCommand.data.AddRange(ubObject.DataList);

                if (item.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                    _addCommand.absExpiration = item.AbsoluteExpiration.Ticks;

                if (item.SlidingExpiration != Cache.NoSlidingExpiration)
                    _addCommand.sldExpiration = item.SlidingExpiration.Ticks;

                _addCommand.flag = item.FlagMap.Data;

                _addCommand.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);

                _addCommand.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];
                }

                _addCommand.removeCallbackId = removeCallbackId;
                _addCommand.updateCallbackId = updateCallbackId;
                _addCommand.updateDataFilter = (short)itemUpdateDataFilter;
                _addCommand.removeDataFilter = (short)itemRemovedDataFilter;

                _bulkAddCommand.addCommand.Add(_addCommand);
            }
        }
        //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);
        }
Esempio n. 10
0
        //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);
        }