Search in sources :

Example 1 with TimeInstanceAwareCallable

use of tasks.TimeInstanceAwareCallable in project microservices by pwillhan.

the class ExecutionInstanceAwareExample method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);
    ExecutorService exec = hz.getExecutorService("exec");
    while (true) {
        Future<String> timeFuture = exec.submit(new TimeInstanceAwareCallable());
        String theTime = timeFuture.get();
        System.err.println("The time is: " + theTime);
        Thread.sleep(1000);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ExecutorService(java.util.concurrent.ExecutorService) TimeInstanceAwareCallable(tasks.TimeInstanceAwareCallable)

Example 2 with TimeInstanceAwareCallable

use of tasks.TimeInstanceAwareCallable in project microservices by pwillhan.

the class ExecutionOnMemberExample method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);
    Member thisMember = hz.getCluster().getLocalMember();
    IExecutorService exec = hz.getExecutorService("exec");
    Callable<String> timeTask = new TimeInstanceAwareCallable();
    Member member = thisMember;
    Future<String> specificTask = exec.submitToMember(timeTask, member);
    String timeFromSpecificMember = specificTask.get(10, TimeUnit.SECONDS);
    System.err.println(timeFromSpecificMember);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IExecutorService(com.hazelcast.core.IExecutorService) Member(com.hazelcast.core.Member) TimeInstanceAwareCallable(tasks.TimeInstanceAwareCallable)

Example 3 with TimeInstanceAwareCallable

use of tasks.TimeInstanceAwareCallable in project microservices by pwillhan.

the class MultiExecutionExample method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);
    IExecutorService exec = hz.getExecutorService("exec");
    Callable<String> timeTask = new TimeInstanceAwareCallable();
    MultiExecutionCallback callback = new MultiExecutionCallback() {

        @Override
        public void onResponse(Member member, Object theTime) {
            System.err.println("Received: " + theTime);
        }

        @Override
        public void onComplete(Map<Member, Object> theTimes) {
            for (Object theTime : theTimes.values()) {
                System.err.println("Complete: " + theTime);
            }
        }
    };
    while (true) {
        Set<Member> clusterMembers = hz.getCluster().getMembers();
        exec.submitToMembers(timeTask, clusterMembers, callback);
        Thread.sleep(1000);
    }
}
Also used : Config(com.hazelcast.config.Config) TimeInstanceAwareCallable(tasks.TimeInstanceAwareCallable) Map(java.util.Map)

Aggregations

Config (com.hazelcast.config.Config)3 TimeInstanceAwareCallable (tasks.TimeInstanceAwareCallable)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 IExecutorService (com.hazelcast.core.IExecutorService)1 Member (com.hazelcast.core.Member)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1