@Override public <T, C> Action<T, C> create(Action<T, C> action) { return (exchange, context) -> { UndertowThreadSetupAction.this.action.setup(Collections.emptyMap()); try { return action.call(exchange, context); } finally { UndertowThreadSetupAction.this.action.teardown(Collections.emptyMap()); } }; } }
@Override public void reset() { if(resetActions != null) { for (SetupAction resetAction : this.resetActions) { try { resetAction.teardown(Collections.<String, Object>emptyMap()); } catch (Throwable e) { EeLogger.ROOT_LOGGER.debug("failed to teardown action",e); } } resetActions = null; } }
@Override public ResetContextHandle setup() throws IllegalStateException { final LinkedList<SetupAction> resetActions = new LinkedList<>(); final OtherEESetupActionsResetContextHandle resetContextHandle = new OtherEESetupActionsResetContextHandle(resetActions); try { for (SetupAction setupAction : this.setupActions) { setupAction.setup(Collections.<String, Object>emptyMap()); resetActions.addFirst(setupAction); } } catch (Error | RuntimeException e) { resetContextHandle.reset(); throw e; } return resetContextHandle; }
Set<ServiceName> dependencies = setupAction.dependencies(); if (dependencies != null) { additionalDependencies.addAll(dependencies);
@Override public void reset() { if(resetActions != null) { for (SetupAction resetAction : this.resetActions) { try { resetAction.teardown(Collections.<String, Object>emptyMap()); } catch (Throwable e) { EeLogger.ROOT_LOGGER.debug("failed to teardown action",e); } } resetActions = null; } }
@Override public ResetContextHandle setup() throws IllegalStateException { final LinkedList<SetupAction> resetActions = new LinkedList<>(); final OtherEESetupActionsResetContextHandle resetContextHandle = new OtherEESetupActionsResetContextHandle(resetActions); try { for (SetupAction setupAction : this.setupActions) { setupAction.setup(Collections.<String, Object>emptyMap()); resetActions.addFirst(setupAction); } } catch (Error | RuntimeException e) { resetContextHandle.reset(); throw e; } return resetContextHandle; }
for (ServiceName dependency : action.dependencies()) { startStopServiceBuilder.requires(dependency); createDestroyServiceBuilder.requires(dependency);
@Override public Object processInvocation(final InterceptorContext context) throws Exception { try { for (int i = 0; i < actions.length; ++i) { actions[i].setup(Collections.<String, Object>emptyMap()); } return context.proceed(); } finally { Throwable error = null; for (int i = actions.length - 1; i >=0; --i) { SetupAction action = actions[i]; try { action.teardown(Collections.<String, Object>emptyMap()); } catch (Throwable e) { error = e; } } if (error != null) { throw new RuntimeException(error); } } }
@Override public void reset() { if(resetActions != null) { for (SetupAction resetAction : this.resetActions) { try { resetAction.teardown(Collections.<String, Object>emptyMap()); } catch (Throwable e) { EeLogger.ROOT_LOGGER.debug("failed to teardown action",e); } } resetActions = null; } }
@Override public ResetContextHandle setup() throws IllegalStateException { final LinkedList<SetupAction> resetActions = new LinkedList<>(); final OtherEESetupActionsResetContextHandle resetContextHandle = new OtherEESetupActionsResetContextHandle(resetActions); try { for (SetupAction setupAction : this.setupActions) { setupAction.setup(Collections.<String, Object>emptyMap()); resetActions.addFirst(setupAction); } } catch (Error | RuntimeException e) { resetContextHandle.reset(); throw e; } return resetContextHandle; }
Set<ServiceName> dependencies = setupAction.dependencies(); if (dependencies != null) { additionalDependencies.addAll(dependencies);
protected void invokeLifecycleMethod(final Method method, final LifecycleContext context) throws InvocationTargetException, IllegalAccessException { if (method != null) { try { for (SetupAction action : setupActions) { action.setup(Collections.<String, Object>emptyMap()); } final ClassLoader old = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(this.mbeanContextClassLoader); try { method.invoke(mBeanInstance); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(old); } } finally { ListIterator<SetupAction> it = setupActions.listIterator(setupActions.size()); while (it.hasPrevious()) { SetupAction action = it.previous(); action.teardown(Collections.<String, Object>emptyMap()); } } } } }
/** * Tears down the contexts. If an exception is thrown by a {@link SetupAction} it is wrapped and re-thrown after all * {@link SetupAction#teardown(java.util.Map)} methods have been called. * <p> * Contexts are torn down in the opposite order to which they are set up (i.e. the first context set up is the last to be * torn down). * <p> * If more than one teardown() method thrown an exception then only the first is propagated. */ void teardown(final Map<String, Object> properties) { Throwable exceptionToThrow = null; final ListIterator<SetupAction> itr = setupActions.listIterator(setupActions.size()); while (itr.hasPrevious()) { final SetupAction action = itr.previous(); try { action.teardown(properties); } catch (Throwable e) { if (exceptionToThrow == null) { exceptionToThrow = e; } } } if (exceptionToThrow != null) { throw new RuntimeException(exceptionToThrow); } }
Set<ServiceName> dependencies = setupAction.dependencies(); if (dependencies != null) { additionalDependencies.addAll(dependencies);
public synchronized void stop(final StopContext context) { if (objectName == null) { ROOT_LOGGER.cannotUnregisterObject(); } final MBeanServer mBeanServer = getMBeanServer(); try { for (SetupAction action : setupActions) { action.setup(Collections.<String, Object>emptyMap()); } try { mBeanServer.unregisterMBean(objectName); } catch (Exception e) { ROOT_LOGGER.unregistrationFailure(e, objectName); } } finally { ListIterator<SetupAction> it = setupActions.listIterator(setupActions.size()); while (it.hasPrevious()) { SetupAction action = it.previous(); action.teardown(Collections.<String, Object>emptyMap()); } } }
/** * Tears down the contexts. If an exception is thrown by a {@link SetupAction} it is wrapped and re-thrown after all * {@link SetupAction#teardown()} methods have been called. * <p> * Contexts are torn down in the oposite order to which they are set up (i.e. the first context set up is the last to be * torn down). * <p> * If more than one teardown() method thrown an exception then only the first is propegated. */ public void teardown(Map<String, Object> properties) { Throwable exceptionToThrow = null; ListIterator<SetupAction> itr = setupActions.listIterator(setupActions.size()); while (itr.hasPrevious()) { SetupAction action = itr.previous(); try { action.teardown(properties); } catch (Throwable e) { if (exceptionToThrow == null) { exceptionToThrow = e; } } } if (exceptionToThrow != null) { throw new RuntimeException(exceptionToThrow); } } }