I'm working on a project written in Java, which has a dependency initialization system written in-house. I've been looking for a robust third party library which could manage this, so we don't have to do maintenance on it as much. So far my search has not been very helpful. Most results have come back suggesting Spring, but I don't think that is satisfies our needs.
Things we need out of the library:
init()
, but allow the service to call back. This is because most of the services are making calls to our web service as part of their initialization.I've looked at Spring and Guice already, and from what I can tell, they won't work, because they don't allow your dependencies to be in an intermediate initialization state, and will block the thread if you ask for an uninitialized object, until it is fully constructed. I'm also not sure if they permit uninitialization.
I'm fully aware that this may be very specific, and possibly a strange system (it is quite old), so I expect that there may not be an alternative to an in-house solution.
Initializer for service initialization logic. This can be very useful for distributed services, to meet several requirements:
During initialization, application service can check health of the components and reflect it accordingly.
As it is intended mainly for connecting to services, retry mechanism and failure handling, health check for dependencies services is intended to be managed separately.
Example usage:
Initializer initializer = Initializer.builder().circuitBreaker(circuitBreaker)
.mandatoryTask("initDB", () -> {return initDB();})
.mandatoryTask("initMessagingService", () -> {return initMessagingService();})
.nonMandatoryTask("initStats", () -> {return initStats();})
.postInitTask("serveRequests", () -> {return serveRequests();})
.build();
initializer.initAsync();
Note: I am the author of this Initializer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.