मैं अक्का अभिनेताओं और वायदा जानने के लिए कोशिश कर रहा हूँ द्वारा लेकिन http://akka.io पर डॉक्स पढ़ने और http://doc.akka.io/docs/akka/2.0.2/intro/getting-started-first-java.html कर मैं अभी भी समझ के साथ कुछ समस्याएं आ रही हैं के बाद समझौता। मुझे लगता है कि पीआई के मूल्य की गणना करना एक चीज है जो बहुत से लोग भी संबंधित हो सकते हैं, लेकिन मुझे नहीं =)। मैंने के आसपास खोज की है लेकिन मुझे कोई भी उदाहरण नहीं मिला है जो मुझे उपयुक्त बनाता है। इसलिए मैंने सोचा कि मैं अपने कुछ वास्तविक जीवन कोड ले जाऊंगा और इसे यहां फेंक दूंगा और अक्का के साथ ऐसा करने के उदाहरण के लिए इसका आदान-प्रदान करूंगा।अक्का अभिनेताओं और वायदा: उदाहरण के
ठीक है तो यहाँ हम चले:
मैं एक जावा play2 आवेदन जहां मैं अपने elasticsearch उदाहरण में मेरी DB और यह सूचकांक से कुछ डेटा लेने की जरूरत है।
मैं डीबी को कॉल करता हूं और स्थानों के लिए आईडी प्राप्त करता हूं।
मैं फिर सूची को विभाजित करता हूं और कुछ कॉल करने योग्य इंडेक्सस्क बनाता हूं।
इसके बाद मैं उन सभी कार्यों का आह्वान करता हूं जहां प्रत्येक कार्य डीबी से निर्दिष्ट आईडी के लिए स्थान एकत्र करता है।
प्रत्येक स्थान के लिए यह elasticsearch उदाहरण के लिए सूचकांक और इसे खोजने योग्य बनाते हैं।
हो गया।
Application.java:
public class Application extends Controller {
private static final int VENUE_BATCH = 1000;
private static int size;
public static Result index() {
List<Long> venueIds = DbService.getAllVenueIds();
size = venueIds.size();
Logger.info("Will index " + size + " items in total.");
ExecutorService service = Executors.newFixedThreadPool(getRuntime().availableProcessors());
int startIx = 0;
Collection<Callable<Object>> indexTasks = new ArrayList<Callable<Object>>();
do {
int endIx = Math.min(startIx + VENUE_BATCH, size);
List<Long> subList = venueIds.subList(startIx, endIx);
VenueIndexTask indexTask = new VenueIndexTask(subList);
indexTasks.add(indexTask);
} while ((startIx += VENUE_BATCH) < size);
Logger.info("Invoking all tasks!");
try {
service.invokeAll(indexTasks);
} catch (InterruptedException e) {
e.printStackTrace();
}
return ok(index.render("Done indexing."));
}
}
VenueTask:
public class VenueIndexTask implements Callable<Object> {
private List<Long> idSubList;
public VenueIndexTask(List<Long> idSubList){
this.idSubList = idSubList;
Logger.debug("Creating task which will index " + idSubList.size() + " items. " +
"Range: " + rangeAsString() + ".");
}
@Override
public Object call() throws Exception {
List<Venue> venues = DbService.getVenuesForIds(idSubList);
Logger.debug("Doing some indexing: "+venues.size());
for(Venue venue : venues) {
venue.index();
}
return null;
}
private String rangeAsString() {
return "[" + idSubList.get(0) + "-" + idSubList.get(idSubList.size() - 1) + "]";
}
}
स्थान:
@IndexType(name = "venue")
public class Venue extends Index {
private String name;
// Find method static for request
public static Finder<Venue> find = new Finder<Venue>(Venue.class);
public Venue() {
}
public Venue(String id, String name) {
super.id = id;
this.name = name;
}
@Override
public Map toIndex() {
HashMap map = new HashMap();
map.put("id", super.id);
map.put("name", name);
return map;
}
@Override
public Indexable fromIndex(Map map) {
if (map == null) {
return this;
}
this.name = (String) map.get("name");
return this;
}
}
तो आप सभी अक्का लोग वहां पागल हो जाते हैं! और कृपया जितना संभव हो उतना करें, कूल वायदा कार्यक्षमता का प्रस्ताव दें जिसका उपयोग किया जा सकता है या कोई अन्य ज्ञान/कोड जिसे मैं इस सामान को जानने के लिए उपयोग कर सकता हूं।
यह एक अच्छा सवाल है, लेकिन यह codereview.stackexchange.com पर बेहतर हो सकता है –