class GatewayInstanceInitializer {

    @EventListener(ApplicationReadyEvent.class)
    public void init() {
        if (gatewayClient.isInitialized()) {
            return;
        }

        log.info("GatewayInstanceInitializer starting asynchronous initialization of Gateway configuration");

        instanceLookupExecutor.run(
            CoreService.GATEWAY.getServiceId(),
            instance -> {
                GatewayConfigProperties foundGatewayConfigProperties = process(instance);

                log.info(
                    "GatewayInstanceInitializer has been initialized with Gateway instance on url: {}://{}",
                    foundGatewayConfigProperties.getScheme(),
                    foundGatewayConfigProperties.getHostname()
                );

                gatewayClient.setGatewayConfigProperties(foundGatewayConfigProperties);
                applicationEventPublisher.publishEvent(new GatewayLookupCompleteEvent(this));
            },
            (exception, isStopped) -> {
                if (Boolean.TRUE.equals(isStopped)) {
                    apimlLog.log("org.zowe.apiml.common.gatewayInstanceInitializerStopped", exception.getMessage());
                }
            }
        );
    }

}