The Artima Developer Community
Sponsored Link

Java Buzz Forum
Hazelcast 1.2beta: Distributed ExecutorService

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Talip Ozturk

Posts: 103
Nickname: talip
Registered: May, 2003

Talip Ozturk is founder of Hazelcast, distributed queue, set, map and lock implementation.
Hazelcast 1.2beta: Distributed ExecutorService Posted: Aug 26, 2008 7:10 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Talip Ozturk.
Original Post: Hazelcast 1.2beta: Distributed ExecutorService
Feed Title: Shared Memory
Feed URL: http://www.jroller.com/talipozturk/feed/entries/rss
Feed Description: about java, jcache, jini, javaspaces, distributed data structures and a little bit of me and life.
Latest Java Buzz Posts
Latest Java Buzz Posts by Talip Ozturk
Latest Posts From Shared Memory

Advertisement
Another big milestone for Hazelcast: Distributed implementation of java.util.concurrent.ExecutorService is now available for download. It is time to execute code on cluster. You can tell Hazelcast to execute your code (Runnable, Callable):
  • on a specific cluster member you choose.
  • on the member owning the key you choose.
  • on the member Hazelcast will pick.
  • on all or subset of the cluster members.

Sample code will make it more understandable so let say you have a Echo callable that you want to execute:

import java.util.concurrent.Callable;
import java.io.Serializable;

public class Echo implements Callable, Serializable {
       String input = null;
       public Echo() {
               super();
       }
       public Echo(String input) {
               super();
               this.input = input;
       }
       public String call() {
               return Hazelcast.getCluster().getLocalMember().toString() + ":"
                               + input;
       }
}

Here are the methods to execute the Echo in a distributed way:

import com.hazelcast.core.Member;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.MultiTask;
import com.hazelcast.core.DistributedTask;
import java.util.concurrent.ExecutorService;   
import java.util.concurrent.FutureTask;   
import java.util.concurrent.Future;   
import java.util.Set;

public void echoOnTheMember(String input, Member member) throws Exception {
       FutureTask task = new DistributedTask(new Echo(input), member);
       ExecutorService executorService = Hazelcast.getExecutorService();
       executorService.execute(task);
       String echoResult = task.get();
}

public void echoOnTheMemberOwningTheKey(String input, Object key) throws Exception {
       FutureTask task = new DistributedTask(new Echo(input), key);
       ExecutorService executorService = Hazelcast.getExecutorService();
       executorService.execute(task);
       String echoResult = task.get();
}

public void echoOnSomewhere(String input) throws Exception { 
       ExecutorService executorService = Hazelcast.getExecutorService();
       Future task = executorService.submit(new Echo(input));
       String echoResult = task.get();
}

public void echoOnMembers(String input, Set members) throws Exception {
       MultiTask task = new MultiTask(new Echo(input), members);
       ExecutorService executorService = Hazelcast.getExecutorService();
       executorService.execute(task);
       Collection result = task.get(); 
} 

I plan to add couple of more features before the 1.2final such as executing multiple callable|runnables in shot. Make sure you check out the documentation at hazelcast.com for complete list of features and more sample code.

Feedback is always welcomed (oztalip@gmail.com or hazelcast@googlegroups.com)

Read: Hazelcast 1.2beta: Distributed ExecutorService

Topic: Biggest Db4o Gotcha! Previous Topic   Next Topic Topic: Australian Tortoise Beetle

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use