ZooKeeper for configuration management in JavaEE

A very important principle in continuous delivery is to build your application binaries only once and then let the exact same binary flow through each step of the deployment pipeline, where each step evaluates the binary from different perspectives in order to prove that the binary actually is a release candidate.

A typical flow might look something like this:
Commit stage (build, unit test, analysis) => Automated acceptance tests => Capacity testing => User acceptance testing => Production

Many of these steps will often require different configuration of the application. We might for instance want to stub out some backend services in our automated acceptance tests and use different endpoints in our UAT and production environments.

A typical convention in Java EE is to package configuration inside the war or ear along with the rest of the application. This is encouraged by the specification. Since the application is configured at build time, this means that you have to create a different war or ear for many different steps of the deployment pipeline. This is a serious risk. To mitigate this we have to find another way to configure the application at deployment or run time.

Continue reading ZooKeeper for configuration management in JavaEE

Timestamps on entities with EntityListener

This example shows how you can add timestamps to your entities in a non-intrusive unified way with plain JPA.

We start off with an embeddable JPA entity, TimeStamp:

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.util.Date;

@Embeddable
public class TimeStamp {

    @Column(name = "date_created")
    @Temporal(TemporalType.TIMESTAMP)
    private Date created;

    @Column(name = "date_updated")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updated;

    // getters, setters, etc
}

Continue reading Timestamps on entities with EntityListener

Java 8 Stream and Lambda code kata

I just added a code kata for learning the Stream and Lambda API’s in Java 8.

The purpose of a kata is to repeat a simple exercise over and over again, making small improvements for each iteration, until you basically can do the exercise blind folded.

I find this to be one of the most effective ways to improve basic coding skills and to learn new things.

Feel free to fork and submit your own “perfectionnized” solution.

Link: https://github.com/JorgenRingen/stream-lambda-kata

Logging – Why your threads should have a meaningful name

Ever seen this kind of output in your logs?

18:33:51,083 INFO  [org.example.business.PersonResource] (default task-2) Validation error. Returning status-code 400

What’s the problem with this log-message? We know that some validation has failed and that a status-code 400 was returned. Other than that it doesn’t provide a lot more information other than the time of the event and the name of the class that logged the message.

Continue reading Logging – Why your threads should have a meaningful name