All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.hana.datalake.files.utils.filewatcher.CertificateWatcherService Maven / Gradle / Ivy

Go to download

An implementation of org.apache.hadoop.fs.FileSystem targeting SAP HANA Data Lake Files.

There is a newer version: 3.0.27
Show newest version
// © 2023-2024 SAP SE or an SAP affiliate company. All rights reserved.
package com.sap.hana.datalake.files.utils.filewatcher;

import org.apache.hadoop.conf.Configuration;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CertificateWatcherService {

  private static volatile CertificateWatcherService instance;

  private final Map, CertificateWatcher> certificateWatchers;

  public static CertificateWatcherService getInstance() {
    if (instance == null) {
      synchronized (CertificateWatcherService.class) {
        if (instance == null) {
          instance = new CertificateWatcherService();
        }
      }
    }

    return instance;
  }

  private CertificateWatcherService() {
    this.certificateWatchers = new HashMap<>();
  }

  public void watchCertificates(final List certificates,
                                final CertificateWatcher.CertificateRotationHandler certificateRotationHandler,
                                final Configuration conf) {
    final CertificateWatcher certificateWatcher;

    synchronized (this.certificateWatchers) {
      certificateWatcher = this.certificateWatchers.computeIfAbsent(certificates, certs -> this.startNewCertificateWatcher(certs, conf));
    }

    certificateWatcher.registerCertificateHandler(certificateRotationHandler);
  }

  public void shutdown() {
    synchronized (this.certificateWatchers) {
      this.certificateWatchers.values().forEach(CertificateWatcher::shutdown);
      this.certificateWatchers.clear();
    }
  }

  private CertificateWatcher startNewCertificateWatcher(final List certificates, final Configuration conf) {
    final CertificateWatcher certificateWatcher = new CertificateWatcher(certificates, conf);
    certificateWatcher.start();

    return certificateWatcher;
  }

}

// © 2023-2024 SAP SE or an SAP affiliate company. All rights reserved.




© 2015 - 2025 Weber Informatics LLC | Privacy Policy