Run any lifecycle methods which match the targetMethodScope (.e.g at end of SCENARIO, run SCENARIO scoped methods)
160219
private void runLifecycleMethods(Object handler, Scope scope, Scope targetMethodScope, boolean isDestroy) throws Exception {
        String description = isDestroy ? "@Destroy" : "@Initialize";
        log.debug("Running " + description + " methods for Handler " + handler);

        Class<?> handlerClass = handler.getClass();
        for (Method method : handlerClass.getMethods()) {   //getMethods() includes inherited methods
            if (method.getParameterTypes().length == 0) {

                Scope methodScope = getMethodScope(isDestroy, method);

                //if this lifecycle method is for the correct cope, then run it
                if (methodScope != null && methodScope == targetMethodScope) {
                    log.trace("Found " + description + " annotation with scope " + targetMethodScope + " on handler method " + method + " and will now invoke it");
                    try {
                        method.invoke(handler);
                    } catch ( Throwable t) {
                        log.warn("Exception when calling " + description + " method [" + method + "] with scope " + targetMethodScope + " on handler " + handlerClass, t);
                    }
                }
            }
        }
    }
896513
private Method findHandlerMethod(Object target, Class<? extends IEvents> eventsClass,
            String eventName, Object[] params) {
        // Use cached method if available. Note: no further type checking is done if the
        // method has been cached. It will be checked by JRE when the method is invoked.
        Method cachedMethod = getCachedMethod(target, eventName);
        if (cachedMethod != null) {
            return cachedMethod;
        }

        // Check the event and params against the eventsClass interface object.
        Method nameMatch = null;
        Method signatureMatch = null;
        for (Method method : eventsClass.getMethods()) {
            // Match method name and event name
            if (method.getName().equals(eventName)) {
                nameMatch = method;

                // Check number of parameters
                Class<?>[] types = method.getParameterTypes();
                if (types.length != params.length)
                    continue;

                // Check parameter types
                int i = 0;
                boolean foundMatchedMethod = true;
                for (Class<?> type : types) {
                    Object param = params[i++];
                    if (!isInstanceWithAutoboxing(type, param)) {
                        foundMatchedMethod = false;
                        break;
                    }
                }

                if (foundMatchedMethod) {
                    signatureMatch = method;
                    break;
                }
            }
        }

        // Error
        if (nameMatch == null) {
            throw new RuntimeException(String.format("The interface contains no method %s", eventName));
        } else if (signatureMatch == null ){
            throw new RuntimeException(String.format("The interface contains a method %s but "
                    + "parameters don't match", eventName));
        }

        // Cache the method for the target, even if it doesn't implement the interface. This is
        // to avoid always verifying the event.
        addCachedMethod(target, eventName, signatureMatch);

        return signatureMatch;
    }
174777
public static Object invokeMethod(Object target, String method, Object... args) {
		Class<?>[] types = new Class[args.length];
		for(int index = args.length - 1; index >= 0; index--) {
			types[index] = args[index].getClass();
		}
		try {
			return target.getClass().getMethod(method, types).invoke(target, args);
		} catch(Throwable t) {
			throw new MethodInvocationException(t);
		}
	}
1101223
static void runChildWithRetry(Object runner, final FrameworkMethod method, RunNotifier notifier, int maxRetry) {
        boolean doRetry = false;
        Statement statement = invoke(runner, "methodBlock", method);
        Description description = invoke(runner, "describeChild", method);
        AtomicInteger count = new AtomicInteger(maxRetry);
        
        do {
            EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
            
            eachNotifier.fireTestStarted();
            try {
                statement.evaluate();
                doRetry = false;
            } catch (AssumptionViolatedException thrown) {
                doRetry = doRetry(method, thrown, count);
                if (doRetry) {
                    description = RetriedTest.proxyFor(description, thrown);
                    eachNotifier.fireTestIgnored();
                } else {
                    eachNotifier.addFailedAssumption(thrown);
                }
            } catch (Throwable thrown) {
                doRetry = doRetry(method, thrown, count);
                if (doRetry) {
                    description = RetriedTest.proxyFor(description, thrown);
                    eachNotifier.fireTestIgnored();
                } else {
                    eachNotifier.addFailure(thrown);
                }
            } finally {
                eachNotifier.fireTestFinished();
            }
        } while (doRetry);
    }
