public void Remove()
        {
            var cacheFactory = CacheFactory.Create()
                               .SetProperty("log-level", "none")
                               .SetProperty("log-file", "SessionStateCacheIntegrationTests.log");

            var         cache       = (Cache)cacheFactory.CreateCache();
            PoolFactory poolFactory = cache.PoolFactory.AddLocator("localhost", 10334);
            var         pool        = poolFactory.CreatePool("myPool");

            var ssCache = new SessionStateCache(cache, _regionName);

            var            options       = new DistributedCacheEntryOptions();
            DateTime       localTime     = DateTime.Now.AddDays(1);
            DateTimeOffset dateAndOffset = new DateTimeOffset(localTime,
                                                              TimeZoneInfo.Local.GetUtcOffset(localTime));

            options.AbsoluteExpiration = dateAndOffset;
            var testValue = new byte[] { 1, 2, 3, 4, 5 };

            ssCache.Set("testKey", testValue, options);
            byte[] value = ssCache.Get("testKey");

            ssCache.Remove("testKey");
            value = ssCache.Get("testKey");
            Assert.Null(value);
        }
Beispiel #2
0
        public void TestGetTypeNotPresent()
        {
            RegisterPoolAndAssertion <TypeOne>(1);
            TypeTwo obj = PoolFactory.GetObject <TypeTwo>();

            Assert.IsNull(obj);
        }
        public void Refresh()
        {
            var cacheFactory = CacheFactory.Create()
                               .SetProperty("log-level", "none")
                               .SetProperty("log-file", "SessionStateCacheIntegrationTests.log");

            var         cache       = (Cache)cacheFactory.CreateCache();
            PoolFactory poolFactory = cache.PoolFactory.AddLocator("localhost", 10334);
            var         pool        = poolFactory.CreatePool("myPool");

            var ssCache = new SessionStateCache(cache, _regionName);

            var options    = new DistributedCacheEntryOptions();
            int numSeconds = 20;

            options.SlidingExpiration = new TimeSpan(0, 0, numSeconds);
            var testValue = new byte[] { 1, 2, 3, 4, 5 };

            // Set a value
            ssCache.Set("testKey", testValue, options);

            // Wait half a timeout then refresh
            System.Threading.Thread.Sleep(numSeconds / 2 * 1000);
            ssCache.Refresh("testKey");

            // Wait beyond the original expiration
            System.Threading.Thread.Sleep(numSeconds / 2 * 1000 + 1);

            // Ensure it's not expired
            byte[] value = ssCache.Get("testKey");
            Assert.True(testValue.SequenceEqual(value));
        }
        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");
        }
Beispiel #5
0
        public static IVariablePool GetVariablePool(string sessionID, string keyID)
        {
            IVariablePool rVP = null;

            PoolFactory.Get(sessionID, keyID, out rVP);

            return(rVP);
        }
Beispiel #6
0
    public static void Spawn(EffectId id, Transform target, float durationTime, params object[] values)
    {
        var key    = id.Id2key();
        var entity = PoolFactory.Get <Effect>(key, Vector3.zero, Quaternion.identity);

        entity.OnReturn = Return;
        entity.Spawn(key, target, durationTime, values);
    }
Beispiel #7
0
        public void TestCreationAndGet()
        {
            RegisterPoolAndAssertion <TypeOne>(1, 10);

            TypeOne obj = PoolFactory.GetObject <TypeOne>();

            Assert.IsNotNull(obj);
        }
Beispiel #8
0
    protected virtual void OnHit(Cube owner, Monster target, Missile missile)
    {
        owner.Hit(missile);
        target.Hit(owner, missile);

        missiles.Remove(missile);
        PoolFactory.Return("Missile", missile);
    }
    public void SetUp()
    {
        GameObject gameObject = new GameObject();

        poolFactory = gameObject.AddComponent <PoolFactory>();

        prefabTransform = Resources.Load <Transform>("TestResources/GameObject_OnlyTransform");
    }
Beispiel #10
0
        internal PoolFactory ApplyLocators(PoolFactory poolFactory)
        {
            foreach (var locator in locators_)
            {
                poolFactory.AddLocator(locator.Address.address, locator.Address.port);
            }

            return(poolFactory);
        }
