public static void CreateFactoriesAndChannelsUseAllOnceCloseAll()
 {
     using (var theOneTimeThing = 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(func: () => s_test.CreateChannel(chf)),
                    destroyObject: (ch) =>
                    s_CloseChannelStats.CallActionAndRecordStats(() => s_test.CloseChannel(ch))
                    ),
                destroyInstance: (_fapoic) => _fapoic.Destroy()))
     {
         foreach (var factoryAndPoolOfItsChannels in theOneTimeThing.GetAllPooledInstances())
         {
             foreach (var channel in factoryAndPoolOfItsChannels.ObjectsPool.GetAllPooledInstances())
             {
                 s_CallChannelStats.CallActionAndRecordStats(() =>
                 {
                     s_test.UseChannel()(channel);
                 });
             }
         }
     }
 }
        static RecyclablePooledFactoriesAndChannels_OpenOnce()
        {
            // moving the following magic numbers to the test template interface will help each test to collect different type of stats
            s_CreateChannelStats = new CallStats(samples: 1000, errorSamples: 1000);
            s_CallChannelStats   = new CallStats(samples: 1000000, errorSamples: 10000);
            s_CloseChannelStats  = new CallStats(samples: 1000, errorSamples: 1000);
            s_CloseFactoryStats  = new CallStats(samples: 1000, errorSamples: 1000);

            s_test = new TestTemplate();
            Console.WriteLine(s_test.GetType().ToString());

            // Perhaps a helper (extension?) method to hide new PoolOfThings would make things more readable
            s_recyclablePooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
                new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, OpenOnceChannelWrapper <ChannelType> > >(
                    maxSize: 3, // # of pooled FactoryAndPoolOfItsObjects
                    createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, OpenOnceChannelWrapper <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(func: () => new OpenOnceChannelWrapper <ChannelType>(s_test.CreateChannel(chf))),
                        destroyObject: (chWr) =>
                        s_CloseChannelStats.CallActionAndRecordStats(action: () => s_test.CloseChannel(chWr.Channel))
                        ),
                    destroyInstance: (_fapoic) => _fapoic.Destroy()));
        }
Esempio n. 3
0
 virtual public Func <ChannelType, int> UseChannel()
 {
     return((channel) =>
     {
         using (StartTrackingOperation(channel))
         {
             return _useChannelStats.CallFuncAndRecordStats(
                 () => UseChannelImpl(channel), RelaxedExceptionPolicy);
         }
     });
 }
Esempio n. 4
0
 virtual public Func <ChannelType, int> UseChannel()
 {
     if (_params.TrackServiceCallTimeouts)
     {
         return((channel) =>
         {
             using (_timeoutTracker.StartTrackingOperation(channel))
             {
                 return _useChannelStats.CallFuncAndRecordStats(
                     () => UseChannelImpl()(channel),
                     RelaxedExceptionPolicy);
             }
         });
     }
     else
     {
         return((channel) =>
         {
             return _useChannelStats.CallFuncAndRecordStats(
                 () => UseChannelImpl()(channel),
                 RelaxedExceptionPolicy);
         });
     }
 }
 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()));
 }
 static RecyclablePooledFactoriesAndChannelsAsync_OpenOnce()
 {
     s_test = new TestTemplate();
     s_recyclablePooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
         new PoolOfAsyncThings <
             FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, OpenAsyncOnceChannelWrapper <ChannelType> > >(
             maxSize: 3,     // # of pooled FactoryAndPoolOfItsChannels
             createInstance: () => new FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, OpenAsyncOnceChannelWrapper <ChannelType> >(
                 createFactoryInstance:
                 s_test.CreateChannelFactory,
                 destroyFactoryInstanceAsync: async(chf) =>
                 await s_CloseFactoryStats.CallAsyncFuncAndRecordStatsAsync(s_test.CloseFactoryAsync, chf),
                 maxPooledObjects: 3,     // # of pooled channels within each pooled FactoryAndPoolOfItsAsyncObjects
                 createObject: (chf) =>
                 s_CreateChannelStats.CallFuncAndRecordStats(func: () => new OpenAsyncOnceChannelWrapper <ChannelType>(s_test.CreateChannel(chf))),
                 destroyObjectAsync: async(chWr) =>
                 await s_CloseChannelStats.CallAsyncFuncAndRecordStatsAsync(func: () => s_test.CloseChannelAsync(chWr.Channel))
                 ),
             destroyInstanceAsync: async(_fapoic) => await _fapoic.DestroyAsync()));
 }
Esempio n. 7
0
 virtual public ChannelType CreateChannel(ChannelFactory <ChannelType> factory)
 {
     return(_createChannelStats.CallFuncAndRecordStats(TestHelpers.CreateChannel, factory, RelaxedExceptionPolicy));
 }