Showing posts from December, 2014

Java 8 Dynamic Filtering with Lambdas

Dynamic Filtering Gist

REST API design

REST API design REST Best Practices REST tools and frameworks API Transformer Best Practices

Java Runnable & Serializable

Java Runnable & Serializable Runnable r = (Runnable & Serializable)() -> System.out.println("Serializable!");

Google Angular vs Google Polymer

Article Angular is a complete framework for building webapps, whereas Polymer is a library for creating Web Components. Those components, however, can then be used to build a webapp. Can Angular and Polymer be used together? Yes! You can use Polymer custom elements inside of an Angular app. Web components are just regular DOM elements, so they have attributes, emit events, and can contain child elements. What about the future of both projects? Angular and Polymer will remain separate projects with their own goals. That said, Angular has  announced  they’ll eventually move to use the Web Components APIs in their underlying architecture. For Angular 2.0, Web Components will work seamlessly within Angular apps and directives, and components written in Angular will export to Web Components to be used by Polymer or other libraries.

Aeron Messaging 6M mesgs/sec

Aeron: Do We Really Need Another Messaging System At its core Aeron is a replicated persistent log of messages. And through a very conscious design process messages are wait-free and zero-copy along the entire path from publication to reception. This means latency is very good and very predictable. It’s not a full featured messaging product in the way you may be used to, like Kafka. Aeron does not persist messages, it doesn’t support guaranteed delivery, nor clustering, nor does it support topics. Aeron won’t know if a client has crashed and be able to sync it back up from history or initialize a new client from history. Aeron - Martin Thompson Aeron - github Design Principles Garbage free in steady state running Apply Smart Batching in the message path Wait-free algorithms in the message path Non-blocking IO in the message path No exceptional cases in the message path Apply the Single Writer Principle Prefer unshared state Avoid unnecessary data copies

High Throughput

Martin Thompson HDR Histogram Batching for efficiency Observable state machines without locking - histogram state changes

Asynchronous retry pattern

Libary ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); RetryExecutor executor = new AsyncRetryExecutor(scheduler).     retryOn(SocketException.class).     withExponentialBackoff(500, 2).     //500ms times 2 after each retry     withMaxDelay(10_000).               //10 seconds     withUniformJitter().                //add between +/- 100 ms randomly     withMaxRetries(20);

Java 8 concurrent asynchronous lambda

Intellij recommends lambda alternatives where possible CompletableFuture       .supplyAsync(() -> validateRequest(id, headers))       .thenAccept(id -> processRequest(id, req))       .exceptionally(t -> handleException(throable, req)); supplyAsync returns a new CompletableFuture that is asynchronously completed by a task running in the  ForkJoinPool.commonPool() Thread Runnable:     Runnable r = () -> {...};    Thread t = new Thread(r);     t.start();     new Thread( () -> {...} ).start(); Predicate - boolean expression:     while (!acctStates.values().stream().allMatch(s -> {       return s.getState().equals(AcctState.OPEN) ;     }))     {       Thread.sleep(100);     } Local method call: getSomeCollection().forEach( this::processElement ); Stream, Filter, Map, to new Collection: Collection acctStates =         accts.values(). stream().filter (acct -> curUser.equals(acct.getOwner()))             . map (acct -> acctStates.g