Skip to content

Commit

Permalink
Improve init and fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
cdfive committed Apr 28, 2020
1 parent d5cc3e7 commit d3926c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public final class Constants {
public static final int ORDER_STATISTIC_SLOT = -7000;
public static final int ORDER_AUTHORITY_SLOT = -6000;
public static final int ORDER_SYSTEM_SLOT = -5000;
// order in GatewayFlowSlot -4000
// order in ParamFlowSlot -3000
// order of GatewayFlowSlot -4000
// order of ParamFlowSlot -3000
public static final int ORDER_FLOW_SLOT = -2000;
public static final int ORDER_DEGRADE_SLOT = -1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* <p>SPI is short for Service Provider Interface.</p>
*
* <p>
* Service is represented by a single type, that is, a single interface or abstract class.
* Service is represented by a single type, that is, a single interface or an abstract class.
* Provider is implementations of Service, that is, some classes which implement the interface or extends the abstract class.
* </p>
*
Expand Down Expand Up @@ -64,9 +64,9 @@
*
* @author Eric Zhao
* @author cdfive
* @see Spi
* @see java.util.ServiceLoader
* @since 1.4.0
* @see com.alibaba.csp.sentinel.spi.Spi
* @see java.util.ServiceLoader
*/
public final class SpiLoader<S> {

Expand Down Expand Up @@ -117,8 +117,13 @@ public static <T> SpiLoader<T> of(Class<T> service) {
String className = service.getName();
SpiLoader<T> spiLoader = SPI_LOADER_MAP.get(className);
if (spiLoader == null) {
SPI_LOADER_MAP.putIfAbsent(className, new SpiLoader<>(service));
spiLoader = SPI_LOADER_MAP.get(className);
synchronized (SpiLoader.class) {
spiLoader = SPI_LOADER_MAP.get(className);
if (spiLoader == null) {
SPI_LOADER_MAP.putIfAbsent(className, new SpiLoader<>(service));
spiLoader = SPI_LOADER_MAP.get(className);
}
}
}

return spiLoader;
Expand Down Expand Up @@ -338,11 +343,11 @@ public void load() {
try {
urls = classLoader.getResources(fullFileName);
} catch (IOException e) {
fail("Error locating SPI file,fileName=" + fullFileName + ",classloader=" + classLoader, e);
fail("Error locating SPI file,filename=" + fullFileName + ",classloader=" + classLoader, e);
}

if (urls == null || !urls.hasMoreElements()) {
RecordLog.warn("No SPI file,fileName=" + fullFileName + ",classloader=" + classLoader);
RecordLog.warn("No SPI file,filename=" + fullFileName + ",classloader=" + classLoader);
return;
}

Expand Down Expand Up @@ -381,7 +386,7 @@ public void load() {
}

if (!service.isAssignableFrom(clazz)) {
fail("class " + clazz.getName() + "is not subtype of " + service.getName() + ",SPI file name=" + fullFileName);
fail("class " + clazz.getName() + "is not subtype of " + service.getName() + ",SPI filename=" + fullFileName);
}

classList.add(clazz);
Expand All @@ -390,7 +395,7 @@ public void load() {
if (classMap.containsKey(aliasName)) {
Class<? extends S> existClass = classMap.get(aliasName);
fail("Found repeat aliasname for " + clazz.getName() + " and "
+ existClass.getName() + ",SPI file name=" + fullFileName);
+ existClass.getName() + ",SPI filename=" + fullFileName);
}
classMap.put(aliasName, clazz);

Expand Down

0 comments on commit d3926c4

Please sign in to comment.