Skip to content

Instantly share code, notes, and snippets.

View enesakar's full-sized avatar

Enes Akar enesakar

View GitHub Profile
@enesakar
enesakar / sample jsp
Created July 10, 2017 21:23
sample hazelcast jsp
<%@ 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"));
@enesakar
enesakar / execservice.java
Last active March 16, 2017 12:04
exec service hazelcast
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);
@enesakar
enesakar / hzaggregation.java
Created October 13, 2015 17:36
hazelcast aggregation count with filter
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);
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) {
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 {
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);
}
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());
}
}
@enesakar
enesakar / gist:3a7594c83f1b27fbc202
Created February 20, 2015 08:34
hazelcast regex predicate example
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);
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;
@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);