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(); }
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(); }
public void Setup() { _remoteController = CreateRemoteController(); _cluster = CreateCluster(_remoteController); StartMember(_remoteController, _cluster); _client = CreateClient(); }
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 //} }
public void Setup() { _initialMembershipListener = new InitialMembershipListener(); _remoteController = CreateRemoteController(); _cluster = CreateCluster(_remoteController); StartMember(_remoteController, _cluster); _client = CreateClient(); }
public HazelcastHealthCheck(IMessagePublisher messagePublisher, IMessagingClient messagingClient, HazelcastConfig configuration) { this.messagePublisher = messagePublisher; this.messagingClient = messagingClient; this.configuration = configuration; this.hzInstance = GetHazelcastInstance(); }
public void Setup() { _remoteController = CreateRemoteController(); _cluster = CreateCluster(_remoteController); StartMember(_remoteController, _cluster); _client = CreateClient(); _client.GetMap <object, object>("default").Get(new object()); }
public Performance() { client = HazelcastClient.NewHazelcastClient(clientHzFile); tasks = new HashSet<MyTask>(); for (int i = 0; i < threadCount; i++) { tasks.Add(new MyTask()); } }
protected object GenerateKeyForPartition(IHazelcastInstance client, int partitionId) { var partitionService = ((HazelcastClientProxy)client).GetClient().GetClientPartitionService(); while (true) { var randomKey = TestSupport.RandomString(); if (partitionService.GetPartitionId(randomKey) == partitionId) { return(randomKey); } } }
protected int GetUniquePartitionOwnerCount(IHazelcastInstance client) { var proxy = ((HazelcastClientProxy)client); var partitionService = proxy.GetClient().GetClientPartitionService(); var count = partitionService.GetPartitionCount(); var owners = new HashSet <Address>(); for (var i = 0; i < count; i++) { owners.Add(partitionService.GetPartitionOwner(i)); } return(owners.Count); }
protected void StopMemberAndWait(IHazelcastInstance client, RemoteController.Client remoteController, Cluster cluster, Member member) { var resetEvent = new ManualResetEventSlim(); var regId = client.GetCluster().AddMembershipListener(new MembershipListener { OnMemberRemoved = @event => resetEvent.Set() }); StopMember(remoteController, cluster, member); Assert.IsTrue(resetEvent.Wait(120 * 1000), "The member did not get removed in 120 seconds"); Assert.IsTrue(client.GetCluster().RemoveMembershipListener(regId)); }
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"); }
public void InitFixture() { Environment.SetEnvironmentVariable("hazelcast.logging.type", "console"); if (Cluster == null) { Cluster = new HazelcastCluster(1); Cluster.Start(); } else { Assert.AreEqual(1, Cluster.Size); } Client = CreateClient(); }
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); }
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"); }
public static Task <bool> WaitForClientState(IHazelcastInstance instance, LifecycleEvent.LifecycleState state) { var task = new TaskCompletionSource <bool>(); var regId = instance.GetLifecycleService().AddLifecycleListener(new LifecycleListener(l => { if (l.GetState() == state) { task.TrySetResult(true); } })); task.Task.ContinueWith(f => { instance.GetLifecycleService().RemoveLifecycleListener(regId); }).IgnoreExceptions(); return(task.Task); }
private static void Main11(string[] args) { Environment.SetEnvironmentVariable("hazelcast.logging.class", "console"); Console.WriteLine("INIT APP"); ClientConfig clientConfig = new ClientConfig(); clientConfig.SetNetworkConfig(new ClientNetworkConfig().AddAddress(("127.0.0.1:5701"))); IHazelcastInstance client = HazelcastClient.NewHazelcastClient(clientConfig); var queue = client.GetQueue <byte[]>("a queue"); var watch = Stopwatch.StartNew(); var task = Task.Factory.StartNew( () => { byte[] loop = queue.Poll(15, TimeUnit.SECONDS); while (loop != null && loop.Length != 0) { loop = queue.Poll(15, TimeUnit.SECONDS); if (loop != null) { var a = new [] { loop[0], loop[1] }; Console.WriteLine(BitConverter.ToInt16(a, 0)); } } }); const int byteLen = 1024 * 500; byte[] buf = new byte[byteLen]; for (int i = 0; i < 1000; ++i) { byte[] bytes = BitConverter.GetBytes((short)i); Array.Copy(bytes, buf, bytes.Length); queue.Put(buf); } queue.Put(new byte[0]); task.Wait(); var elapsed = watch.Elapsed; Console.WriteLine("Time: {0}", elapsed.TotalMilliseconds); client.Shutdown(); }
protected Member StartMemberAndWait(IHazelcastInstance client, IRemoteController remoteController, Cluster cluster, int expectedSize) { var resetEvent = new ManualResetEventSlim(); var regId = client.Cluster.AddMembershipListener(new MembershipListener { OnMemberAdded = @event => resetEvent.Set() }); var member = StartMember(remoteController, cluster); Assert.IsTrue(resetEvent.Wait(120 * 1000), "The member did not get added in 120 seconds"); Assert.IsTrue(client.Cluster.RemoveMembershipListener(regId)); // make sure partitions are updated TestSupport.AssertTrueEventually(() => { Assert.AreEqual(expectedSize, GetUniquePartitionOwnerCount(client)); }, 60, "The partition list did not contain " + expectedSize + " partitions."); return(member); }
/// <summary>Create a Hazelcast client</summary> /// <returns>Promise of void</returns> private async Task CreateHazelcastClient() { Environment.SetEnvironmentVariable("hazelcast.logging.level", "info"); Environment.SetEnvironmentVariable("hazelcast.logging.type", "console"); var config = new ClientConfig(); var hostname = Environment.GetEnvironmentVariable("HOSTNAME") ?? "localhost"; var port = Environment.GetEnvironmentVariable("PORT") != null?Convert.ToUInt32(Environment.GetEnvironmentVariable("PORT"), 10) : 5900; var serializerConfig = new SerializerConfig(); serializerConfig.SetImplementation(new Message()).SetTypeClass(typeof(CommonMessage)); config.GetSerializationConfig().AddSerializerConfig(serializerConfig); config.GetNetworkConfig().AddAddress(hostname + ":" + port); Client = Task.Run(() => HazelcastClient.NewHazelcastClient(config)).Result; _nodeId = Client.GetLocalEndpoint().GetUuid(); }
static void Main111(string[] args) { Environment.SetEnvironmentVariable("hazelcast.logging.type", "console"); ClientConfig clientConfig = new ClientConfig(); clientConfig.SetNetworkConfig(new ClientNetworkConfig().AddAddress(("127.0.0.1:5701"))); IHazelcastInstance instance = HazelcastClient.NewHazelcastClient(clientConfig); var locker = instance.GetLock("processLock"); Console.WriteLine("Waiting for lock"); locker.Lock(); Console.WriteLine("Locked"); Console.ReadLine(); locker.Unlock(); instance.Shutdown(); }
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); }
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(); }
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 HazelcastClientManagedContext(IHazelcastInstance instance, IManagedContext externalContext) { _instance = instance; _externalContext = externalContext; _hasExternalContext = _externalContext != null; }
public void InitFixture() { Environment.SetEnvironmentVariable("hazelcast.logging.type", "console"); Environment.SetEnvironmentVariable("hazelcast.logging.level", "finest"); if (Cluster == null) { Cluster = new HazelcastCluster(1); Cluster.Start(); } else { Assert.AreEqual(1, Cluster.Size); } Client = CreateClient(); }
public HazelcastClientManagedContext(IHazelcastInstance instance, IManagedContext externalContext) { this.instance = instance; this.externalContext = externalContext; hasExternalContext = this.externalContext != null; }
static void Main(string[] args) { Environment.SetEnvironmentVariable("hazelcast.logging.type", "console"); Environment.SetEnvironmentVariable("hazelcast.client.request.timeout", "250000"); var clientConfig = new ClientConfig(); clientConfig.GetNetworkConfig().AddAddress("192.168.2.50:5701"); clientConfig.GetNetworkConfig().SetConnectionAttemptLimit(1000); hazelcast = HazelcastClient.NewHazelcastClient(clientConfig); Console.WriteLine("Client Ready to go"); stats = new Stats(); //Thread.Sleep(100000); if (args != null && args.Length > 0) { foreach (string _arg in args) { string arg = _arg.Trim(); //if (arg.startsWith("t")) { // THREAD_COUNT = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("c")) { // ENTRY_COUNT = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("v")) { // VALUE_SIZE = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("g")) { // GET_PERCENTAGE = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("p")) { // PUT_PERCENTAGE = Integer.parseInt(arg.substring(1)); //} } } else { Console.WriteLine("Help: sh test.sh t200 v130 p10 g85 "); Console.WriteLine(" // means 200 threads, value-size 130 bytes, 10% put, 85% get"); Console.WriteLine(""); } Console.WriteLine("Starting Test with "); Console.WriteLine(" Thread Count: " + THREAD_COUNT); Console.WriteLine(" Entry Count: " + ENTRY_COUNT); Console.WriteLine(" Value Size: " + VALUE_SIZE); Console.WriteLine(" Get Percentage: " + GET_PERCENTAGE); Console.WriteLine(" Put Percentage: " + PUT_PERCENTAGE); Console.WriteLine(" Remove Percentage: " + (100 - (PUT_PERCENTAGE + GET_PERCENTAGE))); var tasks = new List<Task>(); for (int i = 0; i < THREAD_COUNT; i++) { var t = new Task(()=> HzTask(hazelcast),TaskCreationOptions.LongRunning); tasks.Add(t); t.Start(); } var tm = new Thread(StatDisplayTask); tm.Start(); Task.WaitAll(tasks.ToArray()); tm.Abort(); Console.WriteLine("--THE END--"); //Task.Factory.StartNew(StatDisplayTask); //startNew.Wait(); //StatDisplayTask(); //Task.Factory.Scheduler.MaximumConcurrencyLevel = THREAD_COUNT; Console.ReadKey(); }
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"); }
protected Member StartMemberAndWait(IHazelcastInstance client, RemoteController.Client remoteController, Cluster cluster, int expectedSize) { var resetEvent = new ManualResetEventSlim(); var regId = client.GetCluster().AddMembershipListener(new MembershipListener { OnMemberAdded = @event => resetEvent.Set() }); var member = StartMember(remoteController, cluster); Assert.IsTrue(resetEvent.Wait(120*1000), "The member did not get added in 120 seconds"); Assert.IsTrue(client.GetCluster().RemoveMembershipListener(regId)); // make sure partitions are updated TestSupport.AssertTrueEventually( () => { Assert.AreEqual(expectedSize, GetUniquePartitionOwnerCount(client)); }, 60, "The partition list did not contain " + expectedSize + " partitions."); return member; }
protected int GetUniquePartitionOwnerCount(IHazelcastInstance client) { var proxy = ((HazelcastClientProxy) client); var partitionService = proxy.GetClient().GetClientPartitionService(); var count = partitionService.GetPartitionCount(); var owners = new HashSet<Address>(); for (var i = 0; i < count; i++) { owners.Add(partitionService.GetPartitionOwner(i)); } return owners.Count; }
private static void Main(string[] args) { Environment.SetEnvironmentVariable("hazelcast.logging.type", "console"); Environment.SetEnvironmentVariable("hazelcast.client.request.timeout", "250000"); var clientConfig = new ClientConfig(); clientConfig.GetNetworkConfig().AddAddress("192.168.2.50:5701"); clientConfig.GetNetworkConfig().SetConnectionAttemptLimit(1000); hazelcast = HazelcastClient.NewHazelcastClient(clientConfig); Console.WriteLine("Client Ready to go"); stats = new Stats(); //Thread.Sleep(100000); if (args != null && args.Length > 0) { foreach (var _arg in args) { var arg = _arg.Trim(); //if (arg.startsWith("t")) { // THREAD_COUNT = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("c")) { // ENTRY_COUNT = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("v")) { // VALUE_SIZE = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("g")) { // GET_PERCENTAGE = Integer.parseInt(arg.substring(1)); //} else if (arg.startsWith("p")) { // PUT_PERCENTAGE = Integer.parseInt(arg.substring(1)); //} } } else { Console.WriteLine("Help: sh test.sh t200 v130 p10 g85 "); Console.WriteLine(" // means 200 threads, value-size 130 bytes, 10% put, 85% get"); Console.WriteLine(""); } Console.WriteLine("Starting Test with "); Console.WriteLine(" Thread Count: " + THREAD_COUNT); Console.WriteLine(" Entry Count: " + ENTRY_COUNT); Console.WriteLine(" Value Size: " + VALUE_SIZE); Console.WriteLine(" Get Percentage: " + GET_PERCENTAGE); Console.WriteLine(" Put Percentage: " + PUT_PERCENTAGE); Console.WriteLine(" Remove Percentage: " + (100 - (PUT_PERCENTAGE + GET_PERCENTAGE))); var tasks = new List <Task>(); for (var i = 0; i < THREAD_COUNT; i++) { var t = new Task(() => HzTask(hazelcast), TaskCreationOptions.LongRunning); tasks.Add(t); t.Start(); } var tm = new Thread(StatDisplayTask); tm.Start(); Task.WaitAll(tasks.ToArray()); tm.Abort(); Console.WriteLine("--THE END--"); //Task.Factory.StartNew(StatDisplayTask); //startNew.Wait(); //StatDisplayTask(); //Task.Factory.Scheduler.MaximumConcurrencyLevel = THREAD_COUNT; Console.ReadKey(); }
protected void StopMemberAndWait(IHazelcastInstance client, RemoteController.Client remoteController, Cluster cluster, Member member) { var resetEvent = new ManualResetEventSlim(); var regId = client.GetCluster().AddMembershipListener(new MembershipListener { OnMemberRemoved = @event => resetEvent.Set() }); StopMember(remoteController, cluster, member); Assert.IsTrue(resetEvent.Wait(120*1000), "The member did not get removed in 120 seconds"); Assert.IsTrue(client.GetCluster().RemoveMembershipListener(regId)); }
public ISerializationServiceBuilder SetHazelcastInstance(IHazelcastInstance hazelcastInstance) { _hazelcastInstance = hazelcastInstance; return(this); }
public ISerializationServiceBuilder SetHazelcastInstance(IHazelcastInstance hazelcastInstance) { this._hazelcastInstance = hazelcastInstance; return this; }