Skip to content

Commit 623559e

Browse files
committed
add Ordered interface to MessageProducerManager and Injector SPI
1 parent 8d17de5 commit 623559e

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Apollo Java 2.1.0
1818
* [Add apollo-plugin-log4j2 module to support log4j2.xml integration](https://github.com/apolloconfig/apollo-java/pull/6)
1919
* [Allow users to config comma-separated namespaces for ApolloConfigChangeListener](https://github.com/apolloconfig/apollo-java/pull/11)
2020
* [Fix beanName2SpringValueDefinitions cache issue](https://github.com/apolloconfig/apollo-java/pull/16)
21+
* [Add Ordered interface to MessageProducerManager and Injector SPI](https://github.com/apolloconfig/apollo-java/pull/15)
2122

2223
------------------
2324
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/1?closed=1)

apollo-client/src/main/java/com/ctrip/framework/apollo/build/ApolloInjector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private static Injector getInjector() {
3333
synchronized (lock) {
3434
if (s_injector == null) {
3535
try {
36-
s_injector = ServiceBootstrap.loadFirst(Injector.class);
36+
s_injector = ServiceBootstrap.loadPrimary(Injector.class);
3737
} catch (Throwable ex) {
3838
ApolloConfigException exception = new ApolloConfigException("Unable to initialize Apollo Injector!", ex);
3939
Tracer.logError(exception);

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/Injector.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
*/
1717
package com.ctrip.framework.apollo.internals;
1818

19+
import com.ctrip.framework.apollo.core.spi.Ordered;
20+
1921
/**
2022
* @author Jason Song(song_s@ctrip.com)
2123
*/
22-
public interface Injector {
24+
public interface Injector extends Ordered {
2325

2426
/**
2527
* Returns the appropriate instance for the given injection type
@@ -30,4 +32,9 @@ public interface Injector {
3032
* Returns the appropriate instance for the given injection type and name
3133
*/
3234
<T> T getInstance(Class<T> clazz, String name);
35+
36+
@Override
37+
default int getOrder() {
38+
return 0;
39+
}
3340
}

apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/Tracer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private static MessageProducer getProducer() {
4444
if (producerManager == null) {
4545
synchronized (lock) {
4646
if (producerManager == null) {
47-
producerManager = ServiceBootstrap.loadFirst(MessageProducerManager.class);
47+
producerManager = ServiceBootstrap.loadPrimary(MessageProducerManager.class);
4848
}
4949
}
5050
}

apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/spi/MessageProducerManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@
1616
*/
1717
package com.ctrip.framework.apollo.tracer.spi;
1818

19+
import com.ctrip.framework.apollo.core.spi.Ordered;
20+
1921
/**
2022
* @author Jason Song(song_s@ctrip.com)
2123
*/
22-
public interface MessageProducerManager {
24+
public interface MessageProducerManager extends Ordered {
2325
/**
2426
* @return the message producer
2527
*/
2628
MessageProducer getProducer();
29+
30+
@Override
31+
default int getOrder() {
32+
return 0;
33+
}
2734
}

apollo-core/src/main/java/com/ctrip/framework/foundation/internals/ServiceBootstrap.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import java.util.ServiceLoader;
2626

2727
public class ServiceBootstrap {
28+
29+
/**
30+
* @deprecated use {@link ServiceBootstrap#loadPrimary(Class)} instead
31+
*/
2832
public static <S> S loadFirst(Class<S> clazz) {
2933
Iterator<S> iterator = loadAll(clazz);
3034
if (!iterator.hasNext()) {

0 commit comments

Comments
 (0)