645004
def run(self):
        """"""
        self.api = self.context.get("cls")(self.context)
        self.context["inst"].append(self)  # Adapters used by strategies

        for call, calldata in self.context.get("calls", {}).items():
            def loop():
                """Loop on event scheduler, calling calls"""
                while not self.stopped.wait(calldata.get("delay", None)):
                    self.call(call, calldata.get("arguments", None))

            self.thread[call] = Process(target=loop)
            self.thread[call].start()
85973
public static MethodHandle findMethodHandle(Object target,String methodName,Object ...args)
	{
		Class<?>[] ptypes = new Class<?>[args.length];
		for(int i=0;i<args.length;i++)
		{
			ptypes[i]=args[i].getClass();
		}
		return findMethodHandle(target, methodName, ptypes);
	}
723723
public void execute(T target) throws Throwable
    {
        try
        {
            for (Invokation invokation : queue)
            {
                invokation.invoke(target);
            }
        }
        catch (InvocationTargetException ex)
        {
            throw ex.getCause();
        }
        catch (ReflectiveOperationException ex)
        {
            throw new RuntimeException(ex);
        }
    }
995197
public void postInvokeForLifecycleInterceptors(LifecycleInterceptorWrapper wrapper,
                                                   int methodId,
                                                   EJSDeployedSupport s) throws RemoteException {
        // NOTE: The implementation of this method is structured after postInvoke.
        // For a detailed explanation of the operations here, see the comments in
        // that method.

        EJBMethodInfoImpl methodInfo = s.methodInfo;

        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn) {
            if (TEEJBInvocationInfo.isTraceEnabled())
                TEEJBInvocationInfo.tracePostInvokeBegins(s, wrapper);

            if (tcClntInfo.isDebugEnabled())
                Tr.debug(tcClntInfo, "postInvoke(" + methodInfo.getMethodName() + ")");

            if (tc.isEntryEnabled())
                Tr.entry(tc, "postInvokeForLifecycleInterceptors(" + methodId +
                             ":" + methodInfo.getMethodName() + ")");
        }

        // UOWManager.runUnderUOW may have left cached currentTx invalid; reset
        if (s.resetCurrentTx) {
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(tc, "s.currentTx may be invalid; reset");
            s.currentTx = getCurrentContainerTx();
        }

        s.currentTx.postInvoke(s);

        try {
            boolean isRollbackOnly = uowCtrl.getRollbackOnly(); //d636725
            try {
                if (s.began && s.currentTx.ivPostInvokeContext == null) {
                    s.currentTx.ivPostInvokeContext = s;
                }

                uowCtrl.postInvoke(wrapper.beanId, s.uowCookie, s.exType, methodInfo);
            } catch (CSITransactionRolledbackException ex) {
                // Per preInvokeForLifecycleInterceptors, all exceptions thrown from
                // lifecycle interceptors must not be application exceptions.  This
                // ensures postInvokeRolledbackException will propagate this exception
                // (unless setRollbackOnly was called).  The exception is mapped to
                // prevent application code from seeing internal CSIExceptions.
                postInvokeRolledbackException(s, ex);
            }

            //d636725 start
            // If setRollbackOnly was called in a PostConstruct method of a
            // singleton bean, then we need to throw an
            // EJBTransactionRolledBackException here which will be wrapped
            // in a NoSuchEJBException.
            // Our interpretation of the spec requires that we throw this
            // exception here (as opposed to within the setRollbackOnly
            // method - which is an allowed operation) so that the the
            // NoSuchEJBException will be thrown to the client during
            // postInvoke. This behavior is specific to Singleton beans
            // as Stateful and Stateless beans are not allowed to call
            // setRollbackOnly inside PostConstruct methods - they would
            // receive an IllegalStateException.
            if (methodId == LifecycleInterceptorWrapper.MID_POST_CONSTRUCT &&
                isRollbackOnly) {

                String msg = "setRollbackOnly called from within a singleton post construct method.";
                if (isTraceOn && tc.isDebugEnabled())
                    Tr.debug(tc, msg);
                throw new EJBTransactionRolledbackException(msg);
            }
            //d636725 end
        } finally {
            if (!s.began || s.currentTx.ivPostInvokeContext != null) {
                postInvokePopCallbackContexts(s);
            }

            if (s.ivSecurityCollaborator != null) {
                notifyPostInvoke(s.ivSecurityCollaborator, s, s.securityCookie);
            }

            if (s.currentTx != null && s.began) {
                s.currentTx.releaseResources();
                s.currentTx = null;
            }

            EJBThreadData.svThreadContextAccessor.popContextClassLoaderForUnprivileged(s.oldClassLoader);

            s.ivThreadData.popMethodContext(); // d646139.1, RTC102449

            if (isTraceOn) {
                if (tc.isEntryEnabled())
                    Tr.exit(tc, "postInvokeForLifecycleInterceptors(" + methodId + ":" +
                                methodInfo.getMethodName() + ")" +
                                ((s.ivException != null) ? ("**** throws " + s.ivException) : ""));
            }
        }
    }
