I had a few ideas I put together and would appreciate some feedback. A lot of it revolves around Java 8 but I kept all of the extensions themselves at Java 7. The main goal of Java 8 was to make constructing HttpHandlers easier when you delegate to other handlers.
Example:
Handlers.routing()
.add(Methods.GET, "/messages", HandlerBuilder
.create(CustomHandlers.json(Messages::getMessages))
.wrap(CustomHandlers::timing, "getMessages")
.wrap(BlockingHandler::new)
.build())
Please excuse the boring example I couldn't think of anything interesting.
If you run it locally
curl -X POST localhost:8080/messages/optional -d '{"title": "Optional", "message": "Using optional"}'
{"success":true}
curl -X POST localhost:8080/messages/lambda -d '{"title": "Lambda", "message": "Using Lambda"}'
{"success":true}
curl -X POST localhost:8080/messages -d '{"title": "Method References", "message": "Using method references"}'
{"success":true}
curl -X GET localhost:8080/messages
[
{
title: "Lambda",
message: "Using Lambda"
},
]
curl -X GET localhost:8080/info/metrics
{
version: "3.0.0",
gauges: { },
counters: { },
histograms: { },
meters:
{
response.status.code.200:
{
count: 8,
m15_rate: 21.787938213503697,
m1_rate: 6.5304307794735275,
m5_rate: 18.017228623496,
mean_rate: 4.457584495510739,
units: "events/minute"
}
},
timers:
{
createMessageLambda:
{
count: 1,
max: 1.169,
mean: 1.169,
min: 1.169,
p50: 1.169,
p75: 1.169,
p95: 1.169,
p98: 1.169,
p99: 1.169,
p999: 1.169,
stddev: 0,
m15_rate: 0.059490549916151686,
m1_rate: 0.1812199126454006,
m5_rate: 0.14211865026090975,
mean_rate: 0.5343847126926461,
duration_units: "milliseconds",
rate_units: "calls/minute"
},
createMessageMethodReferences:
{
-
count: 1,
max: 0.648,
mean: 0.648,
min: 0.648,
p50: 0.648,
p75: 0.648,
p95: 0.648,
p98: 0.648,
p99: 0.648,
p999: 0.648,
stddev: 0,
m15_rate: 0.05982197273776584,
m1_rate: 0.19696865690816925,
m5_rate: 0.14450714325124409,
mean_rate: 0.5343791108783038,
duration_units: "milliseconds",
rate_units: "calls/minute"
},
createMessageOptional:
{
count: 1,
max: 94.579,
mean: 94.579,
min: 94.579,
p50: 94.579,
p75: 94.579,
p95: 94.579,
p98: 94.579,
p99: 94.579,
p999: 94.579,
stddev: 0,
m15_rate: 10.678581251856285,
m1_rate: 2.0852873214053433,
m5_rate: 8.456257076624562,
mean_rate: 0.5343875445806129,
duration_units: "milliseconds",
rate_units: "calls/minute"
},
getMessages:
{
count: 3,
max: 9.809999999999999,
mean: 3.6413333333333333,
min: 0.514,
p50: 0.6,
p75: 9.809999999999999,
p95: 9.809999999999999,
p98: 9.809999999999999,
p99: 9.809999999999999,
p999: 9.809999999999999,
stddev: 5.342395093339066,
m15_rate: 0.18767034671569677,
m1_rate: 1.2185014871528328,
m5_rate: 0.49650226189858143,
mean_rate: 1.6030845484157583,
duration_units: "milliseconds",
rate_units: "calls/minute"
},
}
}