use of cn.bran.play.routing.RouterClass in project Japid by branaway.
the class JapidPlugin method buildRoutes.
private void buildRoutes() {
List<Route> oldRoutes = Router.routes;
List<Route> newRoutes = new ArrayList<Route>(oldRoutes.size());
if (this.lastApplicationClassloaderState == Play.classloader.currentState && recentAddedRoutes != null && this.ctxPath == Play.ctxPath) {
JapidFlags.debug("classloader state not changed. Use cached auto-routes.");
newRoutes = new ArrayList<Route>(recentAddedRoutes);
} else {
// rebuild the dynamic route table
long start = System.nanoTime();
boolean ctxChanged = this.ctxPath != Play.ctxPath;
for (ApplicationClass ac : Play.classes.all()) {
// check cache
RouterClass r = routerCache.get(ac.name);
if (r != null && !ctxChanged && r.matchHash(ac.sigChecksum)) {
// no change
// JapidFlags.debug(ac.name + " has not changed. ");
} else {
Class<?> javaClass = ac.javaClass;
if (javaClass != null && javaClass.getName().startsWith("controllers.") && javaClass.getAnnotation(AutoPath.class) != null) {
JapidFlags.debug("generate route for: " + ac.name);
r = new RouterClass(javaClass, appPath, ac.sigChecksum);
} else
continue;
}
this.routerCache.put(ac.name, r);
newRoutes.addAll(r.buildRoutes());
}
//
JapidFlags.debug("rebuilding auto paths took(/ms): " + StringUtils.durationInMsFromNanos(start, System.nanoTime()));
this.recentAddedRoutes = new ArrayList<Route>(newRoutes);
this.lastApplicationClassloaderState = Play.classloader.currentState;
}
// copy fixed routes from the old route
for (Iterator<Route> iterator = oldRoutes.iterator(); iterator.hasNext(); ) {
Route r = iterator.next();
if (r.routesFileLine != RouterMethod.AUTO_ROUTE_LINE) {
newRoutes.add(r);
}
}
Router.routes = newRoutes;
}
Aggregations