Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
ponfee committed Apr 11, 2024
1 parent 83599f2 commit 7cbb35f
Showing 14 changed files with 78 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label is-required">执行超时时间(毫秒):</label>
<label class="col-sm-3 control-label">执行超时时间(毫秒):</label>
<div class="col-sm-9">
<input name="executeTimeout" class="form-control" th:field="*{executeTimeout}" type="text" placeholder="不填写或设置为0则表示无超时时间" autocomplete="off" />
</div>
@@ -192,6 +192,16 @@
retryInterval: {
digits: true,
min: 0
},
executeTimeout: {
digits: true,
min: 0
}
},
messages: {
executeTimeout: {
digits: "请输入正数",
min: "请输入正数"
}
}
});
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label is-required">执行超时时间(毫秒):</label>
<label class="col-sm-3 control-label">执行超时时间(毫秒):</label>
<div class="col-sm-9">
<p class="form-control-static">[(*{executeTimeout})]</p>
</div>
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label is-required">执行超时时间(毫秒):</label>
<label class="col-sm-3 control-label">执行超时时间(毫秒):</label>
<div class="col-sm-9">
<input name="executeTimeout" class="form-control" th:field="*{executeTimeout}" type="text" placeholder="不填写或设置为0则表示无超时时间" autocomplete="off" />
</div>
@@ -183,7 +183,27 @@
});

$("#form-job-edit").validate({
focusCleanup: true
focusCleanup: true,
rules: {
retryCount: {
digits: true,
min: 0
},
retryInterval: {
digits: true,
min: 0
},
executeTimeout: {
digits: true,
min: 0
}
},
messages: {
executeTimeout: {
digits: "请输入正数",
min: "请输入正数"
}
}
});

