use of org.hypertrace.entity.type.service.v2.EntityTypeServiceImpl in project entity-service by hypertrace.
the class EntityService method doInit.
@Override
protected void doInit() {
serviceName = getAppConfig().getString(SERVICE_NAME_CONFIG);
int port = getAppConfig().getInt(SERVICE_PORT_CONFIG);
Config config = getAppConfig().getConfig(ENTITY_SERVICE_CONFIG);
EntityServiceConfig entityServiceConfig = new EntityServiceConfig(config);
Config dataStoreConfig = entityServiceConfig.getDataStoreConfig(entityServiceConfig.getDataStoreType());
this.datastore = DatastoreProvider.getDatastore(entityServiceConfig.getDataStoreType(), dataStoreConfig);
GrpcChannelRegistry channelRegistry = new GrpcChannelRegistry();
this.getLifecycle().shutdownComplete().thenRun(channelRegistry::shutdown);
Channel localChannel = channelRegistry.forAddress("localhost", port);
EntityChangeEventGenerator entityChangeEventGenerator = EntityChangeEventGeneratorFactory.getInstance().createEntityChangeEventGenerator(getAppConfig(), Clock.systemUTC());
server = ServerBuilder.forPort(port).addService(InterceptorUtil.wrapInterceptors(new org.hypertrace.entity.type.service.EntityTypeServiceImpl(datastore))).addService(InterceptorUtil.wrapInterceptors(new EntityTypeServiceImpl(datastore))).addService(InterceptorUtil.wrapInterceptors(new EntityDataServiceImpl(datastore, localChannel, entityChangeEventGenerator))).addService(InterceptorUtil.wrapInterceptors(new EntityQueryServiceImpl(datastore, getAppConfig(), channelRegistry))).build();
scheduledExecutorService.scheduleAtFixedRate(() -> {
if (!datastore.healthCheck()) {
consecutiveFailedHealthCheck++;
if (consecutiveFailedHealthCheck > 5) {
LOG.warn("Failed 5 times to connect to data store, shut down EntityService...");
System.exit(2);
}
} else {
consecutiveFailedHealthCheck = 0;
}
}, 60, 60, TimeUnit.SECONDS);
}
Aggregations