Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 6bbc0b4

Browse files
committed
document onStart/onStop lifecycle methods fix jooby-project#359
1 parent d7a440f commit 6bbc0b4

File tree

42 files changed

+503
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+503
-298
lines changed

coverage-report/src/test/java/org/jooby/PostConstructFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void start() throws Exception {
2727

2828
{
2929

30-
managed(SingletonObject.class);
30+
lifeCycle(SingletonObject.class);
3131

3232
get("/singleton", req -> {
3333
return SingletonObject.started;

coverage-report/src/test/java/org/jooby/StartManagedObjectFeature.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

jooby-assets/src/main/java/org/jooby/assets/Assets.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ public void configure(final Env env, final Config config, final Binder binder) {
253253
}
254254
if (watch) {
255255
LiveCompiler liveCompiler = new LiveCompiler(conf, compiler);
256-
env.managed(liveCompiler);
256+
env.onStart(liveCompiler::start);
257+
env.onStop(liveCompiler::stop);
257258
routes.addBinding()
258259
.toInstance(new Route.Definition("*", "*", liveCompiler).name("/assets/compiler"));
259260
}

jooby-assets/src/main/java/org/jooby/internal/assets/LiveCompiler.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.concurrent.atomic.AtomicReference;
2929
import java.util.stream.Collectors;
3030

31-
import org.jooby.Managed;
3231
import org.jooby.MediaType;
3332
import org.jooby.Request;
3433
import org.jooby.Response;
@@ -43,7 +42,7 @@
4342

4443
import com.typesafe.config.Config;
4544

46-
public class LiveCompiler implements Route.Handler, Managed {
45+
public class LiveCompiler implements Route.Handler {
4746

4847
/** The logging system. */
4948
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -170,12 +169,10 @@ private void reportErr(final Request req, final Response rsp, final AssetExcepti
170169

171170
}
172171

173-
@Override
174-
public void start() throws Exception {
172+
public void start() {
175173
watcher.start();
176174
}
177175

178-
@Override
179176
public void stop() throws Exception {
180177
watcher.stop();
181178
}

jooby-assets/src/test/java/org/jooby/assets/AssetsTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jooby.assets;
22

33
import static org.easymock.EasyMock.expect;
4+
import static org.easymock.EasyMock.isA;
45
import static org.junit.Assert.assertTrue;
56

67
import org.jooby.Env;
@@ -27,6 +28,8 @@
2728
import com.typesafe.config.ConfigFactory;
2829
import com.typesafe.config.ConfigValueFactory;
2930

31+
import javaslang.control.Try.CheckedRunnable;
32+
3033
@RunWith(PowerMockRunner.class)
3134
@PrepareForTest({Assets.class, AssetCompiler.class, Multibinder.class, LiveCompiler.class })
3235
public class AssetsTest {
@@ -129,12 +132,13 @@ public void configureWithWatch() throws Exception {
129132
}).expect(unit -> {
130133
AssetCompiler compiler = unit.get(AssetCompiler.class);
131134

132-
LiveCompiler liveCompiler = unit.constructor(LiveCompiler.class)
135+
unit.constructor(LiveCompiler.class)
133136
.args(Config.class, AssetCompiler.class)
134137
.build(conf, compiler);
135138

136139
Env env = unit.get(Env.class);
137-
expect(env.managed(liveCompiler)).andReturn(env);
140+
expect(env.onStart(isA(CheckedRunnable.class))).andReturn(env);
141+
expect(env.onStop(isA(CheckedRunnable.class))).andReturn(env);
138142

139143
LinkedBindingBuilder<Definition> lbblc = unit.mock(LinkedBindingBuilder.class);
140144
lbblc.toInstance(unit.capture(Route.Definition.class));

jooby-camel/src/main/java/org/jooby/camel/Camel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public void configure(final Env env, final Config config, final Binder binder) {
375375
properties.setSuffixToken("}");
376376
ctx.addComponent("properties", properties);
377377

378-
env.managed(CamelFinalizer.class);
378+
env.lifeCycle(CamelFinalizer.class);
379379

380380
/**
381381
* Guice!

jooby-camel/src/test/java/org/jooby/camel/CamelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class CamelTest {
6666

6767
private MockUnit.Block onStop = unit -> {
6868
Env env = unit.get(Env.class);
69-
expect(env.managed(CamelFinalizer.class)).andReturn(env);
69+
expect(env.lifeCycle(CamelFinalizer.class)).andReturn(env);
7070
};
7171

7272
@Test(expected = IllegalArgumentException.class)

jooby-ebean/src/main/java/org/jooby/ebean/Ebeanby.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ public void configure(final Env env, final Config conf, final Binder binder) {
243243
}
244244

245245
EbeanManaged server = new EbeanManaged(conf, config);
246-
env.managed(server);
246+
env.onStart(server::start);
247+
env.onStop(server::stop);
247248
keys(EbeanServer.class, key -> binder.bind(key).toProvider(server).asEagerSingleton());
248249
}
249250

jooby-ebean/src/main/java/org/jooby/internal/ebean/EbeanManaged.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@
2222

2323
import javax.inject.Provider;
2424

25-
import org.jooby.Managed;
26-
2725
import com.avaje.ebean.EbeanServer;
2826
import com.avaje.ebean.EbeanServerFactory;
2927
import com.avaje.ebean.config.ServerConfig;
3028
import com.google.common.base.Supplier;
3129
import com.google.common.base.Suppliers;
3230
import com.typesafe.config.Config;
3331

34-
public class EbeanManaged implements Provider<EbeanServer>, Managed {
32+
public class EbeanManaged implements Provider<EbeanServer> {
3533

3634
private Supplier<EbeanServer> ebean;
3735

@@ -52,12 +50,10 @@ private void move(final String fname, final String tmpdir) {
5250
new File(fname).renameTo(new File(tmpdir, fname));
5351
}
5452

55-
@Override
5653
public void start() throws Exception {
5754
ebean.get();
5855
}
5956

60-
@Override
6157
public void stop() throws Exception {
6258
if (ebean != null) {
6359
ebean.get().shutdown(false, false);

jooby-ebean/src/test/java/org/jooby/ebean/EbeanbyTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import javax.sql.DataSource;
1010

1111
import org.jooby.Env;
12-
import org.jooby.Managed;
1312
import org.jooby.internal.ebean.EbeanEnhancer;
1413
import org.jooby.internal.ebean.EbeanManaged;
1514
import org.jooby.internal.ebean.ForwardingDataSource;
@@ -32,6 +31,8 @@
3231
import com.typesafe.config.Config;
3332
import com.typesafe.config.ConfigValueFactory;
3433

34+
import javaslang.control.Try.CheckedRunnable;
35+
3536
@RunWith(PowerMockRunner.class)
3637
@PrepareForTest({Ebeanby.class, ServerConfig.class, EbeanEnhancer.class })
3738
public class EbeanbyTest {
@@ -76,8 +77,9 @@ public class EbeanbyTest {
7677
private Block onStop = unit -> {
7778
Env env = unit.get(Env.class);
7879

79-
expect(env.managed(isA(EbeanManaged.class))).andReturn(env);
80-
expect(env.managed(isA(Managed.class))).andReturn(env);
80+
expect(env.onStart(isA(CheckedRunnable.class))).andReturn(env);
81+
expect(env.onStop(isA(CheckedRunnable.class))).andReturn(env);
82+
expect(env.onStop(isA(CheckedRunnable.class))).andReturn(env);
8183
};
8284

8385
@Test

0 commit comments

Comments
 (0)