Beispiel #11
0
 /// <summary>
 /// 创建池
 /// </summary>
 /// <param name="resName"></param>
 /// <param name="mode"></param>
 /// <param name="pType"></param>
 /// <param name="time"></param>
 private void createPool(string resName, E_PoolMode mode = E_PoolMode.Time, E_PoolType pType = E_PoolType.None, float time = 60)
 {
     if (!pools.ContainsKey(resName))
     {
         string   resPath = Path.Combine(Define.abPre, resName).ToLower();
         BasePool p       = PoolFactory.create(resName, resPath, mode, pType, time);
         pools.Add(resName, p);
     }
 }
Beispiel #12
0
    public virtual void DieMonster(int monsterSeq)
    {
        var monster = monsters.Find(x => x.seq == monsterSeq);

        monster.Release();
        monsters.Remove(monster);
        PoolFactory.Return("Monster", monster);

        user.SP += ServerDefine.MONSTER_DIE_SP;
    }
 public HomeController(PoolFactory poolFactory, Cache cache)
 {
     Console.WriteLine("HomeController constructor");
     if (cacheRegion == null)
     {
         Console.WriteLine("Initializing stuff");
         InitializeGemFireObjects(poolFactory, cache);
     }
     Console.WriteLine("Leaving HomeController constructor");
 }
Beispiel #14
0
    public virtual void EscapeMonster(int monsterSeq)
    {
        var monster = monsters.Find(x => x.seq == monsterSeq);

        monster.Release();
        monsters.Remove(monster);
        PoolFactory.Return("Monster", monster);

        user.Life -= 1;
    }
Beispiel #15
0
        void Start()
        {
            _powerSize        = 0.0f;
            _powerSizeOffset  = 0.1f;
            _arrowScaleOffset = 2.0f;
            directionArrow.transform.position = new Vector2(transform.position.x - DirectionArrowOffset, transform.position.y + DirectionArrowOffset);

            _ballFactory = new PoolFactory(baksetballPrefab);
            StartCoroutine(UpdateAI());
        }
Beispiel #16
0
        public IPool CreatePool(string name)
        {
            var pool = PoolFactory.Create(name);

            _pools.Add(name, pool);

            EventSystem.Publish(new PoolAddedEvent(pool));

            return(pool);
        }
Beispiel #17
0
        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>();
        }
