public static void UsePooledChannels() { foreach (var factoryAndPoolOfItsChannels in s_recyclablePooledFactoriesAndChannels.GetAllPooledInstances()) { foreach (var channelWrapper in factoryAndPoolOfItsChannels.ObjectsPool.GetAllPooledInstances()) { s_CallChannelStats.CallActionAndRecordStats(() => { channelWrapper.OpenChannelOnce(); s_test.UseChannel()(channelWrapper.Channel); }); } } }
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())); }
static PooledFactories() { s_test = new TestTemplate(); s_pooledChannelFactories = StaticDisposablesHelper.AddDisposable( new PoolOfThings <ChannelFactory <ChannelType> >( maxSize: 10, createInstance: () => s_test.CreateChannelFactory(), destroyInstance: (chf) => s_CloseFactoryStats.CallActionAndRecordStats(() => s_test.CloseFactory(chf)))); }
public static void UseChannelsInPooledFactoriesAndChannels() { foreach (var factoryAndPoolOfItsChannels in s_pooledFactoriesAndChannels.GetAllPooledInstances()) { foreach (var channel in factoryAndPoolOfItsChannels.ObjectsPool.GetAllPooledInstances()) { s_CallChannelStats.CallActionAndRecordStats(() => { s_test.UseChannel()(channel); }); } } }
public static void CreateUseAndCloseChannels() { foreach (var factory in s_pooledChannelFactories.GetAllPooledInstances()) { ChannelType channel = null; s_CreateChannelStats.CallActionAndRecordStats(() => channel = s_test.CreateChannel(factory)); if (channel != null) { s_CallChannelStats.CallActionAndRecordStats(() => s_test.UseChannel()(channel)); s_CloseChannelStats.CallActionAndRecordStats(() => s_test.CloseChannel(channel)); } } }
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())); }
virtual public void CloseChannel(ChannelType channel) { _closeChannelStats.CallActionAndRecordStats(() => TestHelpers.CloseChannel(channel), RelaxedExceptionPolicy); }
virtual public void CloseFactory(ChannelFactory <ChannelType> factory) { _closeFactoryStats.CallActionAndRecordStats(() => TestHelpers.CloseFactory(factory), RelaxedExceptionPolicy); }