I'am starting using play framework i want to write a job that makes a certain number of ws calls.
I wrote 2 classes as following:
@Singleton
public class AutoGateJob {
@Inject
private ActorSystem actorSystem;
@Inject
private ExecutionContext executionContext;
@Inject
private RgsDataServiceServices rgsDataServiceServices;
@Inject
public AutoGateJob(ApplicationLifecycle lifecycle, ActorSystem system, ExecutionContext
context) {
Logger.info("### create autojob");
this.actorSystem = system;
this.executionContext = context;
this.initialize();
lifecycle.addStopHook(() -> {
Logger.info("### c'est l'heure de rentrer!!!");
this.actorSystem.shutdown();
return CompletableFuture.completedFuture(null);
});
}
private void initialize() {
this.actorSystem.scheduler().schedule(
Duration.create(0, TimeUnit.SECONDS), // initialDelay
Duration.create(5, TimeUnit.SECONDS), // interval
() -> this.runAutoGateJobTasks(),
this.executionContext
);
}
private void runAutoGateJobTasks() {
Logger.info("## Run job every 5 seconds");
rgsDataServiceServices = new RgsDataServiceServices();
rgsDataServiceServices.findAllPaymentToSendHandler()
.handle((wsResponse, throwable) -> {
Logger.info("## find all payment to send response: ", wsResponse.asJson());
List<String> paymentsList = new ArrayList<>();
paymentsList.forEach(s -> {
Logger.info("## Processing payment: ", s);
});
return CompletableFuture.completedFuture(null);
});
}
}
and
public class AutoGateJobInitializer extends AbstractModule {
@Override
protected void configure() {
Logger.info("## Setup job on app startup!");
bind(AutoGateJob.class).asEagerSingleton();
}
}
the problem is: Mys rgsDataServiceServices has a working WSClient injection that works well when used with controllers but when called in the AutoGateJob i have null pointer exception ( [error] a.d.TaskInvocation - null java.lang.NullPointerException: null ) I don't really understand what's going on but i need my job to behave this way.
Thank you for helping!