From 5670a0edce147512e86dee83a4861729a40000ef Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 18 Jan 2023 22:14:08 +0800 Subject: [PATCH] add Ordered interface to MessageProducerManager and Injector SPI --- CHANGES.md | 2 ++ .../com/ctrip/framework/apollo/build/ApolloInjector.java | 2 +- .../com/ctrip/framework/apollo/internals/Injector.java | 9 ++++++++- .../java/com/ctrip/framework/apollo/tracer/Tracer.java | 2 +- .../apollo/tracer/spi/MessageProducerManager.java | 9 ++++++++- .../framework/foundation/internals/ServiceBootstrap.java | 4 ++++ 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 333298e8..d3fcd680 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,5 +17,7 @@ Apollo Java 2.1.0 * [apollo-client-config-data support spring boot 3.0](https://github.com/apolloconfig/apollo-java/pull/5) * [Add apollo-plugin-log4j2 module to support log4j2.xml integration](https://github.com/apolloconfig/apollo-java/pull/6) * [Allow users to config comma-separated namespaces for ApolloConfigChangeListener](https://github.com/apolloconfig/apollo-java/pull/11) +* [Add Ordered interface to MessageProducerManager and Injector SPI](https://github.com/apolloconfig/apollo-java/pull/15) + ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/1?closed=1) \ No newline at end of file diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/build/ApolloInjector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/build/ApolloInjector.java index 2871cc96..3b7063e4 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/build/ApolloInjector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/build/ApolloInjector.java @@ -33,7 +33,7 @@ private static Injector getInjector() { synchronized (lock) { if (s_injector == null) { try { - s_injector = ServiceBootstrap.loadFirst(Injector.class); + s_injector = ServiceBootstrap.loadPrimary(Injector.class); } catch (Throwable ex) { ApolloConfigException exception = new ApolloConfigException("Unable to initialize Apollo Injector!", ex); Tracer.logError(exception); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/Injector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/Injector.java index fab83b5f..a7ae8588 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/Injector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/Injector.java @@ -16,10 +16,12 @@ */ package com.ctrip.framework.apollo.internals; +import com.ctrip.framework.apollo.core.spi.Ordered; + /** * @author Jason Song(song_s@ctrip.com) */ -public interface Injector { +public interface Injector extends Ordered { /** * Returns the appropriate instance for the given injection type @@ -30,4 +32,9 @@ public interface Injector { * Returns the appropriate instance for the given injection type and name */ T getInstance(Class clazz, String name); + + @Override + default int getOrder() { + return 0; + } } diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/Tracer.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/Tracer.java index e7818eac..e97e8a6d 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/Tracer.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/Tracer.java @@ -44,7 +44,7 @@ private static MessageProducer getProducer() { if (producerManager == null) { synchronized (lock) { if (producerManager == null) { - producerManager = ServiceBootstrap.loadFirst(MessageProducerManager.class); + producerManager = ServiceBootstrap.loadPrimary(MessageProducerManager.class); } } } diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/spi/MessageProducerManager.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/spi/MessageProducerManager.java index 2d174dd7..0c3afdb5 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/spi/MessageProducerManager.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/spi/MessageProducerManager.java @@ -16,12 +16,19 @@ */ package com.ctrip.framework.apollo.tracer.spi; +import com.ctrip.framework.apollo.core.spi.Ordered; + /** * @author Jason Song(song_s@ctrip.com) */ -public interface MessageProducerManager { +public interface MessageProducerManager extends Ordered { /** * @return the message producer */ MessageProducer getProducer(); + + @Override + default int getOrder() { + return 0; + } } diff --git a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/ServiceBootstrap.java b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/ServiceBootstrap.java index 28273afd..27d62cf8 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/ServiceBootstrap.java +++ b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/ServiceBootstrap.java @@ -25,6 +25,10 @@ import java.util.ServiceLoader; public class ServiceBootstrap { + + /** + * @deprecated use {@link ServiceBootstrap#loadPrimary(Class)} instead + */ public static S loadFirst(Class clazz) { Iterator iterator = loadAll(clazz); if (!iterator.hasNext()) {