@@ -130,18 +130,39 @@ void restart() {
130130 next ();
131131 }
132132
133+ final int nextFailureHandler (int limit ) {
134+ int index ;
135+ do {
136+ index = currentRouteNextFailureHandlerIndex ;
137+ if (index >= limit ) {
138+ return -1 ;
139+ }
140+ } while (!CURRENT_ROUTE_NEXT_FAILURE_HANDLER_INDEX .compareAndSet (this , index , index + 1 ));
141+ return index ;
142+ }
143+
144+ final int nextContextHandler (int limit ) {
145+ int index ;
146+ do {
147+ index = currentRouteNextHandlerIndex ;
148+ if (index >= limit ) {
149+ return -1 ;
150+ }
151+ } while (!CURRENT_ROUTE_NEXT_HANDLER_INDEX .compareAndSet (this , index , index + 1 ));
152+ return index ;
153+ }
154+
133155 boolean iterateNext () {
134156 boolean failed = failed ();
135157 if (currentRoute != null ) { // Handle multiple handlers inside route object
136158 try {
137- if (! failed && currentRoute . hasNextContextHandler ( this )) {
138- CURRENT_ROUTE_NEXT_HANDLER_INDEX . incrementAndGet (this );
159+ Handler < RoutingContext > handler ;
160+ if (! failed && ( handler = currentRoute . nextContextHandler (this )) != null ) {
139161 resetMatchFailure ();
140- currentRoute . handleContext (this );
162+ handler . handle (this );
141163 return true ;
142- } else if (failed && currentRoute .hasNextFailureHandler (this )) {
143- CURRENT_ROUTE_NEXT_FAILURE_HANDLER_INDEX .incrementAndGet (this );
144- currentRoute .handleFailure (this );
164+ } else if (failed && (handler = currentRoute .nextFailureHandler (this )) != null ) {
165+ handler .handle (this );
145166 return true ;
146167 }
147168 } catch (Throwable t ) {
@@ -169,12 +190,11 @@ boolean iterateNext() {
169190 if (LOG .isTraceEnabled ()) {
170191 LOG .trace ("Calling the " + (failed ? "failure" : "" ) + " handler" );
171192 }
172- if (failed && currentRoute .hasNextFailureHandler (this )) {
173- CURRENT_ROUTE_NEXT_FAILURE_HANDLER_INDEX .incrementAndGet (this );
174- routeState .handleFailure (this );
175- } else if (currentRoute .hasNextContextHandler (this )) {
176- CURRENT_ROUTE_NEXT_HANDLER_INDEX .incrementAndGet (this );
177- routeState .handleContext (this );
193+ Handler <RoutingContext > handler ;
194+ if (failed && (handler = currentRoute .nextFailureHandler (this )) != null ) {
195+ handler .handle (this );
196+ } else if ((handler = currentRoute .nextContextHandler (this )) != null ) {
197+ handler .handle (this );
178198 } else {
179199 continue ;
180200 }
@@ -257,4 +277,6 @@ protected void unhandledFailure(int statusCode, Throwable failure, RouterImpl ro
257277 private void resetMatchFailure () {
258278 this .matchFailure = 404 ;
259279 }
280+
281+
260282}
0 commit comments