Showing posts from December, 2014

Java 8 Dynamic Filtering with Lambdas

REST API design

Java Runnable & Serializable

Java Runnable & Serializable

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

Google Angular vs Google Polymer


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 runningApply Smart Batching in the message pathWait-free algorithms in the message pathNon-blocking IO in the message pathNo exceptional cases in the message pathApply the Single Writer PrinciplePrefer unshared stateAvoid unnecessary data copies

High Throughput

Martin Thompson

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

Asynchronous retry pattern


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

Java 8 concurrent asynchronous lambda

Intellij recommends lambda alternatives where possible

      .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);

    new Thread( () -> {...} ).start();

Predicate - boolean expression:

    while (!acctStates.values().stream().allMatch(s -> {
return s.getState().equals(AcctState.OPEN);

Local method call:


Stream, Filter, Map, to new Collection:

Collection acctStates =
        accts.values().stream().filter(acct -> curUser.equals(acct.getOwner()))
            .map(acct -> acctStates.get(acct.getOwner())).filter(acct -> acct != null)