Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize constant naming style #3970

Merged
merged 1 commit into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class MergerFactory {

private static final ConcurrentMap<Class<?>, Merger<?>> mergerCache =
private static final ConcurrentMap<Class<?>, Merger<?>> MERGER_CACHE =
new ConcurrentHashMap<Class<?>, Merger<?>>();

/**
Expand All @@ -46,19 +46,19 @@ public static <T> Merger<T> getMerger(Class<T> 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;
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClassLoader, Map<String, Object>> ProxyCacheMap = new WeakHashMap<ClassLoader, Map<String, Object>>();
private static final Map<ClassLoader, Map<String, Object>> PROXY_CACHE_MAP = new WeakHashMap<ClassLoader, Map<String, Object>>();

private static final Object PendingGenerationMarker = new Object();
private static final Object PENDING_GENERATION_MARKER = new Object();

protected Proxy() {
}
Expand Down Expand Up @@ -102,8 +102,8 @@ public static Proxy getProxy(ClassLoader cl, Class<?>... ics) {

// get cache by class loader.
Map<String, Object> 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;
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class InternalThreadLocal<V> {

private static final int variablesToRemoveIndex = InternalThreadLocalMap.nextVariableIndex();
private static final int VARIABLES_TO_REMOVE_INDEX = InternalThreadLocalMap.nextVariableIndex();

private final int index;

Expand All @@ -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<InternalThreadLocal<?>> variablesToRemove = (Set<InternalThreadLocal<?>>) v;
InternalThreadLocal<?>[] variablesToRemoveArray =
Expand Down Expand Up @@ -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<InternalThreadLocal<?>> variablesToRemove;
if (v == InternalThreadLocalMap.UNSET || v == null) {
variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<InternalThreadLocal<?>, Boolean>());
threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove);
threadLocalMap.setIndexedVariable(VARIABLES_TO_REMOVE_INDEX, variablesToRemove);
} else {
variablesToRemove = (Set<InternalThreadLocal<?>>) v;
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class InternalThreadLocalMap {

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

private static final AtomicInteger nextIndex = new AtomicInteger();
private static final AtomicInteger NEXT_INDEX = new AtomicInteger();

public static final Object UNSET = new Object();

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AtomicPositiveInteger extends Number {

private static final long serialVersionUID = -3038533876489105940L;

private static final AtomicIntegerFieldUpdater<AtomicPositiveInteger> indexUpdater =
private static final AtomicIntegerFieldUpdater<AtomicPositiveInteger> INDEX_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(AtomicPositiveInteger.class, "index");

@SuppressWarnings("unused")
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runnable>(100),
new NamedThreadFactory("Close-ExecutorService-Timer", true));
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> hostNameCache = new LRUCache<>(1000);
private static final Map<String, String> HOST_NAME_CACHE = new LRUCache<>(1000);
private static volatile InetAddress LOCAL_ADDRESS = null;

private static final String SPLIT_IPV4_CHARECTER = "\\.";
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ public abstract class AbstractConfig implements Serializable {
/**
* The legacy properties container
*/
private static final Map<String, String> legacyProperties = new HashMap<String, String>();
private static final Map<String, String> LEGACY_PROPERTIES = new HashMap<String, String>();

/**
* The suffix container
*/
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
*/
Expand All @@ -49,7 +49,7 @@ private DubboShutdownHook(String name) {
}

public static DubboShutdownHook getDubboShutdownHook() {
return dubboShutdownHook;
return DUBBO_SHUTDOWN_HOOK;
}

@Override
Expand Down
Loading