/** * Add a stop lifecycle event, useful for cleanup and/or stop service at stop time. * * You should ONLY call this method while the application is been initialized or from * {@link Jooby.Module#configure(Env, Config, com.google.inject.Binder)}. * * The behavior of this method once application has been initialized is <code>undefined</code>. * * @param task Task to run. * @return This env. */ @Nonnull default LifeCycle onStop(final Throwing.Runnable task) { return onStop(app -> task.run()); }
/** * Add a start lifecycle event, useful for initialize and/or start services at startup time. * * You should ONLY call this method while the application is been initialized or from * {@link Jooby.Module#configure(Env, Config, com.google.inject.Binder)}. * * The behavior of this method once application has been initialized is <code>undefined</code>. * * @param task Task to run. * @return This env. */ @Nonnull default LifeCycle onStart(final Throwing.Runnable task) { return onStart(app -> task.run()); }
/** * Add a started lifecycle event. Started callbacks are executed when the application is ready: * modules and servers has been started. * * You should ONLY call this method while the application is been initialized or while * {@link Jooby.Module#configure(Env, Config, com.google.inject.Binder)}. * * The behavior of this method once application has been initialized is <code>undefined</code>. * * @param task Task to run. * @return This env. */ @Nonnull default LifeCycle onStarted(final Throwing.Runnable task) { return onStarted(app -> task.run()); }
/** * Creates a side effect try from given runnable. Don't forget to either throw or log the exception * in case of failure. Unless, of course you don't care about the exception. * * Log the exception: * <pre>{@code * Try.run(() -> ...) * .onFailure(x -> x.printStacktrace()); * }</pre> * * Throw the exception: * <pre>{@code * Try.run(() -> ...) * .throwException(); * }</pre> * * @param runnable Runnable. * @return A void try. */ public static Try run(Throwing.Runnable runnable) { try { runnable.run(); return new Success<>(null); } catch (Throwable x) { return new Failure(x); } }
/** * Add a started lifecycle event. Started callbacks are executed when the application is ready: * modules and servers has been started. * * You should ONLY call this method while the application is been initialized or while * {@link Jooby.Module#configure(Env, Config, com.google.inject.Binder)}. * * The behavior of this method once application has been initialized is <code>undefined</code>. * * @param task Task to run. * @return This env. */ @Nonnull default LifeCycle onStarted(final Throwing.Runnable task) { return onStarted(app -> task.run()); }
/** * Add a stop lifecycle event, useful for cleanup and/or stop service at stop time. * * You should ONLY call this method while the application is been initialized or from * {@link Jooby.Module#configure(Env, Config, com.google.inject.Binder)}. * * The behavior of this method once application has been initialized is <code>undefined</code>. * * @param task Task to run. * @return This env. */ @Nonnull default LifeCycle onStop(final Throwing.Runnable task) { return onStop(app -> task.run()); }
/** * Add a start lifecycle event, useful for initialize and/or start services at startup time. * * You should ONLY call this method while the application is been initialized or from * {@link Jooby.Module#configure(Env, Config, com.google.inject.Binder)}. * * The behavior of this method once application has been initialized is <code>undefined</code>. * * @param task Task to run. * @return This env. */ @Nonnull default LifeCycle onStart(final Throwing.Runnable task) { return onStart(app -> task.run()); }
/** * Always run the given action, works like a finally clause. * * @param action Finally action. * @return This try result. */ public Try onComplete(Throwing.Runnable action) { try { action.run(); return this; } catch (Throwable x) { return Try.failure(x); } }
private Throwing.Runnable sync(final Throwing.Runnable task) { return () -> { synchronized (this) { task.run(); } }; }
private Throwing.Runnable sync(final Throwing.Runnable task) { return () -> { synchronized (this) { task.run(); } }; }