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

format and optimize code #496

Merged
merged 7 commits into from
Oct 26, 2024
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 @@ -52,6 +52,8 @@ private DynamicTpConst() { }

public static final String EXECUTORS_CONFIG_PREFIX = MAIN_PROPERTIES_PREFIX + ".executors[";

public static final String APP_NAME_KEY = "APP.NAME";

/**
* Dtp executor properties const.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static JreEnum getJre() {
int majorVersion = (int) MethodUtils.invokeMethod(javaRunTimeVersion, "major");
return JreEnum.valueOf("JAVA_" + majorVersion);
} catch (Exception e) {
log.debug("can't determine current JRE version", e);
log.warn("can't determine current JRE version", e);
}
return JAVA_8;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
public class AlarmCheckEvent extends DtpEvent {

public AlarmCheckEvent(Object source, DtpProperties dtpProperties) {
super(source, dtpProperties); // 调用父类的构造方法
super(source, dtpProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
* EventObject related
*
* @author vzer200
* @since 1.1.8
* @since 1.2.0
*/
public class CustomContextRefreshedEvent extends EventObject {

public CustomContextRefreshedEvent(Object source) {
super(source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* DtpEvent related
*
* @author vzer200
* @since 1.1.8
* @since 1.2.0
*/
@Getter
public abstract class DtpEvent extends EventObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/


package org.dromara.dynamictp.common.manager;

import java.util.Map;
Expand All @@ -26,7 +25,7 @@
* and retrieve environment properties and profiles.
*
* @author vzer200
* @since 1.1.8
* @since 1.2.0
*/
public interface ContextManager {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
* limitations under the License.
*/


package org.dromara.dynamictp.common.manager;

import org.dromara.dynamictp.common.util.ExtensionServiceLoader;

import java.util.Map;


/**
* Helper class for accessing ContextManager and publishing events.
*
* @author vzer200
* @since 1.1.8
* @since 1.2.0
*/
public class ContextManagerHelper {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/


package org.dromara.dynamictp.common.manager;

import com.google.common.eventbus.EventBus;
Expand All @@ -24,18 +23,19 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;


/**
* Manages event registration and posting using EventBus.
*
* @author vzer200
* @since 1.1.8
* @since 1.2.0
*/
@Slf4j
public class EventBusManager {

private static final EventBus EVENT_BUS = new EventBus();

private static final Set<Object> REGISTERED_OBJECTS = ConcurrentHashMap.newKeySet();

private EventBusManager() { }

public static void register(Object object) {
Expand Down Expand Up @@ -67,7 +67,7 @@ public static void destroy() {
for (Object object : REGISTERED_OBJECTS) {
try {
EVENT_BUS.unregister(object);
} catch (Throwable e) {
} catch (Exception e) {
log.warn("Attempted to unregister an object that was not registered: {}", object, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.dromara.dynamictp.common.util;

import lombok.experimental.UtilityClass;
import net.sf.cglib.beans.BeanCopier;

import java.util.Map;
Expand All @@ -28,7 +29,9 @@
* @author vzer200
* @since 1.1.8
*/
public class BeanCopierUtils {
@UtilityClass
public class BeanCopierUtil {

private static final Map<String, BeanCopier> BEAN_COPIER_CACHE = new ConcurrentHashMap<>();

public static BeanCopier getBeanCopier(Class<?> sourceClass, Class<?> targetClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.common.base.Preconditions;
import org.apache.commons.collections4.CollectionUtils;


import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* as well as handling auto startup and shutdown phases.
*
* @author vzer200
* @since 1.1.8
* @since 1.2.0
*/
public interface LifeCycleManagement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import lombok.extern.slf4j.Slf4j;
import org.dromara.dynamictp.common.em.CollectorTypeEnum;
import org.dromara.dynamictp.common.entity.ThreadPoolStats;
import org.dromara.dynamictp.common.util.BeanCopierUtils;
import org.dromara.dynamictp.common.util.BeanCopierUtil;
import org.dromara.dynamictp.common.util.CommonUtil;

import java.util.ArrayList;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void collect(ThreadPoolStats threadPoolStats) {
if (Objects.isNull(oldStats)) {
GAUGE_CACHE.put(threadPoolStats.getPoolName(), threadPoolStats);
} else {
BeanCopierUtils.copyProperties(threadPoolStats, oldStats);
BeanCopierUtil.copyProperties(threadPoolStats, oldStats);
}
gauge(GAUGE_CACHE.get(threadPoolStats.getPoolName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static InvokerChain<BaseNotifyCtx> getAlarmInvokerChain() {
}

public static InvokerChain<BaseNotifyCtx> getCommonInvokerChain() {
val filters = ContextManagerHelper.getBeansOfType(NotifyFilter.class);
val filters = ContextManagerHelper.getBeansOfType(NotifyFilter.class);
Collection<NotifyFilter> noticeFilters = Lists.newArrayList(filters.values());
noticeFilters.add(new NoticeBaseFilter());
noticeFilters = noticeFilters.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lombok.Data;
import org.dromara.dynamictp.common.em.NotifyItemEnum;
import org.dromara.dynamictp.common.entity.NotifyItem;
import org.dromara.dynamictp.common.util.BeanCopierUtils;
import org.dromara.dynamictp.common.util.BeanCopierUtil;
import org.dromara.dynamictp.core.aware.AwareManager;
import org.dromara.dynamictp.core.aware.RejectHandlerAware;
import org.dromara.dynamictp.core.aware.TaskEnhanceAware;
Expand Down Expand Up @@ -164,7 +164,7 @@ public static ExecutorWrapper of(DtpExecutor executor) {
*/
public ExecutorWrapper capture() {
ExecutorWrapper executorWrapper = new ExecutorWrapper();
BeanCopierUtils.copyProperties(this, executorWrapper);
BeanCopierUtil.copyProperties(this, executorWrapper);
executorWrapper.executor = new CapturedExecutor(this.getExecutor());
return executorWrapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ default int getOrder() {

/**
* Init.
*
* @param args args
*/
void init();
void init(Object... args);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DtpInitializerExecutor {

private static final AtomicBoolean INITIALIZED = new AtomicBoolean(false);

public static void init() {
public static void init(Object... args) {
if (!INITIALIZED.compareAndSet(false, true)) {
return;
}
Expand All @@ -43,6 +43,6 @@ public static void init() {
return;
}
loadedInitializers.sort(Comparator.comparingInt(DtpInitializer::getOrder));
loadedInitializers.forEach(DtpInitializer::init);
loadedInitializers.forEach(i -> i.init(args));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.dromara.dynamictp.example;

import com.baidu.cloud.starlight.springcloud.server.annotation.StarlightScan;
import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.dromara.dynamictp.example;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.dromara.dynamictp.example;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.dromara.dynamictp.example;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.dromara.dynamictp.example;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.dromara.dynamictp.example;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.spring.EnableDynamicTp;
import org.dromara.dynamictp.spring.annotation.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Loading
Loading