コード例 #1
0
        public object GetCacheData(object data, BitSet flag)
        {
            byte[] serializedObject = null;

            try
            {
                UserBinaryObject userBinaryObject = null;
                if (data is UserBinaryObject)
                {
                    userBinaryObject = (UserBinaryObject)data;
                }
                else
                {
                    userBinaryObject = UserBinaryObject.CreateUserBinaryObject((ICollection)data);
                }

                if (userBinaryObject != null)
                {
                    serializedObject = userBinaryObject.GetFullObject() as byte[];

                    return(SerializationUtil.SafeDeserialize(serializedObject, _context.SerializationContext, flag));
                }
            }
            catch (Exception ex)
            {
                if (_context.NCacheLog != null && _context.NCacheLog.IsErrorEnabled)
                {
                    _context.NCacheLog.Error("ObjectDataFormatService.GetCacheData()", ex.Message);
                }
            }
            return(data);
        }
コード例 #2
0
        public object GetClientData(object data, ref BitSet flag, LanguageContext languageContext)
        {
            byte[] serializedObject = null;
            try
            {
                switch (languageContext)
                {
                case LanguageContext.DOTNET:
                    serializedObject = SerializationUtil.SafeSerialize(data, _context.SerializationFormat, _context.SerializationContext, ref flag) as byte[];
                    break;
                }

                if (serializedObject != null && _context.CompressionEnabled)
                {
                    serializedObject = CompressionUtil.Compress(serializedObject, ref flag, _context.CompressionThreshold);
                }
                if (serializedObject != null)
                {
                    return(UserBinaryObject.CreateUserBinaryObject(serializedObject, _context.TransactionalPoolManager));
                }
            }
            catch (Exception ex)
            {
                if (_context.NCacheLog != null)
                {
                    if (_context.NCacheLog.IsErrorEnabled)
                    {
                        _context.NCacheLog.Error("ObjectDataFormatService.GetClientData()", ex.Message);
                    }
                }
            }
            return(data);
        }
コード例 #3
0
ファイル: CacheEntry.cs プロジェクト: wangchengqun/NCache
        /// <summary>
        /// Gets the deflatted value of the of the object in the value. It does not
        /// deflatten the actual object.
        /// </summary>
        internal object DeflattedValue(string cacheContext)
        {
            object obj = Value;

            //There is possibility that two threads simultaneously do deserialization; therefore
            //we must deserialize the entry in synchronized fashion.
            lock (this)
            {
                if (IsFlattened)
                {
                    // Setting the Value resets the Flat flag!
                    UserBinaryObject ub      = null;
                    CallbackEntry    cbEntry = obj as CallbackEntry;
                    if (cbEntry != null)
                    {
                        ub = cbEntry.Value as UserBinaryObject;
                    }
                    else
                    {
                        ub = obj as UserBinaryObject;
                    }

                    byte[] data = ub.GetFullObject();

                    _size = data.Length;
                    obj   = CompactBinaryFormatter.FromByteBuffer(data, cacheContext);
                    if (cbEntry != null)
                    {
                        cbEntry.Value = obj;
                        obj           = cbEntry;
                    }
                }
            }
            return(obj);
        }
コード例 #4
0
ファイル: EventHelper.cs プロジェクト: javithalion/NCache
        internal static ItemRemoveCallbackResponse GetItemRemovedCallbackResponse(EventContext eventContext, short id, string key, UserBinaryObject value, BitSet flag, ItemRemoveReason reason,EventDataFilter dataFilter)
        {
            Alachisoft.NCache.Common.Protobuf.ItemRemoveCallbackResponse itemRemovedCallback = new Alachisoft.NCache.Common.Protobuf.ItemRemoveCallbackResponse();

            itemRemovedCallback.key = key;
            itemRemovedCallback.callbackId = id;
            itemRemovedCallback.itemRemoveReason = (int)reason;
            itemRemovedCallback.flag = flag != null? (int)flag.Data : 0;
            itemRemovedCallback.dataFilter = (short)dataFilter;
            itemRemovedCallback.eventId = new Common.Protobuf.EventId();
            UserBinaryObject binaryObject = eventContext.Item != null ?(UserBinaryObject) eventContext.Item.Value : null;
            if(binaryObject != null) itemRemovedCallback.value.AddRange(binaryObject.DataList);

            if (eventContext != null)
            {
                itemRemovedCallback.eventId.eventUniqueId = eventContext.EventID.EventUniqueID;
                itemRemovedCallback.eventId.operationCounter = eventContext.EventID.OperationCounter;
                itemRemovedCallback.eventId.eventCounter = eventContext.EventID.EventCounter;
                if (eventContext.Item != null)
                    itemRemovedCallback.flag = eventContext.Item.Flags.Data;
                itemRemovedCallback.eventId.item = ConvertToEventItem(eventContext.Item, null);
                if (itemRemovedCallback.eventId.item != null && itemRemovedCallback.eventId.item.value != null)
                {
                    itemRemovedCallback.eventId.item.value.Clear();//data will be travalling in old fashion due to old callbacks
                }
            }

            return itemRemovedCallback;
        }
