[ISSUE ##7131] replaced with lambda (#7136)

* can be replaced with lambda

* can be replaced with <>
This commit is contained in:
李晓双 Li Xiao Shuang 2021-10-28 10:14:08 +08:00 committed by GitHub
parent 70f7c5674e
commit 72bbd24c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -284,54 +284,51 @@ public class CacheData {
name, dataId, group, md5, listener); name, dataId, group, md5, listener);
return; return;
} }
Runnable job = new Runnable() { Runnable job = () -> {
@Override long start = System.currentTimeMillis();
public void run() { ClassLoader myClassLoader = Thread.currentThread().getContextClassLoader();
long start = System.currentTimeMillis(); ClassLoader appClassLoader = listener.getClass().getClassLoader();
ClassLoader myClassLoader = Thread.currentThread().getContextClassLoader(); try {
ClassLoader appClassLoader = listener.getClass().getClassLoader(); if (listener instanceof AbstractSharedListener) {
try { AbstractSharedListener adapter = (AbstractSharedListener) listener;
if (listener instanceof AbstractSharedListener) { adapter.fillContext(dataId, group);
AbstractSharedListener adapter = (AbstractSharedListener) listener; LOGGER.info("[{}] [notify-context] dataId={}, group={}, md5={}", name, dataId, group, md5);
adapter.fillContext(dataId, group);
LOGGER.info("[{}] [notify-context] dataId={}, group={}, md5={}", name, dataId, group, md5);
}
// Before executing the callback, set the thread classloader to the classloader of
// the specific webapp to avoid exceptions or misuses when calling the spi interface in
// the callback method (this problem occurs only in multi-application deployment).
Thread.currentThread().setContextClassLoader(appClassLoader);
ConfigResponse cr = new ConfigResponse();
cr.setDataId(dataId);
cr.setGroup(group);
cr.setContent(content);
cr.setEncryptedDataKey(encryptedDataKey);
configFilterChainManager.doFilter(null, cr);
String contentTmp = cr.getContent();
listenerWrap.inNotifying = true;
listener.receiveConfigInfo(contentTmp);
// compare lastContent and content
if (listener instanceof AbstractConfigChangeListener) {
Map data = ConfigChangeHandler.getInstance()
.parseChangeData(listenerWrap.lastContent, content, type);
ConfigChangeEvent event = new ConfigChangeEvent(data);
((AbstractConfigChangeListener) listener).receiveConfigChange(event);
listenerWrap.lastContent = content;
}
listenerWrap.lastCallMd5 = md5;
LOGGER.info("[{}] [notify-ok] dataId={}, group={}, md5={}, listener={} ,cost={} millis.", name,
dataId, group, md5, listener, (System.currentTimeMillis() - start));
} catch (NacosException ex) {
LOGGER.error("[{}] [notify-error] dataId={}, group={}, md5={}, listener={} errCode={} errMsg={}",
name, dataId, group, md5, listener, ex.getErrCode(), ex.getErrMsg());
} catch (Throwable t) {
LOGGER.error("[{}] [notify-error] dataId={}, group={}, md5={}, listener={} tx={}", name, dataId,
group, md5, listener, t.getCause());
} finally {
listenerWrap.inNotifying = false;
Thread.currentThread().setContextClassLoader(myClassLoader);
} }
// Before executing the callback, set the thread classloader to the classloader of
// the specific webapp to avoid exceptions or misuses when calling the spi interface in
// the callback method (this problem occurs only in multi-application deployment).
Thread.currentThread().setContextClassLoader(appClassLoader);
ConfigResponse cr = new ConfigResponse();
cr.setDataId(dataId);
cr.setGroup(group);
cr.setContent(content);
cr.setEncryptedDataKey(encryptedDataKey);
configFilterChainManager.doFilter(null, cr);
String contentTmp = cr.getContent();
listenerWrap.inNotifying = true;
listener.receiveConfigInfo(contentTmp);
// compare lastContent and content
if (listener instanceof AbstractConfigChangeListener) {
Map data = ConfigChangeHandler.getInstance()
.parseChangeData(listenerWrap.lastContent, content, type);
ConfigChangeEvent event = new ConfigChangeEvent(data);
((AbstractConfigChangeListener) listener).receiveConfigChange(event);
listenerWrap.lastContent = content;
}
listenerWrap.lastCallMd5 = md5;
LOGGER.info("[{}] [notify-ok] dataId={}, group={}, md5={}, listener={} ,cost={} millis.", name,
dataId, group, md5, listener, (System.currentTimeMillis() - start));
} catch (NacosException ex) {
LOGGER.error("[{}] [notify-error] dataId={}, group={}, md5={}, listener={} errCode={} errMsg={}",
name, dataId, group, md5, listener, ex.getErrCode(), ex.getErrMsg());
} catch (Throwable t) {
LOGGER.error("[{}] [notify-error] dataId={}, group={}, md5={}, listener={} tx={}", name, dataId,
group, md5, listener, t.getCause());
} finally {
listenerWrap.inNotifying = false;
Thread.currentThread().setContextClassLoader(myClassLoader);
} }
}; };
@ -396,7 +393,7 @@ public class CacheData {
this.dataId = dataId; this.dataId = dataId;
this.group = group; this.group = group;
this.tenant = TenantUtil.getUserTenantForAcm(); this.tenant = TenantUtil.getUserTenantForAcm();
listeners = new CopyOnWriteArrayList<ManagerListenerWrap>(); listeners = new CopyOnWriteArrayList<>();
this.isInitializing = true; this.isInitializing = true;
this.content = loadCacheContentFromDiskLocal(name, dataId, group, tenant); this.content = loadCacheContentFromDiskLocal(name, dataId, group, tenant);
this.md5 = getMd5String(content); this.md5 = getMd5String(content);
@ -413,7 +410,7 @@ public class CacheData {
this.dataId = dataId; this.dataId = dataId;
this.group = group; this.group = group;
this.tenant = tenant; this.tenant = tenant;
listeners = new CopyOnWriteArrayList<ManagerListenerWrap>(); listeners = new CopyOnWriteArrayList<>();
this.isInitializing = true; this.isInitializing = true;
this.content = loadCacheContentFromDiskLocal(name, dataId, group, tenant); this.content = loadCacheContentFromDiskLocal(name, dataId, group, tenant);
this.md5 = getMd5String(content); this.md5 = getMd5String(content);