50130
def run(self):
    

    if self.__target is not None:
      return self.__target(self, *self.__args, **self.__kwargs)
    raise NotImplementedError
321160
public static Object invokeMethod(Object target, String method, Object... args) {
    try {
      return InvokerHelper.invokeMethod(target, method, args);
    } catch (InvokerInvocationException e) {
      ExceptionUtil.sneakyThrow(e.getCause());
      return null; // never reached
    }
  }
1002236
public void execute() {
    try {
      for (CommitStep step : this.steps) {
        if (!step.isCompleted()) {
          step.execute();
        }
      }
    } catch (Throwable t) {
      log.error("Commit failed for dataset " + this.datasetUrn, t);
      throw Throwables.propagate(t);
    }
  }
1250308
public <T> T executeInApplicationContext(Callable<T> callable) throws Exception {
        ApplicationContext context = (ApplicationContext) getScopedContext(ApplicationScoped.class);
        boolean activatedByUs = false;
        try {
            if (!context.isActive()) {
                context.activate();
                activatedByUs = true;
            }
            return callable.call();
        } finally {
            if (activatedByUs && context.isActive()) {
                context.deactivate();
            }
        }
    }
244685
def run(self):
        
        if self._py3_wrapper.running:
            cache_time = None
            # execute each method of this module
            for meth, obj in self.methods.items():
                my_method = self.methods[meth]

                # always check py3status is running
                if not self._py3_wrapper.running:
                    break

                # respect the cache set for this method
                if time() < obj["cached_until"]:
                    if not cache_time or obj["cached_until"] < cache_time:
                        cache_time = obj["cached_until"]
                    continue

                try:
                    # execute method and get its output
                    method = getattr(self.module_class, meth)
                    if my_method["call_type"] == self.PARAMS_NEW:
                        # new style modules
                        response = method()
                    else:
                        # legacy modules had parameters passed
                        response = method(
                            self.i3status_thread.json_list,
                            self.config["py3_config"]["general"],
                        )

                    if isinstance(response, dict):
                        # this is a shiny new module giving a dict response
                        result = response
                    elif isinstance(response, tuple):
                        # this is an old school module reporting its position
                        position, result = response
                        if not isinstance(result, dict):
                            raise TypeError("response should be a dict")
                    else:
                        raise TypeError("response should be a dict")

                    if isinstance(response.get("full_text"), (list, Composite)):
                        response["composite"] = response["full_text"]
                        del response["full_text"]
                    if "composite" in response:
                        self.process_composite(response)
                    else:
                        # validate the response
                        if "full_text" not in result:
                            err = 'missing "full_text" key in response'
                            raise KeyError(err)
                        # Remove any none color from our output
                        if hasattr(result.get("color"), "none_setting"):
                            del result["color"]
                        # remove urgent if not allowed
                        if not self.allow_urgent and "urgent" in result:
                            del result["urgent"]
                        # set universal module options in result
                        result.update(self.i3bar_module_options)

                    result["instance"] = self.module_inst
                    result["name"] = self.module_name

                    # initialize method object
                    if my_method["name"] is None:
                        my_method["name"] = result["name"]
                        if "instance" in result:
                            my_method["instance"] = result["instance"]
                        else:
                            my_method["instance"] = result["name"]

                    # update method object cache
                    if "cached_until" in result:
                        cached_until = result["cached_until"]
                        # remove this so we can check later for output changes
                        del result["cached_until"]
                    else:
                        # get module default cached_until
                        cached_until = self.module_class.py3.time_in()
                    my_method["cached_until"] = cached_until
                    if not cache_time or cached_until < cache_time:
                        cache_time = cached_until

                    # update method object output
                    if "composite" in response:
                        my_method["last_output"] = result["composite"]
                    else:
                        my_method["last_output"] = result

                    # debug info
                    if self.config["debug"]:
                        self._py3_wrapper.log(
                            "method {} returned {} ".format(meth, result)
                        )
                    # module working correctly so ensure module works as
                    # expected
                    self.allow_config_clicks = True
                    self.error_messages = None
                    self.error_hide = False

                    # mark module as updated
                    self.set_updated()

                except ModuleErrorException as e:
                    # module has indicated that it has an error
                    self.runtime_error(e.msg, meth)
                    if e.timeout:
                        if e.timeout is PY3_CACHE_FOREVER:
                            cache_time = PY3_CACHE_FOREVER
                        else:
                            cache_time = time() + e.timeout
                    else:
                        cache_time = time() + getattr(
                            self.module_class,
                            "cache_timeout",
                            self.config["cache_timeout"],
                        )

                except Exception as e:
                    msg = "Instance `{}`, user method `{}` failed"
                    msg = msg.format(self.module_full_name, meth)
                    if not self.testing:
                        self._py3_wrapper.report_exception(msg, notify_user=False)
                    # added error
                    self.runtime_error(str(e) or e.__class__.__name__, meth)
                    cache_time = time() + getattr(
                        self.module_class, "cache_timeout", self.config["cache_timeout"]
                    )

            if cache_time is None:
                cache_time = time() + self.config["cache_timeout"]
            self.cache_time = cache_time
            # new style modules can signal they want to cache forever
            if cache_time == PY3_CACHE_FOREVER:
                return
            # don't be hasty mate
            # set timeout to do update next time one is needed
            if not cache_time:
                cache_time = time() + self.config["minimum_interval"]

            self._py3_wrapper.timeout_queue_add(self, cache_time)