Beispiel #18
0
 public virtual void DeleteCube(List <int> deleteCubes)
 {
     deleteCubes.ForEach(x =>
     {
         var cube = cubes.Find(c => c.gameCube.CubeSeq == x);
         user.Cubes.Remove(cube.gameCube);
         cube.Release();
         cubes.Remove(cube);
         PoolFactory.Return("Cube", cube);
     });
 }
        private ImagePipelineConfig(Builder builder)
        {
            _animatedImageFactory            = builder.AnimatedImageFactory;
            _bitmapMemoryCacheParamsSupplier = builder.BitmapMemoryCacheParamsSupplier ??
                                               new DefaultBitmapMemoryCacheParamsSupplier();

            _bitmapConfig = builder.BitmapConfig == default(BitmapPixelFormat) ?
                            BitmapPixelFormat.Bgra8 : builder.BitmapConfig;

            _cacheKeyFactory = builder.CacheKeyFactory ?? DefaultCacheKeyFactory.Instance;

            _decodeMemoryFileEnabled = builder.IsDecodeMemoryFileEnabled;
            _fileCacheFactory        = builder.FileCacheFactory ??
                                       new DiskStorageCacheFactory(new DynamicDefaultDiskStorageFactory());

            _downsampleEnabled = builder.IsDownsampleEnabled;
            _encodedMemoryCacheParamsSupplier = builder.EncodedMemoryCacheParamsSupplier ??
                                                new DefaultEncodedMemoryCacheParamsSupplier();

            _imageCacheStatsTracker = builder.ImageCacheStatsTracker ??
                                      NoOpImageCacheStatsTracker.Instance;

            _imageDecoder = builder.ImageDecoder;
            _isPrefetchEnabledSupplier = builder.IsPrefetchEnabledSupplier ??
                                         new SupplierImpl <bool>(
                () =>
            {
                return(true);
            });

            _mainDiskCacheConfig = builder.MainDiskCacheConfig ??
                                   GetDefaultMainDiskCacheConfig();

            _memoryTrimmableRegistry = builder.MemoryTrimmableRegistry ??
                                       NoOpMemoryTrimmableRegistry.Instance;

            _networkFetcher        = builder.NetworkFetcher ?? new HttpUrlConnectionNetworkFetcher();
            _platformBitmapFactory = builder.PlatformBitmapFactory;
            _poolFactory           = builder.PoolFactory ?? new PoolFactory(PoolConfig.NewBuilder().Build());
            _progressiveJpegConfig = builder.ProgressiveJpegConfig == default(IProgressiveJpegConfig) ?
                                     new SimpleProgressiveJpegConfig() : builder.ProgressiveJpegConfig;

            _requestListeners = builder.RequestListeners ?? new HashSet <IRequestListener>();
            _resizeAndRotateEnabledForNetwork = builder.ResizeAndRotateEnabledForNetwork;
            _smallImageDiskCacheConfig        = builder.SmallImageDiskCacheConfig ?? _mainDiskCacheConfig;

            // Below this comment can't be built in alphabetical order, because of dependencies
            int numCpuBoundThreads = _poolFactory.FlexByteArrayPoolMaxNumThreads;

            _executorSupplier = builder.ExecutorSupplier ??
                                new DefaultExecutorSupplier(numCpuBoundThreads);

            _imagePipelineExperiments = builder.Experiment.Build();
        }
        public void NullPoolFactory_Throws()
        {
            PoolFactory poolFactory  = null;
            var         cacheFactory = CacheFactory.Create()
                                       .SetProperty("log-level", "debug")
                                       .SetProperty("log-file", "SessionStateCacheTests.log");

            var cache = (Cache)cacheFactory.CreateCache();

            Assert.Throws <ArgumentNullException>(() => new SessionStateCache(cache, _regionName));
        }
Beispiel #21
0
 private void Awake()
 {
     if (PoolData == null)
     {
         PoolData = this;
     }
     else
     {
         Destroy(this);
     }
 }
Beispiel #22
0
        public void TestCreatWithNoObjectsAndGet()
        {
            RegisterPoolAndAssertion <TypeOne>(1, 0);
            TypeOne obj = PoolFactory.GetObject <TypeOne>();

            Assert.IsNotNull(obj);
            Assert.AreEqual(0, PoolFactory.GetPoolSize <TypeOne>());

            PoolFactory.Recycle(ref obj);
            Assert.AreEqual(1, PoolFactory.GetPoolSize <TypeOne>());
        }
Beispiel #23
0
        public void TestRegisterOverload()
        {
            int     toCompare = 55;
            TypeTwo toClone   = new TypeTwo(toCompare);

            PoolFactory.RegisterPool(toClone, 2);

            TypeTwo obj = PoolFactory.GetObject <TypeTwo>();

            Assert.IsNotNull(obj);
            Assert.AreEqual(toCompare, obj.testParam);
        }
Beispiel #24
0
        public void TestRecycle()
        {
            RegisterPoolAndAssertion <TypeOne>(1);
            Assert.AreEqual(10, PoolFactory.GetPoolSize <TypeOne>());

            TypeOne obj = PoolFactory.GetObject <TypeOne>();

            Assert.AreEqual(9, PoolFactory.GetPoolSize <TypeOne>());

            PoolFactory.Recycle(ref obj);
            Assert.AreEqual(10, PoolFactory.GetPoolSize <TypeOne>());
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
    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
    }
Beispiel #27
0
        public void TestCompleteFlow()
        {
            PoolFactory.RegisterPool <TypeTwo>();

            // Specify a value to have some instances of objects according to your needs
            PoolFactory.RegisterPool <TypeOne>(10);

            TypeOne obj_0 = PoolFactory.GetObject <TypeOne>();

            // Use methods with "_E" if you want throw Exception
            TypeTwo obj_1 = PoolFactory.GetObject_E <TypeTwo>();

            PoolFactory.Recycle(ref obj_0);
        }
