public void TestListenerWithNonSmartRouting()
        {
            var map = _client.GetMap <string, string>(TestSupport.RandomString());

            var keys          = TestSupport.RandomArray(TestSupport.RandomString, 10);
            var registrations = new List <string>();
            var tasks         = new List <Task>();

            foreach (var key in keys)
            {
                var tcs = new TaskCompletionSource <bool>();
                var id  = map.AddEntryListener(new EntryAdapter <string, string>
                {
                    Added = e => tcs.SetResult(true)
                }, key, false);
                registrations.Add(id);
                tasks.Add(tcs.Task);
            }

            foreach (var key in keys)
            {
                map.Put(key, TestSupport.RandomString());
            }

            Assert.IsTrue(Task.WaitAll(tasks.ToArray(), 500), "Did not get all entry added events within 500ms");
            foreach (var id in registrations)
            {
                Assert.IsTrue(map.RemoveEntryListener(id));
            }
        }
Beispiel #2
0
        public static void Run(string[] args)
        {
            var clientConfig = new Configuration();

            clientConfig.NetworkConfig.AddAddress("127.0.0.1");
            //clientConfig.NetworkConfig.AddAddress("10.0.0.2:5702");

            var sc = new SerializerConfig()
                     .SetImplementation(new CustomSerializer())
                     .SetTypeClass(typeof(Person));

            //Custom Serialization setup up for Person Class.
            clientConfig.SerializationConfig.SerializerConfigs.Add(sc);


            IHazelcastInstance client = HazelcastClient.NewHazelcastClient(clientConfig);
            //All cluster operations that you can do with ordinary HazelcastInstance
            IMap <string, Person> mapCustomers = client.GetMap <string, Person>("persons");

            mapCustomers.Put("1", new Person("Joe", "Smith"));
            mapCustomers.Put("2", new Person("Ali", "Selam"));
            mapCustomers.Put("3", new Person("Avi", "Noyan"));

            ICollection <Person> persons = mapCustomers.Values();

            foreach (var person in persons)
            {
                Console.WriteLine(person.ToString());
            }

            HazelcastClient.ShutdownAll();
            Console.ReadKey();
        }
Beispiel #3
0
        static void Main111(string[] args)
        {
            var clientConfig = new ClientConfig();

            clientConfig.GetNetworkConfig().AddAddress("127.0.0.1");
            //clientConfig.GetNetworkConfig().AddAddress("10.0.0.2:5702");

            //Portable Serialization setup up for Customer CLass
            clientConfig.GetSerializationConfig().AddPortableFactory(MyPortableFactory.FactoryId, new MyPortableFactory());


            IHazelcastInstance client = HazelcastClient.NewHazelcastClient(clientConfig);
            //All cluster operations that you can do with ordinary HazelcastInstance
            IMap <string, Customer> mapCustomers = client.GetMap <string, Customer>("customers");

            mapCustomers.Put("1", new Customer("Joe", "Smith"));
            mapCustomers.Put("2", new Customer("Ali", "Selam"));
            mapCustomers.Put("3", new Customer("Avi", "Noyan"));


            Customer customer1 = mapCustomers.Get("1");

            Console.WriteLine(customer1);

            //ICollection<Customer> customers = mapCustomers.Values();
            //foreach (var customer in customers)
            //{
            //    //customer
            //}
        }
        static void Mainzz(string[] args)
        {
            var clientConfig = new ClientConfig();

            clientConfig.GetNetworkConfig().AddAddress("127.0.0.1");
            clientConfig.GetSerializationConfig().AddDataSerializableFactory(1, new MyDataSerializableFactory());


            IHazelcastInstance client = HazelcastClient.NewHazelcastClient(clientConfig);
            //All cluster operations that you can do with ordinary HazelcastInstance
            IMap <string, DataSerializableType> map = client.GetMap <string, DataSerializableType>("imap");

            ISerializationService service = ((HazelcastClientProxy)client).GetSerializationService();

            object obj   = new DataSerializableType(1000, 1000);
            long   start = Clock.CurrentTimeMillis();
            var    data  = service.ToData(obj);

            var dataSerializableType = service.ToObject <DataSerializableType>(data);

            long diff = Clock.CurrentTimeMillis() - start;

            Console.WriteLine("Serialization time:" + diff);

            Console.ReadKey();
        }
