コード例 #1
0
        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;
        }
コード例 #2
0
ファイル: AddCommand.cs プロジェクト: yaobos/NCache
        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;
        }
コード例 #3
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;
        }
コード例 #4
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);
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
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;
            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);
        }