function submitHandler() {
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
<i class="fa fa-edit"></i> 修改全部
</a>
<a class="btn btn-success" onclick="addWorker()">
<i class="fa fa-plus"></i> 注册Worker
<i class="fa fa-plus"></i> 添加Worker
</a>
</div>

@@ -221,9 +221,9 @@
function addWorker() {
layer.open({
type: 1,
title: '注册Worker',
title: '添加Worker',
btn: ['确定', '取消'],
content: '<input type="text" class="layui-layer-input" placeholder="请输入待注册Worker的`host:port`">',
content: '<input type="text" class="layui-layer-input" placeholder="请输入待添加Worker的`host:port`">',
skin: 'layui-layer-prompt',
resize: false,
success: function (layero, index) {
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@
import com.alibaba.druid.util.Utils;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.MybatisUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.config.properties.DruidProperties;
import com.ruoyi.framework.config.properties.SimpleJdbcProperties;
import com.ruoyi.framework.datasource.DynamicDataSource;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.io.VFS;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
@@ -78,7 +78,7 @@ public DynamicDataSource ruoyiDynamicDataSource(SimpleJdbcProperties ruoyiMaster
druidProperties.dataSource(masterDataSource);
targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);

if (ruoyiSlaveJdbcConfig.isValid()) {
if (StringUtils.isNotBlank(ruoyiSlaveJdbcConfig.getUrl())) {
DruidDataSource slaveDataSource = DruidDataSourceBuilder.create().build();
slaveDataSource.setUrl(ruoyiSlaveJdbcConfig.getUrl());
slaveDataSource.setUsername(ruoyiSlaveJdbcConfig.getUsername());
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@

package com.ruoyi.framework.config.properties;

import org.apache.commons.lang3.StringUtils;

/**
* Simple jdbc properties
*
@@ -53,8 +51,4 @@ public void setPassword(String password) {
this.password = password;
}

public boolean isValid() {
return StringUtils.isNotBlank(url);
}

}
Original file line number Diff line number Diff line change
@@ -103,13 +103,13 @@ class MybatisDataSourceRegistrar implements /*EnvironmentAware,*/ ImportBeanDefi

private final Environment environment;

public MybatisDataSourceRegistrar(Environment environment) {
MybatisDataSourceRegistrar(Environment environment) {
this.environment = environment;
}

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
AnnotationAttributes attrs = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(MybatisDataSourceConfigurer.class.getName()));
AnnotationAttributes attrs = SpringUtils.getAnnotationAttributes(importingClassMetadata, MybatisDataSourceConfigurer.class);
if (attrs == null) {
return;
}
Original file line number Diff line number Diff line change
@@ -19,12 +19,15 @@
import org.apache.commons.io.IOUtils;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.server.WebServer;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.ResourceUtils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.net.URL;

/**
@@ -60,4 +63,9 @@ public static int getActualWebServerPort(WebServerApplicationContext webServerAp
return webServer.getPort();
}

public static AnnotationAttributes getAnnotationAttributes(AnnotatedTypeMetadata metadata,
Class<? extends Annotation> annotationClass) {
return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationClass.getName()));
}

}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
package cn.ponfee.disjob.id.snowflake.db;

import cn.ponfee.disjob.common.base.IdGenerator;
import cn.ponfee.disjob.common.spring.SpringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.annotation.Autowired;
@@ -65,11 +66,11 @@
int workerIdBitLength() default 8;

/**
* Named DbDistributedSnowflake
* Basic DbDistributedSnowflake
*/
class NamedDbdSnowflake extends DbDistributedSnowflake {
class BasicDbdSnowflake extends DbDistributedSnowflake {

NamedDbdSnowflake(JdbcTemplate jdbcTemplate,
BasicDbdSnowflake(JdbcTemplate jdbcTemplate,
Object supervisor,
String bizTag,
int sequenceBitLength,
@@ -103,7 +104,7 @@ private static String serializeSupervisor(Object supervisor) {
/**
* Annotated DbDistributedSnowflake
*/
class AnnotatedDbSnowflake extends NamedDbdSnowflake {
class AnnotatedDbSnowflake extends BasicDbdSnowflake {

AnnotatedDbSnowflake(@Autowired JdbcTemplate jdbcTemplate, // use @Primary JdbcTemplate bean
@Autowired @Qualifier(SPRING_BEAN_NAME_CURRENT_SUPERVISOR) Object supervisor,
@@ -118,7 +119,7 @@ class DbSnowFlakeWorkerRegistrar implements ImportBeanDefinitionRegistrar {

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
AnnotationAttributes attrs = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(DbSnowflakeIdGenerator.class.getName()));
AnnotationAttributes attrs = SpringUtils.getAnnotationAttributes(importingClassMetadata, DbSnowflakeIdGenerator.class);
if (attrs == null) {
return;
}
@@ -129,9 +130,9 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
bd = new AnnotatedGenericBeanDefinition(AnnotatedDbSnowflake.class);
} else {
bd = new GenericBeanDefinition();
bd.setBeanClass(NamedDbdSnowflake.class);
bd.setBeanClass(BasicDbdSnowflake.class);
bd.getConstructorArgumentValues().addIndexedArgumentValue(0, new RuntimeBeanReference(jdbcTemplateRef));
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, new RuntimeBeanReference(NamedDbdSnowflake.SPRING_BEAN_NAME_CURRENT_SUPERVISOR));
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, new RuntimeBeanReference(BasicDbdSnowflake.SPRING_BEAN_NAME_CURRENT_SUPERVISOR));
}

bd.getConstructorArgumentValues().addIndexedArgumentValue(2, attrs.getString("bizTag"));
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ public class EtcdClient implements Closeable {
*/
private final LoopThread healthCheckThread;

private final Map<String, Pair<Watch.Watcher, ChildChangedListener>> childWatchers = new HashMap<>();
private final Map<String, Pair<Watch.Watcher, ChildChangedListener>> childWatchers = new ConcurrentHashMap<>();

private final Set<ConnectionStateListener<EtcdClient>> connectionStateListeners = ConcurrentHashMap.newKeySet();

@@ -224,9 +224,11 @@ public synchronized void watchChildChanged(String parentKey, CountDownLatch latc
throw new IllegalStateException("Parent key already watched: " + parentKey);
}

ChildChangedListener innerListener = new ChildChangedListener(parentKey, latch, listener);
Watch.Watcher watcher = client.getWatchClient().watch(utf8(parentKey), WATCH_PREFIX_OPTION, innerListener);
childWatchers.put(parentKey, Pair.of(watcher, innerListener));
childWatchers.computeIfAbsent(parentKey, key -> {
ChildChangedListener innerListener = new ChildChangedListener(key, latch, listener);
Watch.Watcher watcher = client.getWatchClient().watch(utf8(key), WATCH_PREFIX_OPTION, innerListener);
return Pair.of(watcher, innerListener);
});
}

public synchronized boolean unwatchChildChanged(String parentKey) {
8 changes: 8 additions & 0 deletions disjob-registry/disjob-registry-zookeeper/pom.xml
Original file line number Diff line number Diff line change
@@ -37,6 +37,14 @@
</exclusion>
</exclusions>
</dependency>
<!--
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>${curator-recipes.version}</version>
</dependency>
-->

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
Original file line number Diff line number Diff line change
@@ -35,7 +35,11 @@
import org.springframework.util.Assert;

import java.io.Closeable;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@@ -48,7 +52,7 @@
public class CuratorFrameworkClient implements Closeable {
private static final Logger LOG = LoggerFactory.getLogger(CuratorFrameworkClient.class);

private final Map<String, ChildChangedWatcher> childWatchers = new HashMap<>();
private final Map<String, ChildChangedWatcher> childWatchers = new ConcurrentHashMap<>();
private final CuratorFramework curatorFramework;
private final ReconnectCallback reconnectCallback;

Original file line number Diff line number Diff line change
@@ -39,8 +39,7 @@
@Configuration
@MybatisDataSourceConfigurer(
dataSourceName = SupervisorDataSourceConfig.DATA_SOURCE_NAME,
mapperLocations = "classpath*:cn/ponfee/disjob/supervisor/dao/xml/*.xml",
basePackageClasses = SupervisorDataSourceConfig.class
mapperLocations = "classpath*:cn/ponfee/disjob/supervisor/dao/xml/*.xml"
)
public class SupervisorDataSourceConfig {

Original file line number Diff line number Diff line change
@@ -17,12 +17,9 @@
package cn.ponfee.disjob.supervisor.dao;

import cn.ponfee.disjob.core.model.SchedJob;
import cn.ponfee.disjob.supervisor.application.request.SchedJobPageRequest;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* test disjob tx

0 comments on commit 7cbb35f

Please sign in to comment.