コード例 #5
0
ファイル: CacheItemBase.cs プロジェクト: wangchengqun/NCache
 /// <summary>
 /// Default constructor. No call back.
 /// </summary>
 public CacheItemBase(object obj)
 {
     if (obj is byte[])
     {
         obj = UserBinaryObject.CreateUserBinaryObject((byte[])obj);
     }
     _v = obj;
 }
コード例 #6
0
ファイル: CacheEntry.cs プロジェクト: wangchengqun/NCache
        public void Write(VirtualArray vBuffer, int srcOffset, int dstOffset, int length)
        {
            UserBinaryObject ubObject = (UserBinaryObject)(Value is CallbackEntry ? ((CallbackEntry)Value).Value : Value);

            if (ubObject != null)
            {
                ubObject.Write(vBuffer, srcOffset, dstOffset, length);
            }
        }
コード例 #7
0
ファイル: CacheEntry.cs プロジェクト: wangchengqun/NCache
        public VirtualArray Read(int offset, int length)
        {
            VirtualArray     vBuffer  = null;
            UserBinaryObject ubObject = (UserBinaryObject)(Value is CallbackEntry ? ((CallbackEntry)Value).Value : Value);

            if (ubObject != null)
            {
                vBuffer = ubObject.Read(offset, length);
            }
            return(vBuffer);
        }
コード例 #8
0
        public object GetCacheData(object data, BitSet flag)
        {
            ICollection dataList = data as ICollection;

            if (dataList == null)
            {
                return(data);
            }

            return(UserBinaryObject.CreateUserBinaryObject(dataList, _context.TransactionalPoolManager));
        }
コード例 #9
0
 internal ItemRemoveCallback(short id, string key, object value, ItemRemoveReason reason, string clientId, BitSet Flag, EventContext eventContext,EventDataFilter dataFilter)
 {
     _id = id;
     _key = key;
     _value = value as UserBinaryObject;
     _flag = Flag;
     _reason = reason;
     _clientID = clientId;
     _eventContext = eventContext;
     _dataFilter = dataFilter;
 }
コード例 #10
0
        public object GetCacheData(object data, BitSet flag)
        {
            ICollection dataList = data as ICollection;

            if (dataList == null)
            {
                return(data);
            }

            return(UserBinaryObject.CreateUserBinaryObject(dataList));
        }
コード例 #11
0
        protected static void Construct(CacheItemBase cacheItem, object value)
        {
            var bytes = value as byte[];

            if (bytes != null)
            {
                value = UserBinaryObject.CreateUserBinaryObject(bytes, cacheItem.PoolManager);
            }

            cacheItem.Value = value;
        }
コード例 #12
0
        /// <summary>
        /// Mainly written for cache data as JSON for backing source. Please do not call this method from anywhere
        /// other than the derived classes of <see cref="Runtime.Caching.ProviderItemBase"/>.
        /// </summary>
        public T GetCacheData <T>(object data, BitSet flag, UserObjectType userObjectType)
        {
            var dataList = data as ICollection;

            // If data was requested by socket server
            if (dataList != null && typeof(object).IsAssignableFrom(typeof(T)))
            {
                return((T)(object)UserBinaryObject.CreateUserBinaryObject(dataList));
            }

            return(SerializationUtil.SafeDeserializeInProc <T>(data, string.Empty, flag, userObjectType, false));
        }
コード例 #13
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;
        }