Beispiel #5
0
 protected override void BeginProcessing()
 {
     Map = Client.GetMap <ComplexPortableKey, ComplexPortableData>(mapName);
     generatedKeyValuePairs = GenerateKeyValuePairs();
     generatedKeys          = generatedKeyValuePairs.Keys;
     generatedKeysArray     = generatedKeyValuePairs.Keys.ToArray();
 }
        public void Setup()
        {
            _remoteController = CreateRemoteController();
            _cluster          = CreateCluster(_remoteController);

            StartMember(_remoteController, _cluster);
            _client = CreateClient();
            _client.GetMap <object, object>("default").Get(new object());
        }
Beispiel #7
0
 public static void HzTask(IHazelcastInstance hz)
 {
     try
     {
         var random = new Random();
         var map    = hz.GetMap <string, byte[]>("default");
         //int i = 0;
         while (true)
         {
             //i++;
             //if (i % 1000 == 0)
             //{
             //    Console.WriteLine("Iterate...."+i);
             //}
             try
             {
                 var key       = random.Next(0, ENTRY_COUNT);
                 var operation = random.Next(0, 100);
                 if (operation < GET_PERCENTAGE)
                 {
                     map.Get(key.ToString());
                     Interlocked.Increment(ref stats.gets);
                 }
                 else if (operation < GET_PERCENTAGE + PUT_PERCENTAGE)
                 {
                     map.Put(key.ToString(), new byte[VALUE_SIZE]);
                     Interlocked.Increment(ref stats.puts);
                 }
                 else
                 {
                     map.Remove(key.ToString());
                     Interlocked.Increment(ref stats.removes);
                 }
             }
             catch (Exception ex)
             {
                 Interlocked.Increment(ref stats.exceptions);
                 Console.WriteLine("HATAAAAAA @" + ThreadUtil.GetThreadId());
                 Console.WriteLine(ex.Message);
                 //Console.ReadKey();
                 //break;
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("HATAAAAAA--BUYUK");
         Console.WriteLine(e.StackTrace);
     }
     Console.WriteLine("BITTIIIII");
 }
Beispiel #8
0
        public string Post([FromBody] RequestData data)
        {
            //client with custom configuration
            IHazelcastInstance client = CacheClient.Instance;

            Console.WriteLine(DateTime.Now + ": POST > Connected " + client.GetName());

            var map = client.GetMap <string, string>("mymap");

            Console.WriteLine(DateTime.Now + ": POST > Starting to set value");
            map.Put(data.Key, data.Value);
            Console.WriteLine(DateTime.Now + ": POST > Set value");

            return("ok");
        }
Beispiel #9
0
        public string Get(string key)
        {
            IHazelcastInstance client = CacheClient.Instance;

            Console.WriteLine(DateTime.Now + ": GET > Connected " + client.GetName());

            var map = client.GetMap <string, string>("mymap");

            Console.WriteLine(DateTime.Now + ": GET > Retrieving value");
            var result = map.Get(key);

            Console.WriteLine(DateTime.Now + ": GET > Retrieved value");

            return(result);
        }
Beispiel #10
0
        protected int GetUniquePartitionOwnerCount(IHazelcastInstance client)
        {
            //trigger partition table create
            client.GetMap <object, object>("default").Get(new object());

            var clientInternal   = ((HazelcastClient)client);
            var partitionService = clientInternal.PartitionService;
            var count            = partitionService.GetPartitionCount();
            var owners           = new HashSet <Guid>();

            for (var i = 0; i < count; i++)
            {
                var partitionOwner = partitionService.GetPartitionOwner(i);
                if (partitionOwner != null)
                {
                    owners.Add(partitionOwner.Value);
                }
            }
            return(owners.Count);
        }
Beispiel #11
0
        public Task <HealthCheckResult> CheckHealthAsync(
            HealthCheckContext context,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var map = hzInstance.GetMap <string, string>("my-distributed-map");
                //Standard Put and Get.
                map.Put("key", "value", 100, TimeUnit.Milliseconds);
                map.Get("key");
                //Concurrent Map methods, optimistic updating
                map.PutIfAbsent("somekey", "somevalue", 100, TimeUnit.Milliseconds);
                map.Replace("key", "value", "newvalue");

                return(Task.FromResult(HealthCheckResult.Healthy("The startup task is finished.")));
            }
            catch (Exception)
            {
                return(Task.FromResult(HealthCheckResult.Unhealthy("Hazelcast seems unhealthy")));
            }
        }
Beispiel #12
0
        private void ConnectToHZ()
        {
            var clientConfig = new ClientConfig();
            clientConfig.GetNetworkConfig().AddAddress("127.0.0.1");
            clientConfig.GetSerializationConfig().AddPortableFactory(PortableFactory.FactoryId, new PortableFactory());
            client = HazelcastClient.NewHazelcastClient(clientConfig);

            map = client.GetMap<CarKey, Car>("cars");

            //if (map != null && map.Size() == 0)
            //{
            //    //FILL
            //    for (int i = 1; i <= 100; i++)
            //    {
            //        CarKey key = new CarKey(i,"", "CAR_BRAND-"+i, "Model"+i, 1900+ i);

            //        Car car = new Car();
            //        car.ModelBody = "";
            //        car.ModelEngineCc = 1000+ i * 10;
            //        car.ModelEngineCyl = i % 12;
            //        car.ModelEngineType = "type"+i;
            //        car.ModelEngineValvesPerCyl = 2;
            //        car.ModelEnginePowerPs = 50 % i;
            //        car.ModelEngineCompression = "";
            //        car.ModelEngineFuel = "Gas";
            //        car.ModelTopSpeedKph = 150 + i;
            //        car.Model0To100Kph = i;
            //        car.ModelTransmissionType = "type"+i;
            //        car.ModelWeightKg = 800 + i*2;

            //        map.Put(key, car);
            //    }
            //}

            bindDataSet();
        }
Beispiel #13
0
        public Cache(string[] hosts)
        {
            try
            {
                var clientConfig = new ClientConfig();
                clientConfig.GetNetworkConfig().AddAddress(hosts);
                clientConfig.GetSerializationConfig().
                AddPortableFactory(PersonPortableFactory.FACTORY_ID, new PersonPortableFactory());

                _hazelcast = HazelcastClient.NewHazelcastClient(clientConfig);
                _map       = _hazelcast.GetMap <int, Person>("persons");

                Console.WriteLine("Hazelcast cluster addresses:");
                foreach (var h in hosts)
                {
                    Console.WriteLine(h);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Hazelcast: connection failed.");
                Console.WriteLine(e.Message);
            }
        }
        public static void HzTask(IHazelcastInstance hz)
        {
            try
            {
                var random = new Random();
                IMap<string, byte[]> map = hz.GetMap<String, byte[]>("default");
                int i = 0;
                while (true)
                {
                    //i++;
                    //if (i % 1000 == 0)
                    //{
                    //    Console.WriteLine("Iterate...."+i);
                    //}
                    try
                    {
                        int key = random.Next(0, ENTRY_COUNT);
                        int operation = random.Next(0, 100);
                        if (operation < GET_PERCENTAGE)
                        {
                            map.Get(key.ToString());
                            Interlocked.Increment(ref stats.gets);
                        }
                        else if (operation < GET_PERCENTAGE + PUT_PERCENTAGE)
                        {
                            map.Put(key.ToString(), new byte[VALUE_SIZE]);
                            Interlocked.Increment(ref stats.puts);
                        }
                        else
                        {
                            map.Remove(key.ToString());
                            Interlocked.Increment(ref stats.removes);
                        }
                    }
                    catch (Exception ex)
                    {
                        Interlocked.Increment(ref stats.exceptions);
                        Console.WriteLine("HATAAAAAA @" + ThreadUtil.GetThreadId());
                        Console.WriteLine(ex.Message);
                        //Console.ReadKey();
                        //break;
                    }

                }

            }
            catch (Exception e)
            {
                Console.WriteLine("HATAAAAAA--BUYUK");
                Console.WriteLine(e.StackTrace);
            }
            Console.WriteLine("BITTIIIII");
        }