Skip to content

Commit 70edcf8

Browse files
slievrlybeiwei30
authored andcommitted
optimize constant naming style (#3970)
1 parent 667f227 commit 70edcf8

File tree

29 files changed

+148
-148
lines changed

29 files changed

+148
-148
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/merger/MergerFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
public class MergerFactory {
2929

30-
private static final ConcurrentMap<Class<?>, Merger<?>> mergerCache =
30+
private static final ConcurrentMap<Class<?>, Merger<?>> MERGER_CACHE =
3131
new ConcurrentHashMap<Class<?>, Merger<?>>();
3232

3333
/**
@@ -46,19 +46,19 @@ public static <T> Merger<T> getMerger(Class<T> returnType) {
4646
Merger result;
4747
if (returnType.isArray()) {
4848
Class type = returnType.getComponentType();
49-
result = mergerCache.get(type);
49+
result = MERGER_CACHE.get(type);
5050
if (result == null) {
5151
loadMergers();
52-
result = mergerCache.get(type);
52+
result = MERGER_CACHE.get(type);
5353
}
5454
if (result == null && !type.isPrimitive()) {
5555
result = ArrayMerger.INSTANCE;
5656
}
5757
} else {
58-
result = mergerCache.get(returnType);
58+
result = MERGER_CACHE.get(returnType);
5959
if (result == null) {
6060
loadMergers();
61-
result = mergerCache.get(returnType);
61+
result = MERGER_CACHE.get(returnType);
6262
}
6363
}
6464
return result;
@@ -69,7 +69,7 @@ static void loadMergers() {
6969
.getSupportedExtensions();
7070
for (String name : names) {
7171
Merger m = ExtensionLoader.getExtensionLoader(Merger.class).getExtension(name);
72-
mergerCache.putIfAbsent(ReflectUtils.getGenericClass(m.getClass()), m);
72+
MERGER_CACHE.putIfAbsent(ReflectUtils.getGenericClass(m.getClass()), m);
7373
}
7474
}
7575

dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public Object invoke(Object proxy, Method method, Object[] args) {
4848
};
4949
private static final AtomicLong PROXY_CLASS_COUNTER = new AtomicLong(0);
5050
private static final String PACKAGE_NAME = Proxy.class.getPackage().getName();
51-
private static final Map<ClassLoader, Map<String, Object>> ProxyCacheMap = new WeakHashMap<ClassLoader, Map<String, Object>>();
51+
private static final Map<ClassLoader, Map<String, Object>> PROXY_CACHE_MAP = new WeakHashMap<ClassLoader, Map<String, Object>>();
5252

53-
private static final Object PendingGenerationMarker = new Object();
53+
private static final Object PENDING_GENERATION_MARKER = new Object();
5454

5555
protected Proxy() {
5656
}
@@ -102,8 +102,8 @@ public static Proxy getProxy(ClassLoader cl, Class<?>... ics) {
102102

103103
// get cache by class loader.
104104
Map<String, Object> cache;
105-
synchronized (ProxyCacheMap) {
106-
cache = ProxyCacheMap.computeIfAbsent(cl, k -> new HashMap<>());
105+
synchronized (PROXY_CACHE_MAP) {
106+
cache = PROXY_CACHE_MAP.computeIfAbsent(cl, k -> new HashMap<>());
107107
}
108108

109109
Proxy proxy = null;
@@ -117,13 +117,13 @@ public static Proxy getProxy(ClassLoader cl, Class<?>... ics) {
117117
}
118118
}
119119

120-
if (value == PendingGenerationMarker) {
120+
if (value == PENDING_GENERATION_MARKER) {
121121
try {
122122
cache.wait();
123123
} catch (InterruptedException e) {
124124
}
125125
} else {
126-
cache.put(key, PendingGenerationMarker);
126+
cache.put(key, PENDING_GENERATION_MARKER);
127127
break;
128128
}
129129
}

dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocal.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
public class InternalThreadLocal<V> {
3535

36-
private static final int variablesToRemoveIndex = InternalThreadLocalMap.nextVariableIndex();
36+
private static final int VARIABLES_TO_REMOVE_INDEX = InternalThreadLocalMap.nextVariableIndex();
3737

3838
private final int index;
3939

@@ -54,7 +54,7 @@ public static void removeAll() {
5454
}
5555

5656
try {
57-
Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex);
57+
Object v = threadLocalMap.indexedVariable(VARIABLES_TO_REMOVE_INDEX);
5858
if (v != null && v != InternalThreadLocalMap.UNSET) {
5959
Set<InternalThreadLocal<?>> variablesToRemove = (Set<InternalThreadLocal<?>>) v;
6060
InternalThreadLocal<?>[] variablesToRemoveArray =
@@ -86,11 +86,11 @@ public static void destroy() {
8686

8787
@SuppressWarnings("unchecked")
8888
private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, InternalThreadLocal<?> variable) {
89-
Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex);
89+
Object v = threadLocalMap.indexedVariable(VARIABLES_TO_REMOVE_INDEX);
9090
Set<InternalThreadLocal<?>> variablesToRemove;
9191
if (v == InternalThreadLocalMap.UNSET || v == null) {
9292
variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<InternalThreadLocal<?>, Boolean>());
93-
threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove);
93+
threadLocalMap.setIndexedVariable(VARIABLES_TO_REMOVE_INDEX, variablesToRemove);
9494
} else {
9595
variablesToRemove = (Set<InternalThreadLocal<?>>) v;
9696
}
@@ -101,7 +101,7 @@ private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap
101101
@SuppressWarnings("unchecked")
102102
private static void removeFromVariablesToRemove(InternalThreadLocalMap threadLocalMap, InternalThreadLocal<?> variable) {
103103

104-
Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex);
104+
Object v = threadLocalMap.indexedVariable(VARIABLES_TO_REMOVE_INDEX);
105105

106106
if (v == InternalThreadLocalMap.UNSET || v == null) {
107107
return;

dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalMap.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public final class InternalThreadLocalMap {
3030

3131
private static ThreadLocal<InternalThreadLocalMap> slowThreadLocalMap = new ThreadLocal<InternalThreadLocalMap>();
3232

33-
private static final AtomicInteger nextIndex = new AtomicInteger();
33+
private static final AtomicInteger NEXT_INDEX = new AtomicInteger();
3434

3535
public static final Object UNSET = new Object();
3636

@@ -64,16 +64,16 @@ public static void destroy() {
6464
}
6565

6666
public static int nextVariableIndex() {
67-
int index = nextIndex.getAndIncrement();
67+
int index = NEXT_INDEX.getAndIncrement();
6868
if (index < 0) {
69-
nextIndex.decrementAndGet();
69+
NEXT_INDEX.decrementAndGet();
7070
throw new IllegalStateException("Too many thread-local indexed variables");
7171
}
7272
return index;
7373
}
7474

7575
public static int lastVariableIndex() {
76-
return nextIndex.get() - 1;
76+
return NEXT_INDEX.get() - 1;
7777
}
7878

7979
private InternalThreadLocalMap() {

dubbo-common/src/main/java/org/apache/dubbo/common/utils/AtomicPositiveInteger.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class AtomicPositiveInteger extends Number {
2222

2323
private static final long serialVersionUID = -3038533876489105940L;
2424

25-
private static final AtomicIntegerFieldUpdater<AtomicPositiveInteger> indexUpdater =
25+
private static final AtomicIntegerFieldUpdater<AtomicPositiveInteger> INDEX_UPDATER =
2626
AtomicIntegerFieldUpdater.newUpdater(AtomicPositiveInteger.class, "index");
2727

2828
@SuppressWarnings("unused")
@@ -32,69 +32,69 @@ public AtomicPositiveInteger() {
3232
}
3333

3434
public AtomicPositiveInteger(int initialValue) {
35-
indexUpdater.set(this, initialValue);
35+
INDEX_UPDATER.set(this, initialValue);
3636
}
3737

3838
public final int getAndIncrement() {
39-
return indexUpdater.getAndIncrement(this) & Integer.MAX_VALUE;
39+
return INDEX_UPDATER.getAndIncrement(this) & Integer.MAX_VALUE;
4040
}
4141

4242
public final int getAndDecrement() {
43-
return indexUpdater.getAndDecrement(this) & Integer.MAX_VALUE;
43+
return INDEX_UPDATER.getAndDecrement(this) & Integer.MAX_VALUE;
4444
}
4545

4646
public final int incrementAndGet() {
47-
return indexUpdater.incrementAndGet(this) & Integer.MAX_VALUE;
47+
return INDEX_UPDATER.incrementAndGet(this) & Integer.MAX_VALUE;
4848
}
4949

5050
public final int decrementAndGet() {
51-
return indexUpdater.decrementAndGet(this) & Integer.MAX_VALUE;
51+
return INDEX_UPDATER.decrementAndGet(this) & Integer.MAX_VALUE;
5252
}
5353

5454
public final int get() {
55-
return indexUpdater.get(this) & Integer.MAX_VALUE;
55+
return INDEX_UPDATER.get(this) & Integer.MAX_VALUE;
5656
}
5757

5858
public final void set(int newValue) {
5959
if (newValue < 0) {
6060
throw new IllegalArgumentException("new value " + newValue + " < 0");
6161
}
62-
indexUpdater.set(this, newValue);
62+
INDEX_UPDATER.set(this, newValue);
6363
}
6464

6565
public final int getAndSet(int newValue) {
6666
if (newValue < 0) {
6767
throw new IllegalArgumentException("new value " + newValue + " < 0");
6868
}
69-
return indexUpdater.getAndSet(this, newValue) & Integer.MAX_VALUE;
69+
return INDEX_UPDATER.getAndSet(this, newValue) & Integer.MAX_VALUE;
7070
}
7171

7272
public final int getAndAdd(int delta) {
7373
if (delta < 0) {
7474
throw new IllegalArgumentException("delta " + delta + " < 0");
7575
}
76-
return indexUpdater.getAndAdd(this, delta) & Integer.MAX_VALUE;
76+
return INDEX_UPDATER.getAndAdd(this, delta) & Integer.MAX_VALUE;
7777
}
7878

7979
public final int addAndGet(int delta) {
8080
if (delta < 0) {
8181
throw new IllegalArgumentException("delta " + delta + " < 0");
8282
}
83-
return indexUpdater.addAndGet(this, delta) & Integer.MAX_VALUE;
83+
return INDEX_UPDATER.addAndGet(this, delta) & Integer.MAX_VALUE;
8484
}
8585

8686
public final boolean compareAndSet(int expect, int update) {
8787
if (update < 0) {
8888
throw new IllegalArgumentException("update value " + update + " < 0");
8989
}
90-
return indexUpdater.compareAndSet(this, expect, update);
90+
return INDEX_UPDATER.compareAndSet(this, expect, update);
9191
}
9292

9393
public final boolean weakCompareAndSet(int expect, int update) {
9494
if (update < 0) {
9595
throw new IllegalArgumentException("update value " + update + " < 0");
9696
}
97-
return indexUpdater.weakCompareAndSet(this, expect, update);
97+
return INDEX_UPDATER.weakCompareAndSet(this, expect, update);
9898
}
9999

100100
@Override

dubbo-common/src/main/java/org/apache/dubbo/common/utils/ExecutorUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
public class ExecutorUtil {
3232
private static final Logger logger = LoggerFactory.getLogger(ExecutorUtil.class);
33-
private static final ThreadPoolExecutor shutdownExecutor = new ThreadPoolExecutor(0, 1,
33+
private static final ThreadPoolExecutor SHUTDOWN_EXECUTOR = new ThreadPoolExecutor(0, 1,
3434
0L, TimeUnit.MILLISECONDS,
3535
new LinkedBlockingQueue<Runnable>(100),
3636
new NamedThreadFactory("Close-ExecutorService-Timer", true));
@@ -102,7 +102,7 @@ public static void shutdownNow(Executor executor, final int timeout) {
102102

103103
private static void newThreadToCloseExecutor(final ExecutorService es) {
104104
if (!isTerminated(es)) {
105-
shutdownExecutor.execute(new Runnable() {
105+
SHUTDOWN_EXECUTOR.execute(new Runnable() {
106106
@Override
107107
public void run() {
108108
try {

dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class NetUtils {
5555
private static final Pattern LOCAL_IP_PATTERN = Pattern.compile("127(\\.\\d{1,3}){3}$");
5656
private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$");
5757

58-
private static final Map<String, String> hostNameCache = new LRUCache<>(1000);
58+
private static final Map<String, String> HOST_NAME_CACHE = new LRUCache<>(1000);
5959
private static volatile InetAddress LOCAL_ADDRESS = null;
6060

6161
private static final String SPLIT_IPV4_CHARECTER = "\\.";
@@ -291,14 +291,14 @@ public static String getHostName(String address) {
291291
if (i > -1) {
292292
address = address.substring(0, i);
293293
}
294-
String hostname = hostNameCache.get(address);
294+
String hostname = HOST_NAME_CACHE.get(address);
295295
if (hostname != null && hostname.length() > 0) {
296296
return hostname;
297297
}
298298
InetAddress inetAddress = InetAddress.getByName(address);
299299
if (inetAddress != null) {
300300
hostname = inetAddress.getHostName();
301-
hostNameCache.put(address, hostname);
301+
HOST_NAME_CACHE.put(address, hostname);
302302
return hostname;
303303
}
304304
} catch (Throwable e) {

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,22 @@ public abstract class AbstractConfig implements Serializable {
9595
/**
9696
* The legacy properties container
9797
*/
98-
private static final Map<String, String> legacyProperties = new HashMap<String, String>();
98+
private static final Map<String, String> LEGACY_PROPERTIES = new HashMap<String, String>();
9999

100100
/**
101101
* The suffix container
102102
*/
103103
private static final String[] SUFFIXES = new String[]{"Config", "Bean"};
104104

105105
static {
106-
legacyProperties.put("dubbo.protocol.name", "dubbo.service.protocol");
107-
legacyProperties.put("dubbo.protocol.host", "dubbo.service.server.host");
108-
legacyProperties.put("dubbo.protocol.port", "dubbo.service.server.port");
109-
legacyProperties.put("dubbo.protocol.threads", "dubbo.service.max.thread.pool.size");
110-
legacyProperties.put("dubbo.consumer.timeout", "dubbo.service.invoke.timeout");
111-
legacyProperties.put("dubbo.consumer.retries", "dubbo.service.max.retry.providers");
112-
legacyProperties.put("dubbo.consumer.check", "dubbo.service.allow.no.provider");
113-
legacyProperties.put("dubbo.service.url", "dubbo.service.address");
106+
LEGACY_PROPERTIES.put("dubbo.protocol.name", "dubbo.service.protocol");
107+
LEGACY_PROPERTIES.put("dubbo.protocol.host", "dubbo.service.server.host");
108+
LEGACY_PROPERTIES.put("dubbo.protocol.port", "dubbo.service.server.port");
109+
LEGACY_PROPERTIES.put("dubbo.protocol.threads", "dubbo.service.max.thread.pool.size");
110+
LEGACY_PROPERTIES.put("dubbo.consumer.timeout", "dubbo.service.invoke.timeout");
111+
LEGACY_PROPERTIES.put("dubbo.consumer.retries", "dubbo.service.max.retry.providers");
112+
LEGACY_PROPERTIES.put("dubbo.consumer.check", "dubbo.service.allow.no.provider");
113+
LEGACY_PROPERTIES.put("dubbo.service.url", "dubbo.service.address");
114114

115115
// this is only for compatibility
116116
DubboShutdownHook.getDubboShutdownHook().register();

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class DubboShutdownHook extends Thread {
3434

3535
private static final Logger logger = LoggerFactory.getLogger(DubboShutdownHook.class);
3636

37-
private static final DubboShutdownHook dubboShutdownHook = new DubboShutdownHook("DubboShutdownHook");
37+
private static final DubboShutdownHook DUBBO_SHUTDOWN_HOOK = new DubboShutdownHook("DubboShutdownHook");
3838
/**
3939
* Has it already been registered or not?
4040
*/
@@ -49,7 +49,7 @@ private DubboShutdownHook(String name) {
4949
}
5050

5151
public static DubboShutdownHook getDubboShutdownHook() {
52-
return dubboShutdownHook;
52+
return DUBBO_SHUTDOWN_HOOK;
5353
}
5454

5555
@Override

0 commit comments

Comments
 (0)