Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37a6254

Browse files
committed
feat: [storageExt] MySqlSeriesDfsService
1 parent c50a3ed commit 37a6254

File tree

7 files changed

+304
-27
lines changed

7 files changed

+304
-27
lines changed

powerjob-common/src/main/java/tech/powerjob/common/serialize/JsonUtils.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import lombok.extern.slf4j.Slf4j;
99
import org.apache.commons.lang3.StringUtils;
1010
import org.apache.commons.lang3.exception.ExceptionUtils;
11+
import tech.powerjob.common.exception.ImpossibleException;
1112
import tech.powerjob.common.exception.PowerJobException;
1213

1314
import java.io.IOException;
15+
import java.util.HashMap;
16+
import java.util.Map;
1417

1518
/**
1619
* JSON工具类
@@ -27,6 +30,8 @@ public class JsonUtils {
2730
.configure(JsonParser.Feature.IGNORE_UNDEFINED, true)
2831
.build();
2932

33+
private static final TypeReference<Map<String, Object>> MAP_TYPE_REFERENCE = new TypeReference<Map<String, Object>> () {};
34+
3035
private JsonUtils(){
3136

3237
}
@@ -67,6 +72,18 @@ public static <T> T parseObject(String json, Class<T> clz) throws JsonProcessing
6772
return JSON_MAPPER.readValue(json, clz);
6873
}
6974

75+
public static Map<String, Object> parseMap(String json) {
76+
if (StringUtils.isEmpty(json)) {
77+
return new HashMap<>();
78+
}
79+
try {
80+
return JSON_MAPPER.readValue(json, MAP_TYPE_REFERENCE);
81+
} catch (Exception e) {
82+
ExceptionUtils.rethrow(e);
83+
}
84+
throw new ImpossibleException();
85+
}
86+
7087
public static <T> T parseObject(byte[] b, Class<T> clz) throws IOException {
7188
return JSON_MAPPER.readValue(b, clz);
7289
}

powerjob-common/src/main/java/tech/powerjob/common/utils/NetUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ public static int getRandomPort() {
5656
return ThreadLocalRandom.current().nextInt(RND_PORT_START, RND_PORT_END);
5757
}
5858

59+
/**
60+
* 检测某个 IP 端口是否可用
61+
* @param ip IP
62+
* @param port 端口
63+
* @return 是否可用
64+
*/
65+
public static boolean checkIpPortAvailable(String ip, int port) {
66+
try (Socket socket = new Socket()) {
67+
socket.connect(new InetSocketAddress(ip, port), 1000);
68+
return true;
69+
} catch (Exception e) {
70+
return false;
71+
}
72+
}
73+
5974
/**
6075
* 获取本机 IP 地址
6176
*

powerjob-server/powerjob-server-extension/src/main/java/tech/powerjob/server/extension/dfs/FileLocation.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tech.powerjob.server.extension.dfs;
22

3-
import lombok.Data;
3+
import lombok.Getter;
4+
import lombok.Setter;
45
import lombok.experimental.Accessors;
56

67
/**
@@ -9,7 +10,8 @@
910
* @author tjq
1011
* @since 2023/7/16
1112
*/
12-
@Data
13+
@Getter
14+
@Setter
1315
@Accessors(chain = true)
1416
public class FileLocation {
1517

@@ -22,4 +24,9 @@ public class FileLocation {
2224
* 名称
2325
*/
2426
private String name;
27+
28+
@Override
29+
public String toString() {
30+
return String.format("%s.%s", bucket, name);
31+
}
2532
}

powerjob-server/powerjob-server-persistence/src/main/java/tech/powerjob/server/persistence/storage/AbstractDFsService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
@Slf4j
1818
public abstract class AbstractDFsService implements DFsService, ApplicationContextAware, DisposableBean {
1919

20+
protected ApplicationContext applicationContext;
21+
2022
public AbstractDFsService() {
2123
log.info("[DFsService] invoke [{}]'s constructor", this.getClass().getName());
2224
}
@@ -32,6 +34,7 @@ protected static String fetchProperty(Environment environment, String dfsType, S
3234

3335
@Override
3436
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
37+
this.applicationContext = applicationContext;
3538
log.info("[DFsService] invoke [{}]'s setApplicationContext", this.getClass().getName());
3639
init(applicationContext);
3740
}

0 commit comments

Comments
 (0)