private void Connect() { if (_cacheRegion != null) { return; } _connectLock.Wait(); try { _poolFactory.Create("IDistributedCachePool"); // create/get region var regionFactory = _cache.CreateRegionFactory(RegionShortcut.PROXY).SetPoolName("pool"); try { _logger?.LogTrace("Create CacheRegion"); _cacheRegion = regionFactory.Create <string, string>(_regionName); _logger?.LogTrace("CacheRegion created"); } catch (Exception e) { _logger?.LogInformation(e, "Create CacheRegion failed... now trying to get the region"); _cacheRegion = _cache.GetRegion <string, string>(_regionName); } } finally { _connectLock.Release(); } }
private void ConnectToCloudCache() { JObject vcapJson = JObject.Parse(Environment.GetEnvironmentVariable("VCAP_SERVICES")); Cache cache = new CacheFactory() .SetAuthInitialize( new UsernamePassword( (string)vcapJson.SelectToken(Constants.jsonPathUsername), (string)vcapJson.SelectToken(Constants.jsonPathPassword))) .Create(); cache.TypeRegistry.PdxSerializer = new ReflectionBasedAutoSerializer(); PoolFactory pool = cache.GetPoolFactory(); foreach (string locator in vcapJson.SelectToken(Constants.jsonPathLocators).Select(s => (string)s).ToArray()) { string[] hostPort = locator.Split('[', ']'); pool.AddLocator(hostPort[0], Int32.Parse(hostPort[1])); } pool.Create("pool"); region = cache.CreateRegionFactory(RegionShortcut.PROXY) .SetPoolName("pool") .Create <string, Book>("owinexample"); }
public IPool CreatePool(string name) { var pool = PoolFactory.Create(name); _pools.Add(name, pool); EventSystem.Publish(new PoolAddedEvent(pool)); return(pool); }
public void CreateBasicPool() { PoolFactory.InitializePool <BasicTestPool>(2, null); var item1 = PoolFactory.Create <BasicTestPool>(); var item2 = PoolFactory.Create <BasicTestPool>(); Assert.AreNotEqual(item1, item2); item1.Dispose(); item2.Dispose(); PoolFactory.DisposePool <BasicTestPool>(); }
public PoolGroup Build() { PoolFactory poolFactory = new PoolFactory(); TeamFactory teamFactory = new TeamFactory(); GameFactory gameFactory = new GameFactory(); _poolGroup.Pools = poolFactory.Create(_numOfPools); _poolGroup.Pools = teamFactory.Create(_poolGroup.Pools, _numOfTeams, _seedMethod); _poolGroup.Pools = gameFactory.Create(_poolGroup.Pools, _numOfRounds); return(_poolGroup); }
public MEntityManager(int capcity = 1024) { _singletonComponents = new MComponent[64]; _entities = new Dictionary <int, MEntity>(capcity); _componentGroup = new ComponentGroup(); #if !RUNINSERVER MEntity Create() { return(new MEntity(_nextEntityId++, this)); } _entityPool = PoolFactory.Create(Create, null, null, null, 512); #endif }
static void TestDistributedSystem(Cache cache, String hostname, int port, String poolName, String regionName) { //create pool factory to create the pool. PoolFactory fact = PoolManager.CreateFactory(); //adding host(endpoint) in pool fact.AddServer(hostname, port); //enabling subscription on pool fact.SetSubscriptionEnabled(true); //creating pool with name "examplePool" fact.Create(poolName); RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY); IRegion <string, string> region = regionFactory.SetPoolName(poolName).Create <string, string>(regionName); Console.WriteLine("Created a generic Region."); // Put an Entry (Key and Value pair) into the Region using the IDictionary interface. region["Key1"] = "Value1"; Console.WriteLine("Put the first Entry into the Region"); // Put another Entry into the Region. region["123"] = "123"; Console.WriteLine("Put the second Entry into the Region"); // Get Entries back out of the Region. string result1 = region["Key1"]; Console.WriteLine("Obtained the first Entry from the Region"); string result2 = region["123"]; Console.WriteLine("Obtained the second Entry from the Region"); // Invalidate an Entry in the Region. region.Invalidate("Key1"); Console.WriteLine("Invalidated the first Entry in the Region"); // Destroy an Entry in the Region using the IDictionary interface. region.Remove("123"); Console.WriteLine("Destroyed the second Entry in the Region"); }
public void createPoolAndTestAttrs(string poolName) { CacheHelper.Init(); PoolFactory factory = CacheHelper.DCache.GetPoolManager().CreateFactory(); factory.SetFreeConnectionTimeout(TimeSpan.FromSeconds(10000)); factory.SetLoadConditioningInterval(TimeSpan.FromSeconds(1)); factory.SetSocketBufferSize(1024); factory.SetReadTimeout(TimeSpan.FromSeconds(10)); factory.SetMinConnections(2); factory.SetMaxConnections(5); factory.SetIdleTimeout(TimeSpan.FromSeconds(5)); factory.SetRetryAttempts(5); factory.SetPingInterval(TimeSpan.FromSeconds(1)); factory.SetUpdateLocatorListInterval(TimeSpan.FromMilliseconds(122000)); factory.SetStatisticInterval(TimeSpan.FromSeconds(1)); factory.SetServerGroup("ServerGroup1"); factory.SetSubscriptionEnabled(true); factory.SetSubscriptionRedundancy(1); factory.SetSubscriptionMessageTrackingTimeout(TimeSpan.FromSeconds(5)); factory.SetSubscriptionAckInterval(TimeSpan.FromSeconds(1)); factory.AddLocator("localhost", CacheHelper.LOCATOR_PORT_1); factory.SetPRSingleHopEnabled(false); Pool pool = factory.Create(poolName, CacheHelper.DCache); Assert.AreEqual(TimeSpan.FromSeconds(10000), pool.FreeConnectionTimeout, "FreeConnectionTimeout"); Assert.AreEqual(TimeSpan.FromSeconds(1), pool.LoadConditioningInterval, "LoadConditioningInterval"); Assert.AreEqual(1024, pool.SocketBufferSize, "SocketBufferSize"); Assert.AreEqual(TimeSpan.FromSeconds(10), pool.ReadTimeout, "ReadTimeout"); Assert.AreEqual(2, pool.MinConnections, "MinConnections"); Assert.AreEqual(5, pool.MaxConnections, "MaxConnections"); Assert.AreEqual(TimeSpan.FromSeconds(5), pool.IdleTimeout, "IdleTimeout"); Assert.AreEqual(5, pool.RetryAttempts, "RetryAttempts"); Assert.AreEqual(TimeSpan.FromSeconds(1), pool.PingInterval, "PingInterval"); Assert.AreEqual(TimeSpan.FromMilliseconds(122000), pool.UpdateLocatorListInterval, "UpdateLocatorListInterval"); Assert.AreEqual(TimeSpan.FromSeconds(1), pool.StatisticInterval, "StatisticInterval"); Assert.AreEqual("ServerGroup1", pool.ServerGroup, "ServerGroup"); Assert.AreEqual(true, pool.SubscriptionEnabled, "SubscriptionEnabled"); Assert.AreEqual(1, pool.SubscriptionRedundancy, "SubscriptionRedundancy"); Assert.AreEqual(TimeSpan.FromSeconds(5), pool.SubscriptionMessageTrackingTimeout, "SubscriptionMessageTrackingTimeout"); Assert.AreEqual(TimeSpan.FromSeconds(1), pool.SubscriptionAckInterval, "SubscriptionAckInterval"); Assert.AreEqual(false, pool.PRSingleHopEnabled, "PRSingleHopEnabled"); }
public void testExistingPool(string poolName) { PoolFactory factory = CacheHelper.DCache.GetPoolManager().CreateFactory(); try { factory.Create(poolName, CacheHelper.DCache); Assert.Fail("Did not get expected IllegalStateException"); } catch (IllegalStateException /*excp*/) { Util.Log("Got expected IllegalStateException"); } catch (Exception excp) { Assert.Fail("Got unexpected {0}: {1}", excp.GetType().Name, excp.Message); } }
public async Task CreateConnectionStringBasedPool() { PoolFactory.InitializeNamedPool <TestPoolWithConnectionString>(2, null); var item1 = PoolFactory.Create <TestPoolWithConnectionString>("http://test1.com/mongo"); var item2 = PoolFactory.Create <TestPoolWithConnectionString>("http://test2.com/mongo"); var item3 = PoolFactory.Create <TestPoolWithConnectionString>("http://test1.com/mongo"); var item4 = PoolFactory.Create <TestPoolWithConnectionString>("http://test2.com/mongo"); Assert.AreNotEqual(item1, item2); Assert.AreNotEqual(item3, item4); Assert.AreNotEqual(item1, item3); Assert.AreNotEqual(item2, item3); Assert.AreNotEqual(item1, item4); try { var item = PoolFactory.Create <TestPoolWithConnectionString>("http://test1.com/mongo"); Assert.Fail(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(Exception)); } var itemTask = Task.Run(() => PoolFactory.CreateAsync <TestPoolWithConnectionString>("http://test1.com/mongo")); item1.Dispose(); await Task.Delay(1); var item5 = await itemTask.ConfigureAwait(false); item2.Dispose(); item3.Dispose(); item4.Dispose(); item5.Dispose(); try { PoolFactory.DisposeNamedPool <TestPoolWithConnectionString>(); } catch { } }
public IPooledServiceContainer <TService> CreatePooledServiceProxy <TService>(IRuntime runtime, string serviceName) where TService : class { var attrib = typeof(TService).GetAttribute <ServiceNameAttribute>(); var serviceRootUrl = attrib.IsInstance() ? runtime.Context.GetEnvironmentConfiguration().GetConfigParameter(attrib.UrlRootName) : null; var address = runtime.Context.GetEndpointConfiguration(serviceName).GetRemoteAddress(serviceRootUrl); if (!PoolStatus.ContainsKey(address)) { lock (PoolStatus) { if (!PoolStatus.ContainsKey(address)) { PoolFactory.InitializeNamedPool <PooledServiceContainer <TService> >(GetInstanceCount(runtime.Context), (i) => InitializePoolItem <TService>(i, serviceName, serviceRootUrl, runtime.Context)); PoolStatus.Add(address, true); } } } return(PoolFactory.Create <PooledServiceContainer <TService> >(address)); }
public IPool <GameObject> GetOrCreatePool(GameObject prefab) { var existPool = GetPoolByPrefab(prefab); if (existPool != null) { return(existPool); } var objectPool = new GameObject("Pool_" + prefab.name); objectPool.transform.SetParent(PoolRoot.transform); objectPool.transform.position = Vector3.zero; objectPool.transform.rotation = Quaternion.identity; objectPool.transform.localScale = Vector3.one; existPool = PoolFactory.Create(objectPool); existPool.Prototype = prefab; return(existPool); }
private void ConnectToCloudCache() { JObject vcapJson = JObject.Parse(Environment.GetEnvironmentVariable("VCAP_SERVICES")); /** * JObject vcapJson = new JObject * { * { "locators", "192.168.12.52[55221]" }, * { "username", "cluster_operator_57Z2ueingjHQrgwIAB389w" }, * { "password", "CTl9gZJlIoS0m2BUdWpQ" } * }; **/ Cache cache = new CacheFactory() .Set("log-level", "debug") .Set("log-file", "pccpad.log") .SetAuthInitialize( new UsernamePassword( (string)vcapJson.SelectToken(Constants.jsonPathUsername), (string)vcapJson.SelectToken(Constants.jsonPathPassword))) .Create(); cache.TypeRegistry.PdxSerializer = new ReflectionBasedAutoSerializer(); PoolFactory pool = cache.GetPoolFactory(); foreach (string locator in vcapJson.SelectToken(Constants.jsonPathLocators).Select(s => (string)s).ToArray()) { string[] hostPort = locator.Split('[', ']'); pool.AddLocator(hostPort[0], Int32.Parse(hostPort[1])); } globalpool = pool.Create("pool"); region = cache.CreateRegionFactory(RegionShortcut.PROXY) .SetPoolName("pool") .Create <int, Customer>("customer"); }
private static void InitializeGemFireObjects(PoolFactory poolFactory, Cache cache) { Console.WriteLine("Create PoolFactory"); gemfireCache = cache; gemfireCache.TypeRegistry.PdxSerializer = new ReflectionBasedAutoSerializer(); try { Console.WriteLine("Create Pool"); // make sure the pool has been created poolFactory.Create("pool"); } catch (IllegalStateException e) { // we end up here with this message if you've hit the reset link after the pool was created if (e.Message != "Pool with the same name already exists") { throw; } } Console.WriteLine("Create Cache RegionFactory"); var regionFactory = gemfireCache.CreateRegionFactory(RegionShortcut.PROXY).SetPoolName("pool"); try { Console.WriteLine("Create CacheRegion"); cacheRegion = regionFactory.Create <string, string>(_regionName); Console.WriteLine("CacheRegion created"); } catch { Console.WriteLine("Create CacheRegion failed... now trying to get the region"); cacheRegion = gemfireCache.GetRegion <string, string>(_regionName); } }