Skip to content

Commit

Permalink
add Ordered interface to MessageProducerManager and Injector SPI
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam committed Jan 18, 2023
1 parent af2751f commit 5670a0e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
package com.ctrip.framework.apollo.internals;

import com.ctrip.framework.apollo.core.spi.Ordered;

/**
* @author Jason Song([email protected])
*/
public interface Injector {
public interface Injector extends Ordered {

/**
* Returns the appropriate instance for the given injection type
Expand All @@ -30,4 +32,9 @@ public interface Injector {
* Returns the appropriate instance for the given injection type and name
*/
<T> T getInstance(Class<T> clazz, String name);

@Override
default int getOrder() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
*/
package com.ctrip.framework.apollo.tracer.spi;

import com.ctrip.framework.apollo.core.spi.Ordered;

/**
* @author Jason Song([email protected])
*/
public interface MessageProducerManager {
public interface MessageProducerManager extends Ordered {
/**
* @return the message producer
*/
MessageProducer getProducer();

@Override
default int getOrder() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import java.util.ServiceLoader;

public class ServiceBootstrap {

/**
* @deprecated use {@link ServiceBootstrap#loadPrimary(Class)} instead
*/
public static <S> S loadFirst(Class<S> clazz) {
Iterator<S> iterator = loadAll(clazz);
if (!iterator.hasNext()) {
Expand Down

0 comments on commit 5670a0e

Please sign in to comment.