Search in sources :

Example 1 with DtpMainProp

use of com.dtp.common.dto.DtpMainProp in project dynamic-tp by lyh200.

the class DtpRegistry method refresh.

private static void refresh(DtpExecutor executor, ThreadPoolProperties properties) {
    if (properties.getCorePoolSize() < 0 || properties.getMaximumPoolSize() <= 0 || properties.getMaximumPoolSize() < properties.getCorePoolSize() || properties.getKeepAliveTime() < 0) {
        log.error("DynamicTp refresh, invalid parameters exist, properties: {}", properties);
        return;
    }
    DtpMainProp oldProp = ExecutorConverter.convert(executor);
    doRefresh(executor, properties);
    DtpMainProp newProp = ExecutorConverter.convert(executor);
    if (oldProp.equals(newProp)) {
        log.warn("DynamicTp [{}] has no properties changed.", executor.getThreadPoolName());
        return;
    }
    List<FieldInfo> diffFields = EQUATOR.getDiffFields(oldProp, newProp);
    List<String> diffKeys = diffFields.stream().map(FieldInfo::getFieldName).collect(Collectors.toList());
    log.info("DynamicTp [{}] refreshed end, changed keys: {}, corePoolSize: [{}], maxPoolSize: [{}], " + "queueType: [{}], queueCapacity: [{}], keepAliveTime: [{}], rejectedType: [{}], " + "allowsCoreThreadTimeOut: [{}]", executor.getThreadPoolName(), diffKeys, String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getCorePoolSize(), newProp.getCorePoolSize()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getMaxPoolSize(), newProp.getMaxPoolSize()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getQueueType(), newProp.getQueueType()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getQueueCapacity(), newProp.getQueueCapacity()), String.format("%ss => %ss", oldProp.getKeepAliveTime(), newProp.getKeepAliveTime()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getRejectType(), newProp.getRejectType()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.isAllowCoreThreadTimeOut(), newProp.isAllowCoreThreadTimeOut()));
    val notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.CHANGE);
    boolean ifNotice = CollUtil.isNotEmpty(dtpProperties.getPlatforms()) && Objects.nonNull(notifyItem) && notifyItem.isEnabled();
    if (!ifNotice) {
        return;
    }
    DtpContext context = DtpContext.builder().dtpExecutor(executor).platforms(dtpProperties.getPlatforms()).notifyItem(notifyItem).build();
    DtpContextHolder.set(context);
    NOTIFY_EXECUTOR.execute(() -> NotifierHandler.getInstance().sendNotice(oldProp, diffKeys));
}
Also used : lombok.val(lombok.val) DtpMainProp(com.dtp.common.dto.DtpMainProp) DtpContext(com.dtp.core.context.DtpContext) FieldInfo(com.github.dadiyang.equator.FieldInfo)

Example 2 with DtpMainProp

use of com.dtp.common.dto.DtpMainProp in project dynamic-tp by lyh200.

the class ExecutorConverter method convert.

public static DtpMainProp convert(DtpExecutor dtpExecutor) {
    DtpMainProp wrapper = new DtpMainProp();
    wrapper.setDtpName(dtpExecutor.getThreadPoolName());
    wrapper.setCorePoolSize(dtpExecutor.getCorePoolSize());
    wrapper.setMaxPoolSize(dtpExecutor.getMaximumPoolSize());
    wrapper.setKeepAliveTime(dtpExecutor.getKeepAliveTime(TimeUnit.SECONDS));
    wrapper.setQueueType(dtpExecutor.getQueueName());
    wrapper.setQueueCapacity(dtpExecutor.getQueueCapacity());
    wrapper.setRejectType(dtpExecutor.getRejectHandlerName());
    wrapper.setAllowCoreThreadTimeOut(dtpExecutor.allowsCoreThreadTimeOut());
    return wrapper;
}
Also used : DtpMainProp(com.dtp.common.dto.DtpMainProp)

Example 3 with DtpMainProp

use of com.dtp.common.dto.DtpMainProp in project dynamic-tp by dromara.

