diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/merger/MergerFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/merger/MergerFactory.java index 845d21a6cd0..74789bbe911 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/merger/MergerFactory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/merger/MergerFactory.java @@ -27,7 +27,7 @@ public class MergerFactory { - private static final ConcurrentMap, Merger> mergerCache = + private static final ConcurrentMap, Merger> MERGER_CACHE = new ConcurrentHashMap, Merger>(); /** @@ -46,19 +46,19 @@ public static Merger getMerger(Class returnType) { Merger result; if (returnType.isArray()) { Class type = returnType.getComponentType(); - result = mergerCache.get(type); + result = MERGER_CACHE.get(type); if (result == null) { loadMergers(); - result = mergerCache.get(type); + result = MERGER_CACHE.get(type); } if (result == null && !type.isPrimitive()) { result = ArrayMerger.INSTANCE; } } else { - result = mergerCache.get(returnType); + result = MERGER_CACHE.get(returnType); if (result == null) { loadMergers(); - result = mergerCache.get(returnType); + result = MERGER_CACHE.get(returnType); } } return result; @@ -69,7 +69,7 @@ static void loadMergers() { .getSupportedExtensions(); for (String name : names) { Merger m = ExtensionLoader.getExtensionLoader(Merger.class).getExtension(name); - mergerCache.putIfAbsent(ReflectUtils.getGenericClass(m.getClass()), m); + MERGER_CACHE.putIfAbsent(ReflectUtils.getGenericClass(m.getClass()), m); } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java index 8381bd20ca0..8486e94b34e 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java @@ -48,9 +48,9 @@ public Object invoke(Object proxy, Method method, Object[] args) { }; private static final AtomicLong PROXY_CLASS_COUNTER = new AtomicLong(0); private static final String PACKAGE_NAME = Proxy.class.getPackage().getName(); - private static final Map> ProxyCacheMap = new WeakHashMap>(); + private static final Map> PROXY_CACHE_MAP = new WeakHashMap>(); - private static final Object PendingGenerationMarker = new Object(); + private static final Object PENDING_GENERATION_MARKER = new Object(); protected Proxy() { } @@ -102,8 +102,8 @@ public static Proxy getProxy(ClassLoader cl, Class... ics) { // get cache by class loader. Map cache; - synchronized (ProxyCacheMap) { - cache = ProxyCacheMap.computeIfAbsent(cl, k -> new HashMap<>()); + synchronized (PROXY_CACHE_MAP) { + cache = PROXY_CACHE_MAP.computeIfAbsent(cl, k -> new HashMap<>()); } Proxy proxy = null; @@ -117,13 +117,13 @@ public static Proxy getProxy(ClassLoader cl, Class... ics) { } } - if (value == PendingGenerationMarker) { + if (value == PENDING_GENERATION_MARKER) { try { cache.wait(); } catch (InterruptedException e) { } } else { - cache.put(key, PendingGenerationMarker); + cache.put(key, PENDING_GENERATION_MARKER); break; } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocal.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocal.java index ac887e45305..8820f12cc2f 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocal.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocal.java @@ -33,7 +33,7 @@ */ public class InternalThreadLocal { - private static final int variablesToRemoveIndex = InternalThreadLocalMap.nextVariableIndex(); + private static final int VARIABLES_TO_REMOVE_INDEX = InternalThreadLocalMap.nextVariableIndex(); private final int index; @@ -54,7 +54,7 @@ public static void removeAll() { } try { - Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); + Object v = threadLocalMap.indexedVariable(VARIABLES_TO_REMOVE_INDEX); if (v != null && v != InternalThreadLocalMap.UNSET) { Set> variablesToRemove = (Set>) v; InternalThreadLocal[] variablesToRemoveArray = @@ -86,11 +86,11 @@ public static void destroy() { @SuppressWarnings("unchecked") private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, InternalThreadLocal variable) { - Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); + Object v = threadLocalMap.indexedVariable(VARIABLES_TO_REMOVE_INDEX); Set> variablesToRemove; if (v == InternalThreadLocalMap.UNSET || v == null) { variablesToRemove = Collections.newSetFromMap(new IdentityHashMap, Boolean>()); - threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove); + threadLocalMap.setIndexedVariable(VARIABLES_TO_REMOVE_INDEX, variablesToRemove); } else { variablesToRemove = (Set>) v; } @@ -101,7 +101,7 @@ private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap @SuppressWarnings("unchecked") private static void removeFromVariablesToRemove(InternalThreadLocalMap threadLocalMap, InternalThreadLocal variable) { - Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); + Object v = threadLocalMap.indexedVariable(VARIABLES_TO_REMOVE_INDEX); if (v == InternalThreadLocalMap.UNSET || v == null) { return; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalMap.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalMap.java index 46d9ec48054..9b38eb484fe 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalMap.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalMap.java @@ -30,7 +30,7 @@ public final class InternalThreadLocalMap { private static ThreadLocal slowThreadLocalMap = new ThreadLocal(); - private static final AtomicInteger nextIndex = new AtomicInteger(); + private static final AtomicInteger NEXT_INDEX = new AtomicInteger(); public static final Object UNSET = new Object(); @@ -64,16 +64,16 @@ public static void destroy() { } public static int nextVariableIndex() { - int index = nextIndex.getAndIncrement(); + int index = NEXT_INDEX.getAndIncrement(); if (index < 0) { - nextIndex.decrementAndGet(); + NEXT_INDEX.decrementAndGet(); throw new IllegalStateException("Too many thread-local indexed variables"); } return index; } public static int lastVariableIndex() { - return nextIndex.get() - 1; + return NEXT_INDEX.get() - 1; } private InternalThreadLocalMap() { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/AtomicPositiveInteger.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/AtomicPositiveInteger.java index 4a13c6c4acd..63b9ab8d119 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/AtomicPositiveInteger.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/AtomicPositiveInteger.java @@ -22,7 +22,7 @@ public class AtomicPositiveInteger extends Number { private static final long serialVersionUID = -3038533876489105940L; - private static final AtomicIntegerFieldUpdater indexUpdater = + private static final AtomicIntegerFieldUpdater INDEX_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AtomicPositiveInteger.class, "index"); @SuppressWarnings("unused") @@ -32,69 +32,69 @@ public AtomicPositiveInteger() { } public AtomicPositiveInteger(int initialValue) { - indexUpdater.set(this, initialValue); + INDEX_UPDATER.set(this, initialValue); } public final int getAndIncrement() { - return indexUpdater.getAndIncrement(this) & Integer.MAX_VALUE; + return INDEX_UPDATER.getAndIncrement(this) & Integer.MAX_VALUE; } public final int getAndDecrement() { - return indexUpdater.getAndDecrement(this) & Integer.MAX_VALUE; + return INDEX_UPDATER.getAndDecrement(this) & Integer.MAX_VALUE; } public final int incrementAndGet() { - return indexUpdater.incrementAndGet(this) & Integer.MAX_VALUE; + return INDEX_UPDATER.incrementAndGet(this) & Integer.MAX_VALUE; } public final int decrementAndGet() { - return indexUpdater.decrementAndGet(this) & Integer.MAX_VALUE; + return INDEX_UPDATER.decrementAndGet(this) & Integer.MAX_VALUE; } public final int get() { - return indexUpdater.get(this) & Integer.MAX_VALUE; + return INDEX_UPDATER.get(this) & Integer.MAX_VALUE; } public final void set(int newValue) { if (newValue < 0) { throw new IllegalArgumentException("new value " + newValue + " < 0"); } - indexUpdater.set(this, newValue); + INDEX_UPDATER.set(this, newValue); } public final int getAndSet(int newValue) { if (newValue < 0) { throw new IllegalArgumentException("new value " + newValue + " < 0"); } - return indexUpdater.getAndSet(this, newValue) & Integer.MAX_VALUE; + return INDEX_UPDATER.getAndSet(this, newValue) & Integer.MAX_VALUE; } public final int getAndAdd(int delta) { if (delta < 0) { throw new IllegalArgumentException("delta " + delta + " < 0"); } - return indexUpdater.getAndAdd(this, delta) & Integer.MAX_VALUE; + return INDEX_UPDATER.getAndAdd(this, delta) & Integer.MAX_VALUE; } public final int addAndGet(int delta) { if (delta < 0) { throw new IllegalArgumentException("delta " + delta + " < 0"); } - return indexUpdater.addAndGet(this, delta) & Integer.MAX_VALUE; + return INDEX_UPDATER.addAndGet(this, delta) & Integer.MAX_VALUE; } public final boolean compareAndSet(int expect, int update) { if (update < 0) { throw new IllegalArgumentException("update value " + update + " < 0"); } - return indexUpdater.compareAndSet(this, expect, update); + return INDEX_UPDATER.compareAndSet(this, expect, update); } public final boolean weakCompareAndSet(int expect, int update) { if (update < 0) { throw new IllegalArgumentException("update value " + update + " < 0"); } - return indexUpdater.weakCompareAndSet(this, expect, update); + return INDEX_UPDATER.weakCompareAndSet(this, expect, update); } @Override diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ExecutorUtil.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ExecutorUtil.java index 14408dacf64..c342ed2e713 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ExecutorUtil.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ExecutorUtil.java @@ -30,7 +30,7 @@ public class ExecutorUtil { private static final Logger logger = LoggerFactory.getLogger(ExecutorUtil.class); - private static final ThreadPoolExecutor shutdownExecutor = new ThreadPoolExecutor(0, 1, + private static final ThreadPoolExecutor SHUTDOWN_EXECUTOR = new ThreadPoolExecutor(0, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(100), new NamedThreadFactory("Close-ExecutorService-Timer", true)); @@ -102,7 +102,7 @@ public static void shutdownNow(Executor executor, final int timeout) { private static void newThreadToCloseExecutor(final ExecutorService es) { if (!isTerminated(es)) { - shutdownExecutor.execute(new Runnable() { + SHUTDOWN_EXECUTOR.execute(new Runnable() { @Override public void run() { try { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java index f03d91a0d5a..3119e5c189a 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java @@ -55,7 +55,7 @@ public class NetUtils { private static final Pattern LOCAL_IP_PATTERN = Pattern.compile("127(\\.\\d{1,3}){3}$"); private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$"); - private static final Map hostNameCache = new LRUCache<>(1000); + private static final Map HOST_NAME_CACHE = new LRUCache<>(1000); private static volatile InetAddress LOCAL_ADDRESS = null; private static final String SPLIT_IPV4_CHARECTER = "\\."; @@ -291,14 +291,14 @@ public static String getHostName(String address) { if (i > -1) { address = address.substring(0, i); } - String hostname = hostNameCache.get(address); + String hostname = HOST_NAME_CACHE.get(address); if (hostname != null && hostname.length() > 0) { return hostname; } InetAddress inetAddress = InetAddress.getByName(address); if (inetAddress != null) { hostname = inetAddress.getHostName(); - hostNameCache.put(address, hostname); + HOST_NAME_CACHE.put(address, hostname); return hostname; } } catch (Throwable e) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 30b3f50daf5..50fb55ed0ab 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -95,7 +95,7 @@ public abstract class AbstractConfig implements Serializable { /** * The legacy properties container */ - private static final Map legacyProperties = new HashMap(); + private static final Map LEGACY_PROPERTIES = new HashMap(); /** * The suffix container @@ -103,14 +103,14 @@ public abstract class AbstractConfig implements Serializable { private static final String[] SUFFIXES = new String[]{"Config", "Bean"}; static { - legacyProperties.put("dubbo.protocol.name", "dubbo.service.protocol"); - legacyProperties.put("dubbo.protocol.host", "dubbo.service.server.host"); - legacyProperties.put("dubbo.protocol.port", "dubbo.service.server.port"); - legacyProperties.put("dubbo.protocol.threads", "dubbo.service.max.thread.pool.size"); - legacyProperties.put("dubbo.consumer.timeout", "dubbo.service.invoke.timeout"); - legacyProperties.put("dubbo.consumer.retries", "dubbo.service.max.retry.providers"); - legacyProperties.put("dubbo.consumer.check", "dubbo.service.allow.no.provider"); - legacyProperties.put("dubbo.service.url", "dubbo.service.address"); + LEGACY_PROPERTIES.put("dubbo.protocol.name", "dubbo.service.protocol"); + LEGACY_PROPERTIES.put("dubbo.protocol.host", "dubbo.service.server.host"); + LEGACY_PROPERTIES.put("dubbo.protocol.port", "dubbo.service.server.port"); + LEGACY_PROPERTIES.put("dubbo.protocol.threads", "dubbo.service.max.thread.pool.size"); + LEGACY_PROPERTIES.put("dubbo.consumer.timeout", "dubbo.service.invoke.timeout"); + LEGACY_PROPERTIES.put("dubbo.consumer.retries", "dubbo.service.max.retry.providers"); + LEGACY_PROPERTIES.put("dubbo.consumer.check", "dubbo.service.allow.no.provider"); + LEGACY_PROPERTIES.put("dubbo.service.url", "dubbo.service.address"); // this is only for compatibility DubboShutdownHook.getDubboShutdownHook().register(); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java index 22d50dd05d4..47c035e293c 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java @@ -34,7 +34,7 @@ public class DubboShutdownHook extends Thread { private static final Logger logger = LoggerFactory.getLogger(DubboShutdownHook.class); - private static final DubboShutdownHook dubboShutdownHook = new DubboShutdownHook("DubboShutdownHook"); + private static final DubboShutdownHook DUBBO_SHUTDOWN_HOOK = new DubboShutdownHook("DubboShutdownHook"); /** * Has it already been registered or not? */ @@ -49,7 +49,7 @@ private DubboShutdownHook(String name) { } public static DubboShutdownHook getDubboShutdownHook() { - return dubboShutdownHook; + return DUBBO_SHUTDOWN_HOOK; } @Override diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index e1df3193c13..4c379375b6e 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -80,19 +80,19 @@ public class ReferenceConfig extends AbstractReferenceConfig { * Actually,when the {@link ExtensionLoader} init the {@link Protocol} instants,it will automatically wraps two * layers, and eventually will get a ProtocolFilterWrapper or ProtocolListenerWrapper */ - private static final Protocol refprotocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); + private static final Protocol REF_PROTOCOL = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); /** * The {@link Cluster}'s implementation with adaptive functionality, and actually it will get a {@link Cluster}'s * specific implementation who is wrapped with MockClusterInvoker */ - private static final Cluster cluster = ExtensionLoader.getExtensionLoader(Cluster.class).getAdaptiveExtension(); + private static final Cluster CLUSTER = ExtensionLoader.getExtensionLoader(Cluster.class).getAdaptiveExtension(); /** * A {@link ProxyFactory} implementation that will generate a reference service's proxy,the JavassistProxyFactory is * its default implementation */ - private static final ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); + private static final ProxyFactory PROXY_FACTORY = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); /** * The url of the reference service @@ -333,7 +333,7 @@ private ConsumerModel buildConsumerModel(String serviceKey, Map private T createProxy(Map map) { if (shouldJvmRefer(map)) { URL url = new URL(Constants.LOCAL_PROTOCOL, Constants.LOCALHOST_VALUE, 0, interfaceClass.getName()).addParameters(map); - invoker = refprotocol.refer(interfaceClass, url); + invoker = REF_PROTOCOL.refer(interfaceClass, url); if (logger.isInfoEnabled()) { logger.info("Using injvm service " + interfaceClass.getName()); } @@ -371,23 +371,23 @@ private T createProxy(Map map) { } if (urls.size() == 1) { - invoker = refprotocol.refer(interfaceClass, urls.get(0)); + invoker = REF_PROTOCOL.refer(interfaceClass, urls.get(0)); } else { List> invokers = new ArrayList>(); URL registryURL = null; for (URL url : urls) { - invokers.add(refprotocol.refer(interfaceClass, url)); + invokers.add(REF_PROTOCOL.refer(interfaceClass, url)); if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) { registryURL = url; // use last registry url } } if (registryURL != null) { // registry url is available - // use RegistryAwareCluster only when register's cluster is available + // use RegistryAwareCluster only when register's CLUSTER is available URL u = registryURL.addParameter(Constants.CLUSTER_KEY, RegistryAwareCluster.NAME); // The invoker wrap relation would be: RegistryAwareClusterInvoker(StaticDirectory) -> FailoverClusterInvoker(RegistryDirectory, will execute route) -> Invoker - invoker = cluster.join(new StaticDirectory(u, invokers)); + invoker = CLUSTER.join(new StaticDirectory(u, invokers)); } else { // not a registry url, must be direct invoke. - invoker = cluster.join(new StaticDirectory(invokers)); + invoker = CLUSTER.join(new StaticDirectory(invokers)); } } } @@ -410,7 +410,7 @@ private T createProxy(Map map) { metadataReportService.publishConsumer(consumerURL); } // create service proxy - return (T) proxyFactory.getProxy(invoker); + return (T) PROXY_FACTORY.getProxy(invoker); } /** diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java index ae16ef961a2..808fd9cdc57 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java @@ -73,7 +73,7 @@ */ public class ConfigManager { private static final Logger logger = LoggerFactory.getLogger(ConfigManager.class); - private static final ConfigManager configManager = new ConfigManager(); + private static final ConfigManager CONFIG_MANAGER = new ConfigManager(); private ApplicationConfig application; private MonitorConfig monitor; @@ -86,7 +86,7 @@ public class ConfigManager { private Map consumers = new ConcurrentHashMap<>(); public static ConfigManager getInstance() { - return configManager; + return CONFIG_MANAGER; } private ConfigManager() { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ReferenceConfigCache.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ReferenceConfigCache.java index 09f12dadeca..0891a767aba 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ReferenceConfigCache.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ReferenceConfigCache.java @@ -59,7 +59,7 @@ public class ReferenceConfigCache { } return ret.toString(); }; - static final ConcurrentMap cacheHolder = new ConcurrentHashMap(); + static final ConcurrentMap CACHE_HOLDER = new ConcurrentHashMap(); private final String name; private final KeyGenerator generator; ConcurrentMap> cache = new ConcurrentHashMap>(); @@ -90,12 +90,12 @@ public static ReferenceConfigCache getCache(String name) { * Create cache if not existed yet. */ public static ReferenceConfigCache getCache(String name, KeyGenerator keyGenerator) { - ReferenceConfigCache cache = cacheHolder.get(name); + ReferenceConfigCache cache = CACHE_HOLDER.get(name); if (cache != null) { return cache; } - cacheHolder.putIfAbsent(name, new ReferenceConfigCache(name, keyGenerator)); - return cacheHolder.get(name); + CACHE_HOLDER.putIfAbsent(name, new ReferenceConfigCache(name, keyGenerator)); + return CACHE_HOLDER.get(name); } @SuppressWarnings("unchecked") diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceConfigCacheTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceConfigCacheTest.java index 2af6da720ec..656d2af382d 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceConfigCacheTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceConfigCacheTest.java @@ -27,7 +27,7 @@ public class ReferenceConfigCacheTest { @BeforeEach public void setUp() throws Exception { MockReferenceConfig.setCounter(0); - ReferenceConfigCache.cacheHolder.clear(); + ReferenceConfigCache.CACHE_HOLDER.clear(); } @Test diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java index 6aa80e860a3..d61db85fd4d 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java @@ -40,29 +40,29 @@ public class SpringExtensionFactory implements ExtensionFactory { private static final Logger logger = LoggerFactory.getLogger(SpringExtensionFactory.class); - private static final Set contexts = new ConcurrentHashSet(); - private static final ApplicationListener shutdownHookListener = new ShutdownHookListener(); + private static final Set CONTEXTS = new ConcurrentHashSet(); + private static final ApplicationListener SHUTDOWN_HOOK_LISTENER = new ShutdownHookListener(); public static void addApplicationContext(ApplicationContext context) { - contexts.add(context); + CONTEXTS.add(context); if (context instanceof ConfigurableApplicationContext) { ((ConfigurableApplicationContext) context).registerShutdownHook(); DubboShutdownHook.getDubboShutdownHook().unregister(); } - BeanFactoryUtils.addApplicationListener(context, shutdownHookListener); + BeanFactoryUtils.addApplicationListener(context, SHUTDOWN_HOOK_LISTENER); } public static void removeApplicationContext(ApplicationContext context) { - contexts.remove(context); + CONTEXTS.remove(context); } public static Set getContexts() { - return contexts; + return CONTEXTS; } // currently for test purpose public static void clearContexts() { - contexts.clear(); + CONTEXTS.clear(); } @Override @@ -74,7 +74,7 @@ public T getExtension(Class type, String name) { return null; } - for (ApplicationContext context : contexts) { + for (ApplicationContext context : CONTEXTS) { if (context.containsBean(name)) { Object bean = context.getBean(name); if (type.isInstance(bean)) { @@ -89,7 +89,7 @@ public T getExtension(Class type, String name) { return null; } - for (ApplicationContext context : contexts) { + for (ApplicationContext context : CONTEXTS) { try { return context.getBean(type); } catch (NoUniqueBeanDefinitionException multiBeanExe) { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index 2593b2e081c..54bb0068a3e 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -75,9 +75,9 @@ public class RegistryDirectory extends AbstractDirectory implements Notify private static final Logger logger = LoggerFactory.getLogger(RegistryDirectory.class); - private static final Cluster cluster = ExtensionLoader.getExtensionLoader(Cluster.class).getAdaptiveExtension(); + private static final Cluster CLUSTER = ExtensionLoader.getExtensionLoader(Cluster.class).getAdaptiveExtension(); - private static final RouterFactory routerFactory = ExtensionLoader.getExtensionLoader(RouterFactory.class) + private static final RouterFactory ROUTER_FACTORY = ExtensionLoader.getExtensionLoader(RouterFactory.class) .getAdaptiveExtension(); private final String serviceKey; // Initialization at construction time, assertion not null @@ -108,7 +108,7 @@ public class RegistryDirectory extends AbstractDirectory implements Notify // Set cache invokeUrls to invokers mapping. private volatile Set cachedInvokerUrls; // The initial value is null and the midway may be assigned to null, please use the local variable reference - private static final ConsumerConfigurationListener consumerConfigurationListener = new ConsumerConfigurationListener(); + private static final ConsumerConfigurationListener CONSUMER_CONFIGURATION_LISTENER = new ConsumerConfigurationListener(); private ReferenceConfigurationListener serviceConfigurationListener; @@ -152,7 +152,7 @@ public void setRegistry(Registry registry) { public void subscribe(URL url) { setConsumerUrl(url); - consumerConfigurationListener.addNotifyListener(this); + CONSUMER_CONFIGURATION_LISTENER.addNotifyListener(this); serviceConfigurationListener = new ReferenceConfigurationListener(this, url); registry.subscribe(url, this); } @@ -178,7 +178,7 @@ public void destroy() { registry.unsubscribe(getConsumerUrl(), this); } DynamicConfiguration.getDynamicConfiguration() - .removeListener(ApplicationModel.getApplication(), consumerConfigurationListener); + .removeListener(ApplicationModel.getApplication(), CONSUMER_CONFIGURATION_LISTENER); } catch (Throwable t) { logger.warn("unexpected error when unsubscribe service " + serviceKey + "from registry" + registry.getUrl(), t); } @@ -308,7 +308,7 @@ private List> toMergeInvokerList(List> invokers) { for (List> groupList : groupMap.values()) { StaticDirectory staticDirectory = new StaticDirectory<>(groupList); staticDirectory.buildRouterChain(); - mergedInvokers.add(cluster.join(staticDirectory)); + mergedInvokers.add(CLUSTER.join(staticDirectory)); } } else { mergedInvokers = invokers; @@ -336,7 +336,7 @@ private Optional> toRouters(List urls) { url = url.setProtocol(routerType); } try { - Router router = routerFactory.getRouter(url); + Router router = ROUTER_FACTORY.getRouter(url); if (!routers.contains(router)) { routers.add(router); } @@ -461,7 +461,7 @@ private URL overrideWithConfigurator(URL providerUrl) { providerUrl = overrideWithConfigurators(this.configurators, providerUrl); // override url with configurator from configurator from "app-name.configurators" - providerUrl = overrideWithConfigurators(consumerConfigurationListener.getConfigurators(), providerUrl); + providerUrl = overrideWithConfigurators(CONSUMER_CONFIGURATION_LISTENER.getConfigurators(), providerUrl); // override url with configurator from configurators from "service-name.configurators" if (serviceConfigurationListener != null) { @@ -655,7 +655,7 @@ private void overrideDirectoryUrl() { this.overrideDirectoryUrl = directoryUrl; List localConfigurators = this.configurators; // local reference doOverrideUrl(localConfigurators); - List localAppDynamicConfigurators = consumerConfigurationListener.getConfigurators(); // local reference + List localAppDynamicConfigurators = CONSUMER_CONFIGURATION_LISTENER.getConfigurators(); // local reference doOverrideUrl(localAppDynamicConfigurators); if (serviceConfigurationListener != null) { List localDynamicConfigurators = serviceConfigurationListener.getConfigurators(); // local reference diff --git a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/servlet/ServletManager.java b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/servlet/ServletManager.java index 0b227704192..243c5541df0 100644 --- a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/servlet/ServletManager.java +++ b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/servlet/ServletManager.java @@ -28,12 +28,12 @@ public class ServletManager { public static final int EXTERNAL_SERVER_PORT = -1234; - private static final ServletManager instance = new ServletManager(); + private static final ServletManager INSTANCE = new ServletManager(); private final Map contextMap = new ConcurrentHashMap(); public static ServletManager getInstance() { - return instance; + return INSTANCE; } public void addServletContext(int port, ServletContext servletContext) { diff --git a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaClient.java b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaClient.java index 23296f71ce0..b5e9c8426d1 100644 --- a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaClient.java +++ b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaClient.java @@ -51,7 +51,7 @@ public class MinaClient extends AbstractClient { private static final Logger logger = LoggerFactory.getLogger(MinaClient.class); - private static final Map connectors = new ConcurrentHashMap(); + private static final Map CONNECTORS = new ConcurrentHashMap(); private String connectorKey; @@ -66,7 +66,7 @@ public MinaClient(final URL url, final ChannelHandler handler) throws RemotingEx @Override protected void doOpen() throws Throwable { connectorKey = getUrl().toFullString(); - SocketConnector c = connectors.get(connectorKey); + SocketConnector c = CONNECTORS.get(connectorKey); if (c != null) { connector = c; } else { @@ -82,7 +82,7 @@ protected void doOpen() throws Throwable { cfg.setConnectTimeout(timeout < 1000 ? 1 : timeout / 1000); // set codec. connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this))); - connectors.put(connectorKey, connector); + CONNECTORS.put(connectorKey, connector); } } diff --git a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java index 9a0e107c84f..f5e02131a36 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java @@ -38,7 +38,7 @@ final class NettyChannel extends AbstractChannel { private static final Logger logger = LoggerFactory.getLogger(NettyChannel.class); - private static final ConcurrentMap channelMap = new ConcurrentHashMap(); + private static final ConcurrentMap CHANNEL_MAP = new ConcurrentHashMap(); private final org.jboss.netty.channel.Channel channel; @@ -56,11 +56,11 @@ static NettyChannel getOrAddChannel(org.jboss.netty.channel.Channel ch, URL url, if (ch == null) { return null; } - NettyChannel ret = channelMap.get(ch); + NettyChannel ret = CHANNEL_MAP.get(ch); if (ret == null) { NettyChannel nc = new NettyChannel(ch, url, handler); if (ch.isConnected()) { - ret = channelMap.putIfAbsent(ch, nc); + ret = CHANNEL_MAP.putIfAbsent(ch, nc); } if (ret == null) { ret = nc; @@ -71,7 +71,7 @@ static NettyChannel getOrAddChannel(org.jboss.netty.channel.Channel ch, URL url, static void removeChannelIfDisconnected(org.jboss.netty.channel.Channel ch) { if (ch != null && !ch.isConnected()) { - channelMap.remove(ch); + CHANNEL_MAP.remove(ch); } } diff --git a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyClient.java b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyClient.java index 434fd2a03b0..e9912985ebc 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyClient.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyClient.java @@ -48,7 +48,7 @@ public class NettyClient extends AbstractClient { // ChannelFactory's closure has a DirectMemory leak, using static to avoid // https://issues.jboss.org/browse/NETTY-424 - private static final ChannelFactory channelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientBoss", true)), + private static final ChannelFactory CHANNEL_FACTORY = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientBoss", true)), Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientWorker", true)), Constants.DEFAULT_IO_THREADS); private ClientBootstrap bootstrap; @@ -62,7 +62,7 @@ public NettyClient(final URL url, final ChannelHandler handler) throws RemotingE @Override protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); - bootstrap = new ClientBootstrap(channelFactory); + bootstrap = new ClientBootstrap(CHANNEL_FACTORY); // config // @see org.jboss.netty.channel.socket.SocketChannelConfig bootstrap.setOption("keepAlive", true); diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java index db69a29f24c..21bf2419487 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java @@ -39,7 +39,7 @@ final class NettyChannel extends AbstractChannel { private static final Logger logger = LoggerFactory.getLogger(NettyChannel.class); - private static final ConcurrentMap channelMap = new ConcurrentHashMap(); + private static final ConcurrentMap CHANNEL_MAP = new ConcurrentHashMap(); private final Channel channel; @@ -57,11 +57,11 @@ static NettyChannel getOrAddChannel(Channel ch, URL url, ChannelHandler handler) if (ch == null) { return null; } - NettyChannel ret = channelMap.get(ch); + NettyChannel ret = CHANNEL_MAP.get(ch); if (ret == null) { NettyChannel nettyChannel = new NettyChannel(ch, url, handler); if (ch.isActive()) { - ret = channelMap.putIfAbsent(ch, nettyChannel); + ret = CHANNEL_MAP.putIfAbsent(ch, nettyChannel); } if (ret == null) { ret = nettyChannel; @@ -72,7 +72,7 @@ static NettyChannel getOrAddChannel(Channel ch, URL url, ChannelHandler handler) static void removeChannelIfDisconnected(Channel ch) { if (ch != null && !ch.isActive()) { - channelMap.remove(ch); + CHANNEL_MAP.remove(ch); } } diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java index 4bf7b6d3bf5..a97eb7e5f22 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java @@ -48,7 +48,7 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient { - static final Charset charset = Charset.forName("UTF-8"); + static final Charset CHARSET = Charset.forName("UTF-8"); private final CuratorFramework client; private Map treeCacheMap = new ConcurrentHashMap<>(); @@ -106,7 +106,7 @@ public void createEphemeral(String path) { @Override protected void createPersistent(String path, String data) { - byte[] dataBytes = data.getBytes(charset); + byte[] dataBytes = data.getBytes(CHARSET); try { client.create().forPath(path, dataBytes); } catch (NodeExistsException e) { @@ -122,7 +122,7 @@ protected void createPersistent(String path, String data) { @Override protected void createEphemeral(String path, String data) { - byte[] dataBytes = data.getBytes(charset); + byte[] dataBytes = data.getBytes(CHARSET); try { client.create().withMode(CreateMode.EPHEMERAL).forPath(path, dataBytes); } catch (NodeExistsException e) { @@ -177,7 +177,7 @@ public boolean isConnected() { public String doGetContent(String path) { try { byte[] dataBytes = client.getData().forPath(path); - return (dataBytes == null || dataBytes.length == 0) ? null : new String(dataBytes, charset); + return (dataBytes == null || dataBytes.length == 0) ? null : new String(dataBytes, CHARSET); } catch (NoNodeException e) { // ignore NoNode Exception. } catch (Exception e) { @@ -295,12 +295,12 @@ public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exc case NODE_ADDED: eventType = EventType.NodeCreated; path = event.getData().getPath(); - content = new String(event.getData().getData(), charset); + content = new String(event.getData().getData(), CHARSET); break; case NODE_UPDATED: eventType = EventType.NodeDataChanged; path = event.getData().getPath(); - content = new String(event.getData().getData(), charset); + content = new String(event.getData().getData(), CHARSET); break; case NODE_REMOVED: path = event.getData().getPath(); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java index f1bffc2a30b..23fa1ea52cb 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java @@ -75,16 +75,16 @@ public class AccessLogFilter implements Filter { // It's safe to declare it as singleton since it runs on single thread only private static final DateFormat FILE_NAME_FORMATTER = new SimpleDateFormat(FILE_DATE_FORMAT); - private static final Map> logEntries = new ConcurrentHashMap>(); + private static final Map> LOG_ENTRIES = new ConcurrentHashMap>(); - private static final ScheduledExecutorService logScheduled = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Dubbo-Access-Log", true)); + private static final ScheduledExecutorService LOG_SCHEDULED = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Dubbo-Access-Log", true)); /** * Default constructor initialize demon thread for writing into access log file with names with access log key * defined in url accesslog */ public AccessLogFilter() { - logScheduled.scheduleWithFixedDelay(this::writeLogToFile, LOG_OUTPUT_INTERVAL, LOG_OUTPUT_INTERVAL, TimeUnit.MILLISECONDS); + LOG_SCHEDULED.scheduleWithFixedDelay(this::writeLogToFile, LOG_OUTPUT_INTERVAL, LOG_OUTPUT_INTERVAL, TimeUnit.MILLISECONDS); } /** @@ -110,7 +110,7 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { } private void log(String accessLog, AccessLogData accessLogData) { - Set logSet = logEntries.computeIfAbsent(accessLog, k -> new ConcurrentHashSet<>()); + Set logSet = LOG_ENTRIES.computeIfAbsent(accessLog, k -> new ConcurrentHashSet<>()); if (logSet.size() < LOG_MAX_BUFFER) { logSet.add(accessLogData); @@ -121,8 +121,8 @@ private void log(String accessLog, AccessLogData accessLogData) { } private void writeLogToFile() { - if (!logEntries.isEmpty()) { - for (Map.Entry> entry : logEntries.entrySet()) { + if (!LOG_ENTRIES.isEmpty()) { + for (Map.Entry> entry : LOG_ENTRIES.entrySet()) { try { String accessLog = entry.getKey(); Set logSet = entry.getValue(); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java index cfad21c02ba..33dcc908e1b 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java @@ -39,38 +39,38 @@ public class ApplicationModel { /** * full qualified class name -> provided service */ - private static final ConcurrentMap providedServices = new ConcurrentHashMap<>(); + private static final ConcurrentMap PROVIDED_SERVICES = new ConcurrentHashMap<>(); /** * full qualified class name -> subscribe service */ - private static final ConcurrentMap consumedServices = new ConcurrentHashMap<>(); + private static final ConcurrentMap CONSUMED_SERVICES = new ConcurrentHashMap<>(); private static String application; public static Collection allConsumerModels() { - return consumedServices.values(); + return CONSUMED_SERVICES.values(); } public static Collection allProviderModels() { - return providedServices.values(); + return PROVIDED_SERVICES.values(); } public static ProviderModel getProviderModel(String serviceName) { - return providedServices.get(serviceName); + return PROVIDED_SERVICES.get(serviceName); } public static ConsumerModel getConsumerModel(String serviceName) { - return consumedServices.get(serviceName); + return CONSUMED_SERVICES.get(serviceName); } public static void initConsumerModel(String serviceName, ConsumerModel consumerModel) { - if (consumedServices.putIfAbsent(serviceName, consumerModel) != null) { + if (CONSUMED_SERVICES.putIfAbsent(serviceName, consumerModel) != null) { LOGGER.warn("Already register the same consumer:" + serviceName); } } public static void initProviderModel(String serviceName, ProviderModel providerModel) { - if (providedServices.putIfAbsent(serviceName, providerModel) != null) { + if (PROVIDED_SERVICES.putIfAbsent(serviceName, providerModel) != null) { LOGGER.warn("Already register the same:" + serviceName); } } @@ -87,7 +87,7 @@ public static void setApplication(String application) { * For unit test */ public static void reset() { - providedServices.clear(); - consumedServices.clear(); + PROVIDED_SERVICES.clear(); + CONSUMED_SERVICES.clear(); } } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java index 4d2f3c6756b..5eb4dd9205f 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java @@ -43,7 +43,7 @@ class CallbackServiceCodec { private static final Logger logger = LoggerFactory.getLogger(CallbackServiceCodec.class); - private static final ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); + private static final ProxyFactory PROXY_FACTORY = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); private static final DubboProtocol protocol = DubboProtocol.getDubboProtocol(); private static final byte CALLBACK_NONE = 0x0; private static final byte CALLBACK_CREATE = 0x1; @@ -105,7 +105,7 @@ private static String exportOrUnexportCallbackService(Channel channel, URL url, // one channel can have multiple callback instances, no need to re-export for different instance. if (!channel.hasAttribute(cacheKey)) { if (!isInstancesOverLimit(channel, url, clazz.getName(), instid, false)) { - Invoker invoker = proxyFactory.getInvoker(inst, clazz, exportUrl); + Invoker invoker = PROXY_FACTORY.getInvoker(inst, clazz, exportUrl); // should destroy resource? Exporter exporter = protocol.export(invoker); // this is used for tracing if instid has published service or not. @@ -144,7 +144,7 @@ private static Object referOrDestroyCallbackService(Channel channel, URL url, Cl if (!isInstancesOverLimit(channel, referurl, clazz.getName(), instid, true)) { @SuppressWarnings("rawtypes") Invoker invoker = new ChannelWrappedInvoker(clazz, channel, referurl, String.valueOf(instid)); - proxy = proxyFactory.getProxy(invoker); + proxy = PROXY_FACTORY.getProxy(invoker); channel.setAttribute(proxyCacheKey, proxy); channel.setAttribute(invokerCacheKey, invoker); increaseInstanceCount(channel, countkey); diff --git a/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpRemoteInvocation.java b/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpRemoteInvocation.java index c2cf48ac5f0..b4617396c21 100644 --- a/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpRemoteInvocation.java +++ b/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpRemoteInvocation.java @@ -31,18 +31,18 @@ public class HttpRemoteInvocation extends RemoteInvocation { private static final long serialVersionUID = 1L; - private static final String dubboAttachmentsAttrName = "dubbo.attachments"; + private static final String DUBBO_ATTACHMENTS_ATTR_NAME = "dubbo.attachments"; public HttpRemoteInvocation(MethodInvocation methodInvocation) { super(methodInvocation); - addAttribute(dubboAttachmentsAttrName, new HashMap(RpcContext.getContext().getAttachments())); + addAttribute(DUBBO_ATTACHMENTS_ATTR_NAME, new HashMap(RpcContext.getContext().getAttachments())); } @Override public Object invoke(Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { RpcContext context = RpcContext.getContext(); - context.setAttachments((Map) getAttribute(dubboAttachmentsAttrName)); + context.setAttachments((Map) getAttribute(DUBBO_ATTACHMENTS_ATTR_NAME)); String generic = (String) getAttribute(Constants.GENERIC_KEY); if (StringUtils.isNotEmpty(generic)) { diff --git a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java index 564505a5837..b40996c8124 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java +++ b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java @@ -84,10 +84,10 @@ public class ThriftCodec implements Codec2 { public static final String PARAMETER_CLASS_NAME_GENERATOR = "class.name.generator"; public static final byte VERSION = (byte) 1; public static final short MAGIC = (short) 0xdabc; - static final ConcurrentMap cachedRequest = + static final ConcurrentMap CACHED_REQUEST = new ConcurrentHashMap(); private static final AtomicInteger THRIFT_SEQ_ID = new AtomicInteger(0); - private static final ConcurrentMap> cachedClass = + private static final ConcurrentMap> CACHED_CLASS = new ConcurrentHashMap>(); private static int nextSeqId() { @@ -193,14 +193,14 @@ private Object decode(TProtocol protocol) "The specified interface name incorrect."); } - Class clazz = cachedClass.get(argsClassName); + Class clazz = CACHED_CLASS.get(argsClassName); if (clazz == null) { try { clazz = ClassUtils.forNameWithThreadContextClassLoader(argsClassName); - cachedClass.putIfAbsent(argsClassName, clazz); + CACHED_CLASS.putIfAbsent(argsClassName, clazz); } catch (ClassNotFoundException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); @@ -268,7 +268,7 @@ private Object decode(TProtocol protocol) Request request = new Request(id); request.setData(result); - cachedRequest.putIfAbsent(id, + CACHED_REQUEST.putIfAbsent(id, RequestData.create(message.seqid, serviceName, message.name)); return request; @@ -306,7 +306,7 @@ private Object decode(TProtocol protocol) + serviceName + ", the service name you specified may not generated by thrift idl compiler"); } - Class clazz = cachedClass.get(resultClassName); + Class clazz = CACHED_CLASS.get(resultClassName); if (clazz == null) { @@ -314,7 +314,7 @@ private Object decode(TProtocol protocol) clazz = ClassUtils.forNameWithThreadContextClassLoader(resultClassName); - cachedClass.putIfAbsent(resultClassName, clazz); + CACHED_CLASS.putIfAbsent(resultClassName, clazz); } catch (ClassNotFoundException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); @@ -422,7 +422,7 @@ private void encodeRequest(Channel channel, ChannelBuffer buffer, Request reques "Could not encode request, the specified interface may be incorrect."); } - Class clazz = cachedClass.get(methodArgs); + Class clazz = CACHED_CLASS.get(methodArgs); if (clazz == null) { @@ -430,7 +430,7 @@ private void encodeRequest(Channel channel, ChannelBuffer buffer, Request reques clazz = ClassUtils.forNameWithThreadContextClassLoader(methodArgs); - cachedClass.putIfAbsent(methodArgs, clazz); + CACHED_CLASS.putIfAbsent(methodArgs, clazz); } catch (ClassNotFoundException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); @@ -538,7 +538,7 @@ private void encodeResponse(Channel channel, ChannelBuffer buffer, Response resp RpcResult result = (RpcResult) response.getResult(); - RequestData rd = cachedRequest.get(response.getId()); + RequestData rd = CACHED_REQUEST.get(response.getId()); String resultClassName = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class).getExtension( channel.getUrl().getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME)) @@ -549,13 +549,13 @@ private void encodeResponse(Channel channel, ChannelBuffer buffer, Response resp "Could not encode response, the specified interface may be incorrect."); } - Class clazz = cachedClass.get(resultClassName); + Class clazz = CACHED_CLASS.get(resultClassName); if (clazz == null) { try { clazz = ClassUtils.forNameWithThreadContextClassLoader(resultClassName); - cachedClass.putIfAbsent(resultClassName, clazz); + CACHED_CLASS.putIfAbsent(resultClassName, clazz); } catch (ClassNotFoundException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } diff --git a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftType.java b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftType.java index 3d8d3b387cf..85ede895488 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftType.java +++ b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftType.java @@ -26,7 +26,7 @@ public enum ThriftType { BOOL, BYTE, I16, I32, I64, DOUBLE, STRING; - private static final Map, ThriftType> types = + private static final Map, ThriftType> TYPES = new HashMap, ThriftType>(); static { @@ -39,13 +39,13 @@ public enum ThriftType { public static ThriftType get(Class key) { if (key != null) { - return types.get(key); + return TYPES.get(key); } throw new NullPointerException("key == null"); } private static void put(Class key, ThriftType value) { - types.put(key, value); + TYPES.put(key, value); } } diff --git a/dubbo-rpc/dubbo-rpc-thrift/src/test/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodecTest.java b/dubbo-rpc/dubbo-rpc-thrift/src/test/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodecTest.java index c2277f7fba5..2b0b1db9bfb 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/src/test/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodecTest.java +++ b/dubbo-rpc/dubbo-rpc-thrift/src/test/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodecTest.java @@ -286,7 +286,7 @@ public void testEncodeReplyResponse() throws Exception { ThriftCodec.RequestData rd = ThriftCodec.RequestData.create( ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString"); - ThriftCodec.cachedRequest.putIfAbsent(request.getId(), rd); + ThriftCodec.CACHED_REQUEST.putIfAbsent(request.getId(), rd); codec.encode(channel, bos, response); byte[] buf = new byte[bos.writerIndex() - 4]; @@ -345,7 +345,7 @@ public void testEncodeExceptionResponse() throws Exception { ThriftCodec.RequestData rd = ThriftCodec.RequestData.create( ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString"); - ThriftCodec.cachedRequest.put(request.getId(), rd); + ThriftCodec.CACHED_REQUEST.put(request.getId(), rd); codec.encode(channel, bos, response); byte[] buf = new byte[bos.writerIndex() - 4]; diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistry.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistry.java index 22de45d5c74..1a8fb69dbd6 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistry.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistry.java @@ -28,7 +28,7 @@ public abstract class SerializableClassRegistry { - private static final Map registrations = new LinkedHashMap<>(); + private static final Map REGISTRATIONS = new LinkedHashMap<>(); /** * only supposed to be called at startup time @@ -49,7 +49,7 @@ public static void registerClass(Class clazz, Serializer serializer) { if (clazz == null) { throw new IllegalArgumentException("Class registered to kryo cannot be null!"); } - registrations.put(clazz, serializer); + REGISTRATIONS.put(clazz, serializer); } /** @@ -58,6 +58,6 @@ public static void registerClass(Class clazz, Serializer serializer) { * @return class serializer * */ public static Map getRegisteredClasses() { - return registrations; + return REGISTRATIONS; } }