1259890
function runWithDetach (args, methodMeta) {
    // skip if no withDetach methods
    if (!defined(methodMeta.withDetach)) {
        return
    }
    // run all functions
    _.each(methodMeta.withDetach, method => {
        // call method
        (method)(args, methodMeta.signature, 'withDetach')
        // log errors
        .catch(err => {
            // require log client
            if (!defined(methodMeta.logClient)) {
                return
            }
            // log error
            methodMeta.logClient.error(err, args.session)
        })
    })
}
660729
public void finished() throws Throwable {
        if( state == FINISHED ) {
            return;
        }

        State previousState = state;

        state = FINISHED;
        methodInterceptor.enableMethodInterception( false );

        try {
            if( previousState == STARTED ) {
                callFinishLifeCycleMethods();
            }
        } finally {
            listener.scenarioFinished();
        }
    }
297992
private Scope getMethodScope(boolean isDestroy, Method method) {
        Scope methodScope;
        if ( isDestroy ) {
            Destroy annotation = method.getAnnotation(Destroy.class);
            methodScope = annotation != null ? annotation.scope() : null;
        } else {
            Initialize annotation = method.getAnnotation(Initialize.class);
            methodScope = annotation != null ? annotation.scope() : null;
        }
        return methodScope;
    }
869684
private void processWatchers(MethodSpec.Builder createdMethodBuilder) {
    createdMethodBuilder.addStatement("Proto p = __proto__");
    getMethodsWithAnnotation(component, Watch.class)
        .forEach(method -> processWatcher(createdMethodBuilder, method));
  }