- @PostConstruct
- protected void start() {
- if (!config.getASDCConnectionDisabled()) {
- initSdcClient();
- }
- }
-
- /**
- * Responsible for stopping the connection to the distribution client before the resource is destroyed.
- */
- public void preShutdownOperations() {
- logger.info(ModelLoaderMsgs.STOPPING_CLIENT);
- if (client != null) {
- client.stop();
- }
- }
-
- /**
- * Responsible for loading configuration files, initializing model distribution clients, and starting them.
- */
- protected void initSdcClient() {
- // Initialize distribution client
- logger.debug(ModelLoaderMsgs.INITIALIZING, "Initializing distribution client...");
- IDistributionClientResult initResult = client.init(config, eventCallback);
-
- if (initResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) {
- // Start distribution client
- logger.debug(ModelLoaderMsgs.INITIALIZING, "Starting distribution client...");
- IDistributionClientResult startResult = client.start();
- if (startResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) {
- logger.info(ModelLoaderMsgs.INITIALIZING, "Connection to SDC established");
- } else {
- String errorMsg = "Failed to start distribution client: " + startResult.getDistributionMessageResult();
- logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg);
-
- // Kick off a timer to retry the SDC connection
- Timer timer = new Timer();
- TimerTask task = new SdcConnectionJob(client, config, eventCallback, timer);
- timer.schedule(task, new Date(), 60000);
- }
- } else {
- String errorMsg = "Failed to initialize distribution client: " + initResult.getDistributionMessageResult();
- logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg);
-
- // Kick off a timer to retry the SDC connection
- Timer timer = new Timer();
- TimerTask task = new SdcConnectionJob(client, config, eventCallback, timer);
- timer.schedule(task, new Date(), 60000);
- }
-
- Runtime.getRuntime().addShutdownHook(new Thread(this::preShutdownOperations));
- }
-