the class ExecutorConverter method convert.

public static DtpMainProp convert(DtpExecutor dtpExecutor) {
    DtpMainProp wrapper = new DtpMainProp();
    wrapper.setDtpName(dtpExecutor.getThreadPoolName());
    wrapper.setCorePoolSize(dtpExecutor.getCorePoolSize());
    wrapper.setMaxPoolSize(dtpExecutor.getMaximumPoolSize());
    wrapper.setKeepAliveTime(dtpExecutor.getKeepAliveTime(TimeUnit.SECONDS));
    wrapper.setQueueType(dtpExecutor.getQueueName());
    wrapper.setQueueCapacity(dtpExecutor.getQueueCapacity());
    wrapper.setRejectType(dtpExecutor.getRejectHandlerName());
    wrapper.setAllowCoreThreadTimeOut(dtpExecutor.allowsCoreThreadTimeOut());
    return wrapper;
}
Also used : DtpMainProp(com.dtp.common.dto.DtpMainProp)

Example 4 with DtpMainProp

use of com.dtp.common.dto.DtpMainProp in project dynamic-tp by dromara.

the class DtpRegistry method refresh.

private static void refresh(DtpExecutor executor, ThreadPoolProperties properties) {
    if (properties.getCorePoolSize() < 0 || properties.getMaximumPoolSize() <= 0 || properties.getMaximumPoolSize() < properties.getCorePoolSize() || properties.getKeepAliveTime() < 0) {
        log.error("DynamicTp refresh, invalid parameters exist, properties: {}", properties);
        return;
    }
    DtpMainProp oldProp = ExecutorConverter.convert(executor);
    doRefresh(executor, properties);
    DtpMainProp newProp = ExecutorConverter.convert(executor);
    if (oldProp.equals(newProp)) {
        log.warn("DynamicTp refresh, main properties of [{}] have not changed.", executor.getThreadPoolName());
        return;
    }
    List<FieldInfo> diffFields = EQUATOR.getDiffFields(oldProp, newProp);
    List<String> diffKeys = diffFields.stream().map(FieldInfo::getFieldName).collect(toList());
    log.info("DynamicTp refresh, name: [{}], changed keys: {}, corePoolSize: [{}], maxPoolSize: [{}], " + "queueType: [{}], queueCapacity: [{}], keepAliveTime: [{}], rejectedType: [{}], " + "allowsCoreThreadTimeOut: [{}]", executor.getThreadPoolName(), diffKeys, String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getCorePoolSize(), newProp.getCorePoolSize()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getMaxPoolSize(), newProp.getMaxPoolSize()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getQueueType(), newProp.getQueueType()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getQueueCapacity(), newProp.getQueueCapacity()), String.format("%ss => %ss", oldProp.getKeepAliveTime(), newProp.getKeepAliveTime()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getRejectType(), newProp.getRejectType()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.isAllowCoreThreadTimeOut(), newProp.isAllowCoreThreadTimeOut()));
    val notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.CHANGE);
    boolean ifNotice = CollUtil.isNotEmpty(dtpProperties.getPlatforms()) && Objects.nonNull(notifyItem) && notifyItem.isEnabled();
    if (!ifNotice) {
        return;
    }
    DtpContext context = DtpContext.builder().dtpExecutor(executor).platforms(dtpProperties.getPlatforms()).notifyItem(notifyItem).build();
    DtpContextHolder.set(context);
    NOTIFY_EXECUTOR.execute(() -> NotifierHandler.getInstance().sendNotice(oldProp, diffKeys));
}
Also used : lombok.val(lombok.val) DtpMainProp(com.dtp.common.dto.DtpMainProp) DtpContext(com.dtp.core.context.DtpContext) FieldInfo(com.github.dadiyang.equator.FieldInfo)

Aggregations

DtpMainProp (com.dtp.common.dto.DtpMainProp)4 DtpContext (com.dtp.core.context.DtpContext)2 FieldInfo (com.github.dadiyang.equator.FieldInfo)2 lombok.val (lombok.val)2