/** * Scope is starting, perform the required processing on the supplied handlers. */ public void processStartOfScope(Scope scopeStarting, Iterable<Object> handlerInstances) throws Exception { for (Object handler : handlerInstances) { Handler handlerAnnotation = handler.getClass().getAnnotation(Handler.class); Scope handlerScope = handlerAnnotation.scope(); injectResourceFieldsForScope(scopeStarting, handler, handlerScope, handlerInstances); runLifecycleMethods(handler, handlerScope, scopeStarting, false); } }
/** * Scope is ending, perform the required processing on the supplied handlers. */ public void processEndOfScope(Scope scopeEnding, Iterable<Object> handlerInstances) throws Exception { for (Object handler : handlerInstances) { Handler handlerAnnotation = handler.getClass().getAnnotation(Handler.class); Scope scope = handlerAnnotation.scope(); runLifecycleMethods(handler, scope, scopeEnding, true); //dispose handler instances with a scope which matches the scopeEnding if (scope == scopeEnding) { disposeSpringResources(handler, scopeEnding); } } }
public List<Object> getOrCreateHandlersForScenario() throws Exception { List<Object> handlerInstances = new ArrayList<>(); for ( Class handlerClass : orderedHandlerClasses ) { Handler handlerAnnotation = (Handler) handlerClass.getAnnotation(Handler.class); if ( handlerAnnotation.scope() != Scope.SCENARIO ) { Object handler = featureScopedHandlers.get(handlerClass); assert(handler != null); //must have been created during createFeatureScopedHandlers log.debug("Adding feature scoped handler " + handler + " class " + handlerClass); handlerInstances.add(handler); } else { log.debug("Creating scenario scoped handler " + handlerClass); Object handler = createAndInitHandlerInstance(handlerClass); handlerInstances.add(handler); } } return handlerInstances; }
public void createFeatureScopedHandlers() throws Exception { for (Class handlerClass : orderedHandlerClasses) { //create a new SCENARIO scoped handler Handler handlerAnnotation = (Handler) handlerClass.getAnnotation(Handler.class); if (handlerAnnotation.scope() != Scope.SCENARIO) { //feature or unmanaged Object handler = createAndInitHandlerInstance(handlerClass); featureScopedHandlers.put(handlerClass, handler); log.debug("Created new feature scoped handler: " + handlerAnnotation.value()); } } }