Beispiel #28
0
        public void Initialize()
        {
            // Initializes the IFileCache
            _fileCacheFactory = new DiskStorageCacheFactory(new DynamicDefaultDiskStorageFactory());
            _fileCache        = _fileCacheFactory.Get(DiskCacheConfig.NewBuilder().Build());

            // Initializes the IPooledByteBufferFactory and PooledByteStreams
            _poolFactory       = new PoolFactory(PoolConfig.NewBuilder().Build());
            _byteBufferFactory = _poolFactory.PooledByteBufferFactory;
            _pooledByteStreams = _poolFactory.PooledByteStreams;

            // Initializes the IPooledByteBuffer from an image
            var file = StorageFile.GetFileFromApplicationUriAsync(
                new Uri("ms-appx:///Assets/SplashScreen.scale-200.png")).GetAwaiter().GetResult();

            using (var stream = file.OpenReadAsync().GetAwaiter().GetResult())
            {
                _pooledByteBuffer = _byteBufferFactory.NewByteBuffer(
                    ByteStreams.ToByteArray(stream.AsStream()));
            }

            _closeableReference = CloseableReference <IPooledByteBuffer> .of(_pooledByteBuffer);

            _encodedImage           = new EncodedImage(_closeableReference);
            _stagingArea            = StagingArea.Instance;
            _imageCacheStatsTracker = NoOpImageCacheStatsTracker.Instance;

            // Initializes the cache keys
            IList <ICacheKey> keys = new List <ICacheKey>();

            keys.Add(new SimpleCacheKey("http://test.uri"));
            keys.Add(new SimpleCacheKey("http://tyrone.uri"));
            keys.Add(new SimpleCacheKey("http://ian.uri"));
            _cacheKey = new MultiCacheKey(keys);

            // Initializes the executors
            _isCancelled           = new AtomicBoolean(false);
            _readPriorityExecutor  = Executors.NewFixedThreadPool(1);
            _writePriorityExecutor = Executors.NewFixedThreadPool(1);

            // Initializes the disk cache
            _bufferedDiskCache = new BufferedDiskCache(
                _fileCache,
                _byteBufferFactory,
                _pooledByteStreams,
                _readPriorityExecutor,
                _writePriorityExecutor,
                _imageCacheStatsTracker);
        }
Beispiel #29
0
        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 EventManager(int expectedEventTypes, int expectedRegisterCalls)
        {
            // NW: Doing this because we cannot call the correct consturctor ourselves (AutoGeneratedSingleton!!).
            // The Events (enum) EventManager is huge. Allocate here, ourselves, with massive capacity.
            // Optimization / hack.
            if (typeof(T).FullName == "Events")
            {
                expectedEventTypes    = 70;
                expectedRegisterCalls = 80;
            }

            m_listenerPool = new PoolFactory <List <Action <T, object[]> > >(
                () => new List <Action <T, object[]> >(2), x => x.Clear(), expectedRegisterCalls);
            m_events = new Dictionary <T, List <Action <T, object[]> > >(expectedEventTypes);
        }
    public void TestPooling() {
      PoolFactory<object> factory = new PoolFactory<object>(10);

      // We allocate 10 objects ahead because a valid pool factory implementation could
      // decide to only start returning reused objects after the pool is full to quickly
      // grow the pool at the beginning.
      object[] objects = new object[10];
      for(int index = 0; index < objects.Length; ++index) {
        objects[index] = factory.Take();
      }

      for(int index = objects.Length - 1; index >= 0; --index) {
        factory.Redeem(objects[index]);
      }

      for(int index = 0; index < objects.Length; ++index) {
        Assert.Contains(factory.Take(), objects);
      }
    }
 public void TestViaObjectFactoryInterface() {
   IAbstractFactory factory = new PoolFactory<object>(10);
   Assert.IsNotNull(factory.CreateInstance());
 }
 public void TestExplicitConstructor() {
   PoolFactory<object> factory = new PoolFactory<object>(100);
   Assert.IsNotNull(factory); // Nonsense; prevents compiler warning
 }