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 code #342

Merged
merged 1 commit into from
Oct 17, 2023
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 @@ -59,7 +59,7 @@ public EagerThreadPoolExecutorProxy(EagerThreadPoolExecutor executor) {

@Override
public void execute(Runnable command) {
command = getEnhancedTask(command, taskWrappers);
command = getEnhancedTask(command);
AwareManager.execute(this, command);
super.execute(command);
}
Expand All @@ -76,6 +76,11 @@ protected void afterExecute(Runnable r, Throwable t) {
AwareManager.afterExecute(this, r, t);
}

@Override
public List<TaskWrapper> getTaskWrappers() {
return taskWrappers;
}

@Override
public void setTaskWrappers(List<TaskWrapper> taskWrappers) {
this.taskWrappers = taskWrappers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public StandardThreadExecutorProxy(StandardThreadExecutor executor) {

@Override
public void execute(Runnable command) {
command = getEnhancedTask(command, taskWrappers);
command = getEnhancedTask(command);
AwareManager.execute(this, command);
super.execute(command);
}
Expand All @@ -71,6 +71,11 @@ protected void afterExecute(Runnable r, Throwable t) {
AwareManager.afterExecute(this, r, t);
}

@Override
public List<TaskWrapper> getTaskWrappers() {
return taskWrappers;
}

@Override
public void setTaskWrappers(List<TaskWrapper> taskWrappers) {
this.taskWrappers = taskWrappers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ default Runnable getEnhancedTask(Runnable command, List<TaskWrapper> taskWrapper
return command;
}

/**
* Enhance task
*
* @param command command
* @return enhanced task
*/
default Runnable getEnhancedTask(Runnable command) {
return getEnhancedTask(command, getTaskWrappers());
}

/**
* Get task wrappers
*
* @return task wrappers
*/
List<TaskWrapper> getTaskWrappers();

/**
* Set task wrappers
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void execute(Runnable task, long startTimeout) {

@Override
public void execute(Runnable command) {
command = getEnhancedTask(command, taskWrappers);
command = getEnhancedTask(command);
AwareManager.execute(this, command);
super.execute(command);
}
Expand Down Expand Up @@ -273,6 +273,7 @@ public void setPlatformIds(List<String> platformIds) {
this.platformIds = platformIds;
}

@Override
public List<TaskWrapper> getTaskWrappers() {
return taskWrappers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.support;
package org.dromara.dynamictp.core.executor;

import org.dromara.dynamictp.core.executor.DtpExecutor;
import org.dromara.dynamictp.core.executor.ScheduledDtpExecutor;
import org.dromara.dynamictp.core.executor.EagerDtpExecutor;
import org.dromara.dynamictp.core.executor.OrderedDtpExecutor;
import org.dromara.dynamictp.core.executor.eager.EagerDtpExecutor;
import lombok.Getter;

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

package org.dromara.dynamictp.core.executor;
package org.dromara.dynamictp.core.executor.eager;

import org.dromara.dynamictp.core.support.TaskQueue;
import org.dromara.dynamictp.core.executor.DtpExecutor;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.support;
package org.dromara.dynamictp.core.executor.eager;

import org.dromara.dynamictp.common.queue.VariableLinkedBlockingQueue;
import org.dromara.dynamictp.core.executor.EagerDtpExecutor;
import org.dromara.dynamictp.core.executor.eager.EagerDtpExecutor;
import org.springframework.lang.NonNull;

import java.util.concurrent.RejectedExecutionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import org.dromara.dynamictp.common.entity.DtpExecutorProps;
import org.dromara.dynamictp.common.properties.DtpProperties;
import org.dromara.dynamictp.common.spring.SpringBeanHelper;
import org.dromara.dynamictp.core.executor.EagerDtpExecutor;
import org.dromara.dynamictp.core.executor.eager.EagerDtpExecutor;
import org.dromara.dynamictp.core.executor.NamedThreadFactory;
import org.dromara.dynamictp.core.reject.RejectHandlerGetter;
import org.dromara.dynamictp.core.support.BinderHelper;
import org.dromara.dynamictp.core.support.ExecutorType;
import org.dromara.dynamictp.core.support.TaskQueue;
import org.dromara.dynamictp.core.executor.ExecutorType;
import org.dromara.dynamictp.core.executor.eager.TaskQueue;
import org.dromara.dynamictp.core.support.task.wrapper.TaskWrappers;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.EnvironmentAware;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import org.dromara.dynamictp.common.util.ReflectionUtil;
import org.dromara.dynamictp.core.DtpRegistry;
import org.dromara.dynamictp.core.executor.DtpExecutor;
import org.dromara.dynamictp.core.executor.EagerDtpExecutor;
import org.dromara.dynamictp.core.executor.eager.EagerDtpExecutor;
import org.dromara.dynamictp.core.plugin.DtpInterceptorRegistry;
import org.dromara.dynamictp.core.support.DynamicTp;
import org.dromara.dynamictp.core.support.ExecutorWrapper;
import org.dromara.dynamictp.core.support.TaskQueue;
import org.dromara.dynamictp.core.executor.eager.TaskQueue;
import org.dromara.dynamictp.core.support.ThreadPoolExecutorProxy;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
import org.dromara.dynamictp.common.em.RejectedTypeEnum;
import org.dromara.dynamictp.common.entity.NotifyItem;
import org.dromara.dynamictp.common.queue.VariableLinkedBlockingQueue;
import org.dromara.dynamictp.core.executor.eager.TaskQueue;
import org.dromara.dynamictp.core.reject.RejectHandlerGetter;
import org.dromara.dynamictp.core.support.task.wrapper.TaskWrapper;
import org.dromara.dynamictp.core.executor.DtpExecutor;
import org.dromara.dynamictp.core.executor.EagerDtpExecutor;
import org.dromara.dynamictp.core.executor.eager.EagerDtpExecutor;
import org.dromara.dynamictp.core.executor.NamedThreadFactory;
import org.dromara.dynamictp.core.executor.OrderedDtpExecutor;
import org.dromara.dynamictp.core.executor.ScheduledDtpExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ public class ThreadPoolExecutorProxy extends ThreadPoolExecutor implements TaskE
/**
* Reject handler type.
*/
private final String rejectHandlerType;
private String rejectHandlerType;

public ThreadPoolExecutorProxy(ThreadPoolExecutor executor) {
super(executor.getCorePoolSize(), executor.getMaximumPoolSize(),
executor.getKeepAliveTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, executor.getQueue(),
executor.getKeepAliveTime(TimeUnit.MILLISECONDS),
TimeUnit.MILLISECONDS, executor.getQueue(),
executor.getThreadFactory(), executor.getRejectedExecutionHandler());
this.rejectHandlerType = getRejectedExecutionHandler().getClass().getSimpleName();
setRejectedExecutionHandler(RejectHandlerGetter.getProxy(getRejectedExecutionHandler()));
Expand All @@ -58,7 +59,7 @@ public ThreadPoolExecutorProxy(ThreadPoolExecutor executor) {

@Override
public void execute(Runnable command) {
command = getEnhancedTask(command, taskWrappers);
command = getEnhancedTask(command);
AwareManager.execute(this, command);
super.execute(command);
}
Expand All @@ -76,6 +77,11 @@ protected void afterExecute(Runnable r, Throwable t) {
AwareManager.afterExecute(this, r, t);
}

@Override
public List<TaskWrapper> getTaskWrappers() {
return taskWrappers;
}

@Override
public void setTaskWrappers(List<TaskWrapper> taskWrappers) {
this.taskWrappers = taskWrappers;
Expand Down
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<url>https://github.com/yanhom1314/dynamic-tp</url>

<properties>
<revision>1.1.4</revision>
<revision>1.1.4.1</revision>
<hutool.version>5.8.12</hutool.version>
<lombok.version>1.18.24</lombok.version>
<apollo.version>1.5.0</apollo.version>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<url>https://github.com/yanhom1314/dynamic-tp</url>

<properties>
<revision>1.1.4</revision>
<revision>1.1.4.1</revision>
<java.version>1.8</java.version>
<spring-boot.version>2.5.14</spring-boot.version>
<spring-cloud.version>2020.0.5</spring-cloud.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public TomcatExecutorProxy(ThreadPoolExecutor executor) {

@Override
public void execute(Runnable command) {
command = getEnhancedTask(command, taskWrappers);
command = getEnhancedTask(command);
AwareManager.execute(this, command);
super.execute(command);
}
Expand All @@ -93,6 +93,11 @@ protected void afterExecute(Runnable r, Throwable t) {
AwareManager.afterExecute(this, r, t);
}

@Override
public List<TaskWrapper> getTaskWrappers() {
return taskWrappers;
}

@Override
public void setTaskWrappers(List<TaskWrapper> taskWrappers) {
this.taskWrappers = taskWrappers;
Expand Down
Loading