Skip to content

Commit

Permalink
Interceptor API tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Jan 20, 2019
1 parent c22aeaa commit af9153d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -35,6 +35,14 @@ public interface IInterceptorRegistry {
@VisibleForTesting
void clearAnonymousHookForUnitTest();

/**
* Register an interceptor
*
* @param theInterceptor The interceptor to register
* @return Returns <code>true</code> if at least one valid hook method was found on this interceptor
*/
boolean registerGlobalInterceptor(Object theInterceptor);

/**
* Invoke the interceptor methods
*/
Expand Down
Expand Up @@ -95,14 +95,17 @@ public void start() {

}

private void registerGlobalInterceptor(Object theNextInterceptor) {
@Override
public boolean registerGlobalInterceptor(Object theInterceptor) {
boolean retVal = false;

int typeOrder = DEFAULT_ORDER;
Order typeOrderAnnotation = AnnotationUtils.findAnnotation(theNextInterceptor.getClass(), Order.class);
Order typeOrderAnnotation = AnnotationUtils.findAnnotation(theInterceptor.getClass(), Order.class);
if (typeOrderAnnotation != null) {
typeOrder = typeOrderAnnotation.value();
}

for (Method nextMethod : theNextInterceptor.getClass().getDeclaredMethods()) {
for (Method nextMethod : theInterceptor.getClass().getDeclaredMethods()) {
Hook hook = AnnotationUtils.findAnnotation(nextMethod, Hook.class);

if (hook != null) {
Expand All @@ -113,14 +116,16 @@ private void registerGlobalInterceptor(Object theNextInterceptor) {
methodOrder = methodOrderAnnotation.value();
}

HookInvoker invoker = new HookInvoker(hook, theNextInterceptor, nextMethod, methodOrder);
HookInvoker invoker = new HookInvoker(hook, theInterceptor, nextMethod, methodOrder);
for (Pointcut nextPointcut : hook.value()) {
myInvokers.put(nextPointcut, invoker);
}

retVal = true;
}
}

myGlobalInterceptors.add(theNextInterceptor);
myGlobalInterceptors.add(theInterceptor);

// Make sure we're always sorted according to the order declared in
// @Order
Expand All @@ -129,6 +134,8 @@ private void registerGlobalInterceptor(Object theNextInterceptor) {
List<BaseInvoker> nextInvokerList = myInvokers.get(nextPointcut);
nextInvokerList.sort(Comparator.naturalOrder());
}

return retVal;
}

private void sortByOrderAnnotation(List<Object> theObjects) {
Expand Down

0 comments on commit af9153d

Please sign in to comment.