Skip to content

Commit

Permalink
Merge branch 'master' into springboot3
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhom1314 committed Dec 20, 2023
2 parents 13a1ee5 + b5ec844 commit 8a9ebb4
Show file tree
Hide file tree
Showing 53 changed files with 146 additions and 106 deletions.
9 changes: 9 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,14 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-http</artifactId>
</dependency>

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ private DynamicTpConst() { }

public static final String RUN_TIMEOUT = "runTimeout";

public static final String TRY_INTERRUPT_WHEN_TIMEOUT = "tryInterrupt";

public static final String QUEUE_TIMEOUT = "queueTimeout";

public static final String TASK_WRAPPERS = "taskWrappers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class NotifyItem {
private int clusterLimit = 1;

/**
* Receivers, split by , If NotifyPlatform.receivers have a value, they will be overwritten by the thread pool alarm
* Receivers, split by, If NotifyPlatform.receivers have a value, they will be overwritten by the thread pool alarm
*/
private String receivers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public class TpExecutorProps {
*/
private long runTimeout = 0;

/**
* If try interrupt task when timeout.
*/
private boolean tryInterrupt = false;

/**
* Task queue wait timeout, unit (ms), just for statistics.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.notifier.base;
package org.dromara.dynamictp.common.notifier;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.notifier.base;
package org.dromara.dynamictp.common.notifier;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.dromara.dynamictp.common.entity.NotifyItem;
import org.dromara.dynamictp.common.entity.NotifyPlatform;
import org.dromara.dynamictp.core.notifier.context.BaseNotifyCtx;
import org.dromara.dynamictp.core.notifier.context.DtpNotifyCtxHolder;

import java.util.Optional;

/**
* AbstractNotifier related
Expand All @@ -51,20 +45,4 @@ public final void send(NotifyPlatform platform, String content) {
* @param content content
*/
protected abstract void send0(NotifyPlatform platform, String content);

/**
* Get the notify receivers
* @param platform platform
* @return Receivers
*/
protected String[] getReceivers(NotifyPlatform platform) {
BaseNotifyCtx context = DtpNotifyCtxHolder.get();
String receivers = Optional.ofNullable(context)
.map(BaseNotifyCtx::getNotifyItem)
.map(NotifyItem::getReceivers)
.orElse(null);
receivers = StringUtils.isBlank(receivers) ? platform.getReceivers() : receivers;
return receivers.split(",");
}

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

package org.dromara.dynamictp.core.notifier.base;
package org.dromara.dynamictp.common.notifier;

import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -57,7 +57,7 @@ protected String buildMsgBody(NotifyPlatform platform, String content) {

MarkdownReq.At at = new MarkdownReq.At();

List<String> mobiles = Lists.newArrayList(getReceivers(platform));
List<String> mobiles = Lists.newArrayList(platform.getReceivers().split(","));
at.setAtMobiles(mobiles);
if (mobiles.contains(ALL) || CollectionUtils.isEmpty(mobiles)) {
at.setAtAll(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.notifier.base;
package org.dromara.dynamictp.common.notifier;

import lombok.extern.slf4j.Slf4j;
import lombok.val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.notifier.base;
package org.dromara.dynamictp.common.notifier;

import org.dromara.dynamictp.common.entity.NotifyPlatform;

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

package org.dromara.dynamictp.core.notifier.base;
package org.dromara.dynamictp.common.notifier;

import lombok.extern.slf4j.Slf4j;
import org.dromara.dynamictp.common.constant.WechatNotifyConst;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.plugin;
package org.dromara.dynamictp.common.plugin;

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

package org.dromara.dynamictp.core.plugin;
package org.dromara.dynamictp.common.plugin;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.plugin;
package org.dromara.dynamictp.common.plugin;

import com.google.common.collect.Maps;
import net.sf.cglib.proxy.Enhancer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.plugin;
package org.dromara.dynamictp.common.plugin;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.plugin;
package org.dromara.dynamictp.common.plugin;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.plugin;
package org.dromara.dynamictp.common.plugin;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.plugin;
package org.dromara.dynamictp.common.plugin;

/**
* The annotation that indicate the method signature.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.dromara.dynamictp.core.plugin;
package org.dromara.dynamictp.common.plugin;

import org.dromara.dynamictp.common.ex.DtpException;

Expand Down
10 changes: 0 additions & 10 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@
<artifactId>hutool-core</artifactId>
</dependency>

<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-http</artifactId>
</dependency>

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected void refresh(TpExecutorProps props, ThreadPoolStatProvider statProvide
if (Objects.nonNull(props)) {
statProvider.setRunTimeout(props.getRunTimeout());
statProvider.setQueueTimeout(props.getQueueTimeout());
statProvider.setTryInterrupt(props.isTryInterrupt());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public class DtpExecutor extends ThreadPoolExecutor
*/
private long runTimeout = 0;

/**
* for manual builder thread pools only
*/
private boolean tryInterrupt = false;

/**
* for manual builder thread pools only
*/
Expand Down Expand Up @@ -355,22 +360,30 @@ public void setRejectHandlerType(String rejectHandlerType) {
this.rejectHandlerType = rejectHandlerType;
}

public long getRunTimeout() {
return runTimeout;
}

public void setRunTimeout(long runTimeout) {
this.runTimeout = runTimeout;
}

public void setQueueTimeout(long queueTimeout) {
this.queueTimeout = queueTimeout;
public boolean isTryInterrupt() {
return tryInterrupt;
}

public long getRunTimeout() {
return runTimeout;
public void setTryInterrupt(boolean tryInterrupt) {
this.tryInterrupt = tryInterrupt;
}

public long getQueueTimeout() {
return queueTimeout;
}

public void setQueueTimeout(long queueTimeout) {
this.queueTimeout = queueTimeout;
}

public boolean isWaitForTasksToCompleteOnShutdown() {
return waitForTasksToCompleteOnShutdown;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.dromara.dynamictp.core.notifier.DtpLarkNotifier;
import org.dromara.dynamictp.core.notifier.DtpNotifier;
import org.dromara.dynamictp.core.notifier.DtpWechatNotifier;
import org.dromara.dynamictp.core.notifier.base.DingNotifier;
import org.dromara.dynamictp.core.notifier.base.LarkNotifier;
import org.dromara.dynamictp.core.notifier.base.WechatNotifier;
import org.dromara.dynamictp.common.notifier.DingNotifier;
import org.dromara.dynamictp.common.notifier.LarkNotifier;
import org.dromara.dynamictp.common.notifier.WechatNotifier;
import org.dromara.dynamictp.core.notifier.context.DtpNotifyCtxHolder;
import org.dromara.dynamictp.core.notifier.manager.NotifyHelper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
import org.dromara.dynamictp.common.entity.NotifyItem;
import org.dromara.dynamictp.common.entity.NotifyPlatform;
import org.dromara.dynamictp.common.entity.TpMainFields;
import org.dromara.dynamictp.common.notifier.Notifier;
import org.dromara.dynamictp.common.util.CommonUtil;
import org.dromara.dynamictp.common.util.DateUtil;
import org.dromara.dynamictp.core.notifier.alarm.AlarmCounter;
import org.dromara.dynamictp.core.notifier.base.Notifier;
import org.dromara.dynamictp.core.notifier.context.AlarmCtx;
import org.dromara.dynamictp.core.notifier.context.BaseNotifyCtx;
import org.dromara.dynamictp.core.notifier.context.DtpNotifyCtxHolder;
import org.dromara.dynamictp.core.support.ExecutorWrapper;
import org.dromara.dynamictp.core.system.SystemMetricManager;
import org.slf4j.MDC;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.Field;
import java.util.List;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void sendChangeMsg(NotifyPlatform notifyPlatform, TpMainFields oldFields,
log.debug("Notice content is empty, ignore send notice message.");
return;
}
notifier.send(notifyPlatform, content);
notifier.send(newTargetPlatform(notifyPlatform), content);
}

@Override
Expand All @@ -84,7 +85,7 @@ public void sendAlarmMsg(NotifyPlatform notifyPlatform, NotifyItemEnum notifyIte
log.debug("Alarm content is empty, ignore send alarm message.");
return;
}
notifier.send(notifyPlatform, content);
notifier.send(newTargetPlatform(notifyPlatform), content);
}

protected String buildAlarmContent(NotifyPlatform platform, NotifyItemEnum notifyItemEnum) {
Expand Down Expand Up @@ -179,6 +180,17 @@ protected String formatReceivers(String receives) {
return Joiner.on(", @").join(receivers);
}

private NotifyPlatform newTargetPlatform(NotifyPlatform platform) {
NotifyPlatform targetPlatform = new NotifyPlatform();
BeanUtils.copyProperties(platform, targetPlatform);

BaseNotifyCtx context = DtpNotifyCtxHolder.get();
NotifyItem item = context.getNotifyItem();
String receives = StringUtils.isBlank(item.getReceivers()) ? platform.getReceivers() : item.getReceivers();
targetPlatform.setReceivers(receives);
return targetPlatform;
}

protected String populatePoolName(ExecutorWrapper executorWrapper) {
String poolAlisaName = executorWrapper.getThreadPoolAliasName();
if (StringUtils.isBlank(poolAlisaName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.dromara.dynamictp.common.constant.DingNotifyConst;
import org.dromara.dynamictp.common.em.NotifyPlatformEnum;
import org.dromara.dynamictp.core.notifier.base.Notifier;
import org.dromara.dynamictp.common.notifier.Notifier;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.dromara.dynamictp.common.constant.LarkNotifyConst;
import org.dromara.dynamictp.common.em.NotifyPlatformEnum;
import org.dromara.dynamictp.core.notifier.base.Notifier;
import org.dromara.dynamictp.common.notifier.Notifier;

import java.util.Arrays;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.commons.lang3.StringUtils;
import org.dromara.dynamictp.common.constant.WechatNotifyConst;
import org.dromara.dynamictp.common.em.NotifyPlatformEnum;
import org.dromara.dynamictp.core.notifier.base.Notifier;
import org.dromara.dynamictp.common.notifier.Notifier;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
Expand Down
Loading

0 comments on commit 8a9ebb4

Please sign in to comment.