};
}
private void route(final YokeRequest request, final PatternBinding binding, final Handler<Object> next) {
final Matcher m = binding.pattern.matcher(request.path());
final Vertx vertx = vertx();
if (m.matches()) {
final MultiMap params = request.params();
if (binding.paramNames != null) {
// Named params
new AsyncIterator<String>(binding.paramNames) {
@Override
public void handle(String param) {
if (hasNext()) {
params.set(param, m.group(param));
final Middleware paramMiddleware = paramProcessors.get(param);
if (paramMiddleware != null) {
// do not block main loop
vertx.runOnContext(new Handler<Void>() {
@Override
public void handle(Void event) {
paramMiddleware.handle(request, new Handler<Object>() {
@Override
public void handle(Object err) {
if (err == null) {
next();
} else {
next.handle(err);
}
}
});
}
});
} else {
next();
}
} else {
// middlewares
new AsyncIterator<Middleware>(binding.middleware) {
@Override
public void handle(final Middleware middleware) {
if (hasNext()) {
// do not block main loop
vertx.runOnContext(new Handler<Void>() {
@Override
public void handle(Void event) {
middleware.handle(request, new Handler<Object>() {
@Override
public void handle(Object err) {
if (err == null) {
next();
} else {
next.handle(err);
}
}
});
}
});
} else {
next.handle(null);
}
}
};
}
}
};
} else {
// Un-named params
for (int i = 0; i < m.groupCount(); i++) {
params.set("param" + i, m.group(i + 1));
}
// middlewares
new AsyncIterator<Middleware>(binding.middleware) {
@Override
public void handle(final Middleware middleware) {
if (hasNext()) {
// do not block main loop
vertx.runOnContext(new Handler<Void>() {
@Override
public void handle(Void event) {
middleware.handle(request, new Handler<Object>() {
@Override
public void handle(Object err) {