This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%@ page import="com.hazelcast.core.Hazelcast" %> | |
| <%@ page import="com.hazelcast.core.HazelcastInstance" %> | |
| <%@ page import="com.hazelcast.client.HazelcastClient" %> | |
| <%@ page import="com.hazelcast.core.IMap" %> | |
| <%@ page import="java.util.Random" %> | |
| <html> | |
| <body> | |
| <% | |
| final int size = request.getParameter("size") == null ? 1000 : Integer.parseInt(request.getParameter("size")); | |
| final int get = request.getParameter("get") == null ? 60 : Integer.parseInt(request.getParameter("get")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface Task<String> extends Callable<String>, Serializable { | |
| String call(); | |
| } | |
| public static void main(String[] args) throws InterruptedException, TimeoutException, ExecutionException { | |
| final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(); | |
| final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(); | |
| ExecutorService ss = Executors.newFixedThreadPool(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void main(String[] args) throws InterruptedException { | |
| HazelcastInstance instance = Hazelcast.newHazelcastInstance(new Config()); | |
| IMap<Integer, Person> map = instance.getMap("map"); | |
| for (int i = 0; i < 100; i++) { | |
| map.put(i, new Person("name" + i, i % 10)); | |
| } | |
| Supplier supplier = Supplier.all(new AgeExtractor(5)); | |
| Aggregation aggregation = Aggregations.count(); | |
| Long count = (Long) map.aggregate(supplier, aggregation); | |
| System.out.println("count:"+count); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void main(String[] args) throws ExecutionException, InterruptedException { | |
| Config cfg = new Config(); | |
| HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg); | |
| HazelcastInstance client= HazelcastClient.newHazelcastClient(); | |
| final IExecutorService ex = client.getExecutorService("ex"); | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| while (true) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void main(String[] args) throws ExecutionException, InterruptedException { | |
| Config cfg = new Config(); | |
| HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg); | |
| final IExecutorService ex = instance.getExecutorService("ex"); | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| while (true) { | |
| Map<Member, Future<String>> futureMap = ex.submitToAllMembers(new GetInstanceNameCallable()); | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void main(String[] args) throws ExecutionException, InterruptedException { | |
| final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(); | |
| final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(); | |
| IExecutorService exec = instance1.getExecutorService("exec"); | |
| List<Future> flist = new ArrayList<Future>(); | |
| for (int i = 0; i < 10; i++) { | |
| Future<Object> future = exec.submitToKeyOwner(new TaskCallable(i), i); | |
| flist.add(future); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void main(String[] args) throws InterruptedException, ExecutionException { | |
| final HazelcastInstance hz = Hazelcast.newHazelcastInstance(new Config("instance1")); | |
| final HazelcastInstance hz2 = Hazelcast.newHazelcastInstance(new Config("instance2")); | |
| IExecutorService collector = hz.getExecutorService("nameCollector"); | |
| Map<Member, Future<String>> map = collector.submitToAllMembers(new GetInstanceNameCallable()); | |
| for (Future<String> future : map.values()) { | |
| System.out.println(future.get()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| final HazelcastInstance hz = Hazelcast.newHazelcastInstance(null); | |
| IMap employees = hz.getMap("employees"); | |
| employees.put(1, new Employee("xxx zz yyy")); | |
| employees.put(2, new Employee("aaa bb ccc")); | |
| Collection<Employee> result = employees.values(Predicates.regex("employeeName", "x+.*")); | |
| for (Employee employee : result) { | |
| System.out.println(employee.employeeName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.hazelcast.test; | |
| import com.hazelcast.core.HazelcastInstance; | |
| import com.hazelcast.core.IMap; | |
| import com.hazelcast.core.ISet; | |
| public class MapFactory { | |
| ISet<String> destroyedMapNames; | |
| HazelcastInstance instance; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void testSplitBrain2() throws InterruptedException { | |
| Config config = new Config(); | |
| config.getGroupConfig().setName("split"); | |
| config.setProperty(GroupProperties.PROP_MERGE_FIRST_RUN_DELAY_SECONDS, "5"); | |
| config.setProperty(GroupProperties.PROP_MERGE_NEXT_RUN_DELAY_SECONDS, "5"); | |
| MapConfig mapConfig = new MapConfig(); | |
| mapConfig.setName("ClusterMap"); | |
| mapConfig.setBackupCount(2); |