Пример #1
0
        static RecyclablePooledFactoriesAndChannels()
        {
            s_test = new TestTemplate();
            // It is expected to see various exceptions when we use factories while recycling them
            s_test.TestParameters.RelaxedExceptionPolicy = true;

            s_recyclablePooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
                new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType> >(
                    maxSize: s_test.TestParameters.MaxPooledFactories,
                    createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType>(
                        createFactoryInstance: () =>
                        s_test.CreateChannelFactory(),
                        destroyFactoryInstance: (chf) => s_test.CloseFactory(chf),
                        maxPooledObjects: s_test.TestParameters.MaxPooledChannels,
                        createObject: (chf) => s_test.CreateChannel(chf),
                        destroyObject: (ch) => s_test.CloseChannel(ch)),
                    destroyInstance: (_fapoic) => _fapoic.Destroy()));
        }
 static PooledFactoriesAndChannels()
 {
     s_test = new TestTemplate();
     s_pooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
         new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType> >(
             maxSize: 3, // # of pooled FactoryAndPoolOfItsObjects
             createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType>(
                 createFactoryInstance:
                 s_test.CreateChannelFactory,
                 destroyFactoryInstance: (chf) =>
                 s_CloseFactoryStats.CallActionAndRecordStats(() => s_test.CloseFactory(chf)),
                 maxPooledObjects: 3, // # of pooled channels within each pooled FactoryAndPoolOfItsObjects
                 createObject: (chf) =>
                 s_CreateChannelStats.CallFuncAndRecordStats(s_test.CreateChannel, chf),
                 destroyObject: (ch) =>
                 s_CloseChannelStats.CallActionAndRecordStats(() => s_test.CloseChannel(ch))
                 ),
             destroyInstance: (_fapoic) => _fapoic.Destroy()));
 }
Пример #3
0
 static PooledFactoriesAndChannels()
 {
     s_test = new TestTemplate();
     s_pooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
         new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType> >(
             maxSize: s_test.TestParameters.MaxPooledFactories, // # of pooled FactoryAndPoolOfItsObjects
             createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType>(
                 createFactoryInstance:
                 s_test.CreateChannelFactory,
                 destroyFactoryInstance: (chf) =>
                 s_test.CloseFactory(chf),
                 maxPooledObjects: s_test.TestParameters.MaxPooledChannels, // # of pooled channels within each pooled FactoryAndPoolOfItsObjects
                 createObject: (chf) =>
                 s_test.CreateChannel(chf),
                 destroyObject: (ch) =>
                 s_test.CloseChannel(ch)
                 ),
             destroyInstance: (_fapoio) => _fapoio.Destroy()));
 }
Пример #4
0
 /// <summary>
 /// The constructor simply creates an empty pool of objects and stores delegates to create/destroy instances
 /// </summary>
 /// <param name="createFactoryInstance"> A func to create an instance of F. </param>
 /// <param name="destroyFactoryInstance"> An action to destroy an instance of F</param>
 /// <param name="maxPooledObjects"> Max size of the pool of objects O </param>
 /// <param name="createObject"> A func to create all instances of O </param>
 /// <param name="destroyObject"> An action to destroy all instances of O</param>
 public FactoryAndPoolOfItsObjects(
     Func <F> createFactoryInstance,
     Action <F> destroyFactoryInstance,
     int maxPooledObjects,
     Func <F, O> createObject,
     Action <O> destroyObject,
     Func <O, bool> validateObjectInstance)
 {
     _destroyFactoryInstance = destroyFactoryInstance;
     Factory     = createFactoryInstance();
     ObjectsPool = new PoolOfThings <O>(
         maxSize: maxPooledObjects,
         createInstance: () =>
     {
         // PoolOfThings lets us use the instances while destroying them
         // Destroy may null Factory out so we save a local copy here
         var f = Factory;
         return(f != null ? createObject(f) : null);
     },
         destroyInstance: destroyObject,
         instanceValidator: validateObjectInstance);
 }
 static PooledFactoriesAndChannels()
 {
     s_test = new TestTemplate();
     // we do not expect exceptions here since we're not closing anything during usage
     (s_test as IExceptionPolicy).RelaxedExceptionPolicy = false;
     s_pooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
         new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType> >(
             maxSize: s_test.TestParameters.MaxPooledFactories, // # of pooled FactoryAndPoolOfItsObjects
             createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType>(
                 createFactoryInstance:
                 s_test.CreateChannelFactory,
                 destroyFactoryInstance: (chf) =>
                 s_test.CloseFactory(chf),
                 maxPooledObjects: s_test.TestParameters.MaxPooledChannels, // # of pooled channels within each pooled FactoryAndPoolOfItsObjects
                 createObject: (chf) =>
                 s_test.CreateChannel(chf),
                 destroyObject: (ch) =>
                 s_test.CloseChannel(ch),
                 validateObjectInstance: s_test.ValidateChannel),
             destroyInstance: (fapoio) => fapoio.Destroy(),
             instanceValidator: (fapoiao) => s_test.ValidateFactory(fapoiao.Factory)));
 }
Пример #6
0
 public AllPooledInstancesCollection(PoolOfThings <T> thePool)
 {
     _thePool = thePool;
 }