From 8f25091e896b1ab86986b6932d1bd0dde1d1b734 Mon Sep 17 00:00:00 2001 From: Elias N Vasylenko Date: Thu, 23 Mar 2017 11:17:35 +0000 Subject: [PATCH] Fix for #83 sort functions inside existing synchronized block. Rankings of exposed functions on the REST mapper are treated as final so they can be sorted when added rather than for each request. Signed-off-by: Elias N Vasylenko --- .../src/osgi/enroute/rest/simple/provider/RestMapper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osgi.enroute.rest.simple.provider/src/osgi/enroute/rest/simple/provider/RestMapper.java b/osgi.enroute.rest.simple.provider/src/osgi/enroute/rest/simple/provider/RestMapper.java index b58383b..0d7844a 100644 --- a/osgi.enroute.rest.simple.provider/src/osgi/enroute/rest/simple/provider/RestMapper.java +++ b/osgi.enroute.rest.simple.provider/src/osgi/enroute/rest/simple/provider/RestMapper.java @@ -156,6 +156,9 @@ public synchronized void addResource(REST resource, int ranking) { Function function = new Function(resource, m, verb, path, ranking); functions.add(function.getName(), function); + + Collections.sort(functions.get(function.getName()), + (a, b) -> Integer.compare(a.ranking, b.ranking)); } endpoints.add(resource); } @@ -259,9 +262,6 @@ public boolean execute(HttpServletRequest rq, HttpServletResponse rsp) throw new FileNotFoundException("No such method " + name + "/" + cardinality + ". Available: " + functions); - Collections.sort(candidates, - (a, b) -> Integer.compare(a.ranking, b.ranking)); - // // All values are arrays, turn them into singletons when // they have one element