コード例 #14
0
ファイル: UserBinaryObject.cs プロジェクト: yaobos/NCache
        public static UserBinaryObject CreateUserBinaryObject(Array data)
        {
            UserBinaryObject binaryObject = null;

            if (data != null)
            {
                if (data.Length > 1)
                {
                    binaryObject = LargeUserBinaryObject.CreateUserBinaryObject(data);
                }
                else
                {
                    binaryObject = SmallUserBinaryObject.CreateUserBinaryObject(data);
                }
            }

            return(binaryObject);
        }
コード例 #15
0
        public static UserBinaryObject CreateUserBinaryObject(ICollection data)
        {
            UserBinaryObject binaryObject = null;

            if (data != null)
            {
                if (data.Count > 1)
                {
                    binaryObject = LargeUserBinaryObject.CreateUserBinaryObject(data);
                }
                else
                {
                    binaryObject = SmallUserBinaryObject.CreateUserBinaryObject(data);
                }
            }

            return(binaryObject);
        }
コード例 #16
0
ファイル: UserBinaryObject.cs プロジェクト: yaobos/NCache
        /// <summary>
        /// Creates a UserBinaryObject from a byte array
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static UserBinaryObject CreateUserBinaryObject(byte[] byteArray)
        {
            UserBinaryObject binaryObject = null;

            if (byteArray != null)
            {
                float noOfChunks = (float)byteArray.Length / (float)LARGE_OBJECT_SIZE;

                if (noOfChunks < 1.0)
                {
                    binaryObject = SmallUserBinaryObject.CreateUserBinaryObject(byteArray);
                }
                else
                {
                    binaryObject = LargeUserBinaryObject.CreateUserBinaryObject(byteArray);
                }
            }

            return(binaryObject);
        }
コード例 #17
0
        public InsertCommand(string key, byte[] value, CacheDependency dependency, CacheSyncDependency syncDependency,
                             DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback,
                             short updateCallback, short dsItemsUpdateCallbackId, bool isResyncExpiredItems, string group,
                             string subGroup, short itemUpdated, bool isAsync, Hashtable queryInfo, BitSet flagMap, object lockId,
                             ulong version, LockAccessType accessType, string providerName, string resyncProviderName, string cacheId,
                             EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter, int methodOverload,
                             string clientId, CallbackType callbackType = Runtime.Events.CallbackType.PushBasedNotification)
        {
            base.name = "InsertCommand";
            base.asyncCallbackSpecified = isAsync && itemUpdated != -1 ? true : false;
            base.isAsync = isAsync;
            base.key     = key;

            _itemUpdated = itemUpdated;

            _insertCommand     = new Alachisoft.NCache.Common.Protobuf.InsertCommand();
            _insertCommand.key = key;

            Alachisoft.NCache.Caching.UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(value);
            _insertCommand.data.AddRange(ubObject.DataList);
            _methodOverload                            = methodOverload;
            _insertCommand.requestId                   = base.RequestId;
            _insertCommand.removeCallbackId            = removeCallback;
            _insertCommand.updateCallbackId            = updateCallback;
            _insertCommand.updateDataFilter            = (short)updateCallbackFilter;
            _insertCommand.removeDataFilter            = (short)removeCallabackFilter;
            _insertCommand.datasourceUpdatedCallbackId = dsItemsUpdateCallbackId;
            _insertCommand.isAsync                     = isAsync;
            _insertCommand.priority                    = (int)priority;
            _insertCommand.flag                        = flagMap.Data;
            _insertCommand.itemVersion                 = version;
            if (lockId != null)
            {
                _insertCommand.lockId = lockId.ToString();
            }
            _insertCommand.lockAccessType     = (int)accessType;
            _insertCommand.providerName       = providerName;
            _insertCommand.resyncProviderName = resyncProviderName;

            _insertCommand.clientID     = clientId;
            _insertCommand.CallbackType = CallbackType(callbackType);

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

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

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


            _insertCommand.isResync = isResyncExpiredItems;
            _insertCommand.group    = group;
            _insertCommand.subGroup = subGroup;

            ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo();

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

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

            if (queryInfo["named-tag-info"] != null)
            {
                objectQueryInfo.namedTagInfo =
                    ProtobufHelper.GetNamedTagInfoObj(queryInfo["named-tag-info"] as Hashtable, true);
            }


            _insertCommand.objectQueryInfo = objectQueryInfo;

            if (dependency != null)
            {
                _insertCommand.dependency =
                    Alachisoft.NCache.Common.Util.DependencyHelper.GetProtoBufDependency(dependency);
            }
        }