diff --git a/Plan/api/src/main/java/com/djrapitops/plan/capability/CapabilityService.java b/Plan/api/src/main/java/com/djrapitops/plan/capability/CapabilityService.java index 0bcff2f3f..bf5bb0000 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/capability/CapabilityService.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/capability/CapabilityService.java @@ -18,6 +18,7 @@ package com.djrapitops.plan.capability; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; /** @@ -49,7 +50,7 @@ public interface CapabilityService { * @param isEnabledListener The boolean given to the method tells if Plan has enabled successfully. */ default void registerEnableListener(Consumer isEnabledListener) { - ListHolder.ENABLE_LISTENERS.add(isEnabledListener); + ListHolder.ENABLE_LISTENERS.get().add(isEnabledListener); } /** @@ -64,6 +65,8 @@ public interface CapabilityService { } class ListHolder { - volatile static List> ENABLE_LISTENERS = new CopyOnWriteArrayList<>(); + volatile static AtomicReference>> ENABLE_LISTENERS = new AtomicReference<>( + new CopyOnWriteArrayList<>() + ); } } diff --git a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/ResolverService.java b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/ResolverService.java index eda3288ce..04b5d7204 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/ResolverService.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/ResolverService.java @@ -20,6 +20,7 @@ import com.djrapitops.plan.delivery.web.resolver.Resolver; import java.util.List; import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Pattern; /** @@ -34,7 +35,7 @@ import java.util.regex.Pattern; public interface ResolverService { static ResolverService getInstance() { - return Optional.ofNullable(ResolverService.Holder.service) + return Optional.ofNullable(ResolverService.Holder.service.get()) .orElseThrow(() -> new IllegalStateException("ResolverService has not been initialised yet.")); } @@ -88,14 +89,14 @@ public interface ResolverService { List getResolvers(String target); class Holder { - volatile static ResolverService service; + volatile static AtomicReference service = new AtomicReference<>(); private Holder() { /* Static variable holder */ } static void set(ResolverService service) { - ResolverService.Holder.service = service; + ResolverService.Holder.service.set(service); } } } diff --git a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/ResourceService.java b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/ResourceService.java index 78eb7d330..bce55088d 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/ResourceService.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/ResourceService.java @@ -19,6 +19,7 @@ package com.djrapitops.plan.delivery.web; import com.djrapitops.plan.delivery.web.resource.WebResource; import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; /** @@ -29,7 +30,7 @@ import java.util.function.Supplier; public interface ResourceService { static ResourceService getInstance() { - return Optional.ofNullable(ResourceService.Holder.service) + return Optional.ofNullable(ResourceService.Holder.service.get()) .orElseThrow(() -> new IllegalStateException("ResourceService has not been initialised yet.")); } @@ -102,14 +103,14 @@ public interface ResourceService { } class Holder { - volatile static ResourceService service; + volatile static AtomicReference service = new AtomicReference<>(); private Holder() { /* Static variable holder */ } static void set(ResourceService service) { - ResourceService.Holder.service = service; + ResourceService.Holder.service.set(service); } } } diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/ExtensionService.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/ExtensionService.java index 99f33a47b..53eb927e5 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/ExtensionService.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/ExtensionService.java @@ -19,6 +19,7 @@ package com.djrapitops.plan.extension; import com.djrapitops.plan.extension.extractor.ExtensionExtractor; import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; /** * Interface for registering {@link DataExtension}s. @@ -44,7 +45,7 @@ public interface ExtensionService { * @throws IllegalStateException If Plan is installed, but not enabled. */ static ExtensionService getInstance() { - return Optional.ofNullable(Holder.service) + return Optional.ofNullable(Holder.service.get()) .orElseThrow(() -> new IllegalStateException("ExtensionService has not been initialised yet.")); } @@ -70,14 +71,14 @@ public interface ExtensionService { void unregister(DataExtension extension); class Holder { - volatile static ExtensionService service; + volatile static AtomicReference service = new AtomicReference<>(); private Holder() { /* Static variable holder */ } static void set(ExtensionService service) { - Holder.service = service; + Holder.service.set(service); } } diff --git a/Plan/api/src/main/java/com/djrapitops/plan/query/QueryService.java b/Plan/api/src/main/java/com/djrapitops/plan/query/QueryService.java index 43fd4bbed..ca9227381 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/query/QueryService.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/query/QueryService.java @@ -21,6 +21,7 @@ import java.sql.SQLException; import java.util.Optional; import java.util.UUID; import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; /** @@ -40,7 +41,7 @@ public interface QueryService { * @throws IllegalStateException If Plan is installed, but not enabled. */ static QueryService getInstance() { - return Optional.ofNullable(Holder.service) + return Optional.ofNullable(Holder.service.get()) .orElseThrow(() -> new IllegalStateException("QueryService has not been initialised yet.")); } @@ -149,14 +150,14 @@ public interface QueryService { } class Holder { - volatile static QueryService service; + volatile static AtomicReference service = new AtomicReference<>(); private Holder() { /* Static variable holder */ } static void set(QueryService service) { - Holder.service = service; + Holder.service.set(service); } } diff --git a/Plan/api/src/main/java/com/djrapitops/plan/settings/SettingsService.java b/Plan/api/src/main/java/com/djrapitops/plan/settings/SettingsService.java index 8a5fce3f7..5e10f8fe4 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/settings/SettingsService.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/settings/SettingsService.java @@ -18,6 +18,7 @@ package com.djrapitops.plan.settings; import java.util.List; import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; /** @@ -33,7 +34,7 @@ import java.util.function.Supplier; public interface SettingsService { static SettingsService getInstance() { - return Optional.ofNullable(Holder.service) + return Optional.ofNullable(Holder.service.get()) .orElseThrow(() -> new IllegalStateException("SettingsService has not been initialised yet.")); } @@ -65,14 +66,14 @@ public interface SettingsService { List getStringList(String path, Supplier> defaultValue); class Holder { - volatile static SettingsService service; + volatile static AtomicReference service = new AtomicReference<>(); private Holder() { /* Static variable holder */ } static void set(SettingsService service) { - Holder.service = service; + Holder.service.set(service); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/capability/CapabilitySvc.java b/Plan/common/src/main/java/com/djrapitops/plan/capability/CapabilitySvc.java index 946ec142c..acb19bb65 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/capability/CapabilitySvc.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/capability/CapabilitySvc.java @@ -28,7 +28,7 @@ import java.util.function.Consumer; public class CapabilitySvc implements CapabilityService { public static void notifyAboutEnable(boolean isEnabled) { - for (Consumer enableListener : CapabilityService.ListHolder.ENABLE_LISTENERS) { + for (Consumer enableListener : CapabilityService.ListHolder.ENABLE_LISTENERS.get()) { enableListener.accept(isEnabled); } }