If we are talking about services we also have to talk about priority startup and shutdown. You want your services being started and stopped in an orderly manner.
You can use Ninja's @Start
and @Dispose
annotations to do so.
The class and method then looks like:
@Singleton public class MyService { @Start(order = 90) public void startService() { //do something } @Dispose(order = 90) public void stopService() { //do something } public Result getCount(Context ctx) { return Results.json(count.get()); } }
Don't forget to bind the class explicitly inside conf/Module.java
public class Module extends AbstractModule { protected void configure() { bind(MyService.class); } }
By that Ninja will start MyService and also stop it nicely.
The order in which it should be started, higher meaning later. While apps are free to use any ordering system they wish, the following convention is recommended: