From d97e3e4b0b6f427549f3a7e762577545bd94c980 Mon Sep 17 00:00:00 2001 From: guljain Date: Tue, 30 Jul 2024 06:01:21 +0000 Subject: [PATCH] cherry pick #1227 --- .../hadoop/fs/gcs/GoogleCloudStorageEventSubscriber.java | 6 ++++-- .../google/cloud/hadoop/fs/gcs/GoogleHadoopFileSystem.java | 2 +- .../cloud/hadoop/fs/gcs/GoogleHadoopFileSystemBase.java | 0 .../hadoop/fs/gcs/GoogleCloudStorageStatisticsTest.java | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) delete mode 100644 gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleHadoopFileSystemBase.java diff --git a/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleCloudStorageEventSubscriber.java b/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleCloudStorageEventSubscriber.java index 4552e2f336..588cfd8307 100644 --- a/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleCloudStorageEventSubscriber.java +++ b/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleCloudStorageEventSubscriber.java @@ -28,9 +28,11 @@ /* Stores the subscriber methods corresponding to GoogleCloudStorageEventBus */ public class GoogleCloudStorageEventSubscriber { + private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); private static GhfsGlobalStorageStatistics storageStatistics; + private static GoogleCloudStorageEventSubscriber INSTANCE = null; - public GoogleCloudStorageEventSubscriber(GhfsGlobalStorageStatistics storageStatistics) { + private GoogleCloudStorageEventSubscriber(GhfsGlobalStorageStatistics storageStatistics) { this.storageStatistics = storageStatistics; } @@ -38,7 +40,7 @@ public GoogleCloudStorageEventSubscriber(GhfsGlobalStorageStatistics storageStat * Singleton class such that registration of subscriber methods is only once. * */ public static synchronized GoogleCloudStorageEventSubscriber getInstance( - @Nonnull GhfsStorageStatistics storageStatistics) { + @Nonnull GhfsGlobalStorageStatistics storageStatistics) { if (INSTANCE == null) { logger.atFiner().log("Subscriber class invoked for first time"); INSTANCE = new GoogleCloudStorageEventSubscriber(storageStatistics); diff --git a/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleHadoopFileSystem.java b/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleHadoopFileSystem.java index 018f193fba..c147a7ed2d 100644 --- a/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleHadoopFileSystem.java +++ b/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleHadoopFileSystem.java @@ -250,7 +250,7 @@ public GoogleHadoopFileSystem() { } GoogleCloudStorageEventBus.register( - new GoogleCloudStorageEventSubscriber(globalStorageStatistics)); + GoogleCloudStorageEventSubscriber.getInstance(globalStorageStatistics)); } /** diff --git a/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleHadoopFileSystemBase.java b/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleHadoopFileSystemBase.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/gcs/src/test/java/com/google/cloud/hadoop/fs/gcs/GoogleCloudStorageStatisticsTest.java b/gcs/src/test/java/com/google/cloud/hadoop/fs/gcs/GoogleCloudStorageStatisticsTest.java index 1fe709a588..3c82800b96 100644 --- a/gcs/src/test/java/com/google/cloud/hadoop/fs/gcs/GoogleCloudStorageStatisticsTest.java +++ b/gcs/src/test/java/com/google/cloud/hadoop/fs/gcs/GoogleCloudStorageStatisticsTest.java @@ -89,7 +89,7 @@ public void test_multiple_register_of_statistics() throws Exception { GoogleCloudStorageEventSubscriber.getInstance(storageStatistics)); GoogleCloudStorageEventBus.onGcsRequest(new GcsRequestExecutionEvent()); - GhfsStorageStatistics verifyCounterStats = new GhfsStorageStatistics(); + GhfsGlobalStorageStatistics verifyCounterStats = new GhfsGlobalStorageStatistics(); verifyCounterStats.incrementCounter(GCS_API_REQUEST_COUNT, 1); verifyStatistics(verifyCounterStats); }