Exemple #1
0
        /// <summary>
        /// 获取Loader
        /// </summary>
        /// <param name="hash"></param>
        /// <returns></returns>
        public static ABLoader GetLoader(uint hash, ABLoadContext _loadContext)
        {
            //如果已经存在Laoder则返回loader
            if (_loadContext.loadingLoaderDict.ContainsKey(hash))
            {
                return(_loadContext.loadingLoaderDict[hash]);
            }

            ABData data = _loadContext.dataHelper.GetABData(hash);

            if (data == null)
            {
                ReDebug.LogError(ReLogType.System, "ABManager",
                                 string.Format("ABData is null, abName={0}", hash));
                return(null);
            }

            //创建Loader并且加入表中
            ABLoader loader = ReusableObjectPool <ABLoader> .Get();

            loader.abName = data.fullName;
            loader.abData = data;
            _loadContext.loadingLoaderDict[hash] = loader;
            loader._loadContext = _loadContext;

            return(loader);
        }
Exemple #2
0
        /// <summary>
        /// 当加载任务结束,无论成功或者失败
        /// </summary>
        /// <param name="succ"></param>
        private void OnTaskFinish(bool succ)
        {
            if (bundle)
            {
                state = ABLoadState.Complete;
                OnComplete();
            }
            else
            {
                state = ABLoadState.Error;
                OnError();
            }

            if (Callback != null)
            {
                Callback(abObject);
            }

            ListPool <ABObject> .Return(depObjectList);

            depObjectList = null;

            ListPool <ABLoader> .Return(depLoaderList);

            depLoaderList = null;

            bundle = null;

            _loadContext.loadingLoaderDict.Remove(abName);
            //回收Loader
            ReusableObjectPool <ABLoader> .Return(this);
        }
Exemple #3
0
        public MsmqQueue(Uri uri, IMsmqConfiguration configuration)
        {
            Guard.AgainstNull(uri, "uri");
            Guard.AgainstNull(configuration, "configuration");

            _log = Log.For(this);

            _parser = new MsmqUriParser(uri);

            _timeout = _parser.Local
                           ? TimeSpan.FromMilliseconds(configuration.LocalQueueTimeoutMilliseconds)
                           : TimeSpan.FromMilliseconds(configuration.RemoteQueueTimeoutMilliseconds);

            Uri = _parser.Uri;

            _messagePropertyFilter = new MessagePropertyFilter();
            _messagePropertyFilter.SetAll();

            _dequeuePipelinePool = new ReusableObjectPool<MsmqGetMessagePipeline>();
        }
        public MsmqQueue(Uri uri, IMsmqConfiguration configuration)
        {
            Guard.AgainstNull(uri, "uri");
            Guard.AgainstNull(configuration, "configuration");

            _log = Log.For(this);

            _parser = new MsmqUriParser(uri);

            _timeout = _parser.Local
                ? TimeSpan.FromMilliseconds(configuration.LocalQueueTimeoutMilliseconds)
                : TimeSpan.FromMilliseconds(configuration.RemoteQueueTimeoutMilliseconds);

            Uri = _parser.Uri;

            _messagePropertyFilter = new MessagePropertyFilter();
            _messagePropertyFilter.SetAll();

            _dequeuePipelinePool = new ReusableObjectPool <MsmqGetMessagePipeline>();
        }
 public DefaultPipelineFactory()
 {
     _pool = new ReusableObjectPool <MessagePipeline>();
 }
Exemple #6
0
        /// <summary>
        /// Starts the data parser given the specified type implementations.
        /// </summary>
        /// <param name="implementations">Output type implementations to establish for the parser.</param>
        public virtual void Start(IEnumerable <Type> implementations)
        {
            // Call base class start method
            base.Start();

            ConstructorInfo typeCtor    = null;
            List <TypeInfo> outputTypes = new List <TypeInfo>();  // Temporarily hold output types until their IDs are determined.

            foreach (Type type in implementations)
            {
                // See if a parameterless constructor is available for this type
                typeCtor = type.GetConstructor(Type.EmptyTypes);

                // Since user can call this overload with any list of types, we double check the type criteria.
                // If output type is a class, see if current type derives from it, else if output type is an
                // interface, see if current type implements it.
                if ((object)typeCtor != null && !type.IsAbstract &&
                    (
                        (typeof(TOutputType).IsClass && type.IsSubclassOf(typeof(TOutputType))) ||
                        (typeof(TOutputType).IsInterface && (object)type.GetInterface(typeof(TOutputType).Name) != null))
                    )
                {
                    // The type meets the following criteria:
                    //      - has a default public constructor
                    //      - is not abstract and can be instantiated.
                    //      - type is related to class or interface specified for the output
                    TypeInfo outputType = new TypeInfo
                    {
                        RuntimeType = type
                    };

                    // If object pooling is allowed and class implementation supports life cycle, use object pool instead of creating an object each time one is parsed
                    if (AllowObjectPooling && (object)type.GetInterface("TVA.ISupportLifecycle") != null)
                    {
                        outputType.SupportsLifecycle = true;
                        outputType.CreateNew         = () => ReusableObjectPool.TakeObject <TOutputType>(type);
                    }
                    else
                    {
                        outputType.SupportsLifecycle = false;
                        outputType.CreateNew         = FastObjectFactory.GetCreateObjectFunction <TOutputType>(type);
                    }

                    // We'll hold all of the matching types in this list temporarily until their IDs are determined.
                    outputTypes.Add(outputType);
                }
            }

            foreach (TypeInfo outputType in outputTypes)
            {
                // Now, we'll go though all of the output types we've found and instantiate an instance of each in order to get
                // the identifier for each of the type. This will help lookup of the type to be used when parsing the data.
                TOutputType instance = outputType.CreateNew();
                outputType.TypeID = instance.TypeID;

                if (!m_outputTypes.ContainsKey(outputType.TypeID))
                {
                    m_outputTypes.Add(outputType.TypeID, outputType);
                }
                else
                {
                    OnDuplicateTypeHandlerEncountered(outputType.RuntimeType, outputType.TypeID);
                }

                // Return object to the pool if it supports lifecycle management
                if (outputType.SupportsLifecycle)
                {
                    ((IDisposable)instance).Dispose();
                }
            }
        }
Exemple #7
0
 static ResponseAsyncHelper()
 {
     ResponseBuffersPool = new ReusableObjectPool <byte[]>(() => new byte[HttpServerSettings.MaxResponseSize], HttpServerSettings.Concurrency);
 }