List<String> jsonList = new ArrayList<String>(10); int taken = 0; for (Document doc : result) { if (taken >= 10) break; if (!doc.isStarred()) continue; taken++; final CountDownLatch rendezVous = new CountDownLatch(3); final JsonObject jsonBuffer = new JsonObject(); jsonBuffer.appendInt("id", doc.getId()); jsonBuffer.append("text", doc.getText()); CommentService.findForDoc(doc, new Callback<List<Comment>>() { public void onSuccess(List<Comment> comments) { final JsonObject commentArray = JsonObject.createArray(); CountDownLatch userLatch = new CountDownLatch(comments.size()); for (Comment c : comments) { JsonObject cj = new JsonObject(); cj.append("content", c.getText()); cj.append("date", c.getDate()); UserService.find(c.getUserId(), new Callback<User>() { public void onSuccess(User user) { cj.append("author", user.getName()); cj.append("nickname", user.getLogin()); Futures<T>? Callbacks? too easy to block (get) complex beyond 1 level of composition no composition have you heared of Callback Hell?
it doesn’t catch and recover Execute PoolControllerTest.testLastBlock() and verify it succeeds Sometimes it should print several “ELECTED” messages, this is the retry in action
for this month • ExchangeRateService ◦ rate retrieval method similar to current one ◦ use endpoint from exchange.nonfree.api.baseUrl • switch thanks to OnErrorResumeNext • use side effects ◦ log when we switch & track the cost
returned without blocking • subscribe on stream ◦ onNext: inject T via setResult ◦ onError: create a DogePoolException and inject it via setErrorResult
adapter of Observable to DeferredResult • each time an Observable is returned, it’ll be converted into this adapter ◦ WebAsyncUtils.getAsyncManager(...). startDeferredResultProcessing(...)
assert status().isOk() and request().asyncStarted() • trigger the async processing ◦ mockMvc.perform(asyncDispatch(mvcResult)) • from this point assert as before
- Jean-Daniel Echenard on Flickr ➔ Twin Falls - Blese on Flickr ➔ Tumbeast Gnawing on Servers - Matthew Inman on Wikimedia ➔ Trap - Anticiv on Flickr ➔ Kane Cleaning Supplies - Collinanderson on Flickr ➔ Chain - Stomchak on Wikimedia ➔ Takeaway - Edimburgh Blog on Flickr ➔ The End Sands - Elektro-Plan on Pixabay Cc0 By-Nd By-Nc By By-Sa By By By Cc0 Credits (2/2)