Skip to content

Commit

Permalink
license notice
Browse files Browse the repository at this point in the history
  • Loading branch information
ponfee committed Jan 29, 2024
1 parent 0c51c9a commit 2fe04bc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 28 deletions.
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -186,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright (c) 2017-2023 Ponfee
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Disjob
Copyright 2022-2024 Ponfee (http://www.ponfee.cn/)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
42 changes: 21 additions & 21 deletions disjob-common/src/main/java/cn/ponfee/disjob/common/util/Jsons.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public final class Jsons {
/**
* Jackson ObjectMapper(thread safe)
*/
private final ObjectMapper mapper;
private final ObjectMapper objectMapper;

private Jsons(JsonInclude.Include include) {
this.mapper = createObjectMapper(include);
this.objectMapper = createObjectMapper(include);
}

// --------------------------------------------------------serialization
Expand All @@ -92,7 +92,7 @@ private Jsons(JsonInclude.Include include) {
*/
public void write(OutputStream output, Object target) {
try {
mapper.writeValue(output, target);
objectMapper.writeValue(output, target);
} catch (IOException e) {
ExceptionUtils.rethrow(e);
}
Expand All @@ -106,7 +106,7 @@ public void write(OutputStream output, Object target) {
*/
public String string(Object target) {
try {
return mapper.writeValueAsString(target);
return objectMapper.writeValueAsString(target);
} catch (IOException e) {
return ExceptionUtils.rethrow(e);
}
Expand All @@ -120,7 +120,7 @@ public String string(Object target) {
*/
public byte[] bytes(Object target) {
try {
return mapper.writeValueAsBytes(target);
return objectMapper.writeValueAsBytes(target);
} catch (IOException e) {
return ExceptionUtils.rethrow(e);
}
Expand All @@ -143,7 +143,7 @@ public <T> T parse(String json, JavaType javaType) {
return null;
}
try {
return mapper.readValue(json, javaType);
return objectMapper.readValue(json, javaType);
} catch (Exception e) {
return ExceptionUtils.rethrow(e);
}
Expand All @@ -161,34 +161,34 @@ public <T> T parse(byte[] json, JavaType javaType) {
return null;
}
try {
return mapper.readValue(json, javaType);
return objectMapper.readValue(json, javaType);
} catch (Exception e) {
return ExceptionUtils.rethrow(e);
}
}

public <T> T parse(String json, Class<T> target) {
return parse(json, mapper.constructType(target));
return parse(json, objectMapper.constructType(target));
}

public <T> T parse(byte[] json, Class<T> target) {
return parse(json, mapper.constructType(target));
return parse(json, objectMapper.constructType(target));
}

public <T> T parse(String json, Type type) {
return parse(json, mapper.constructType(type));
return parse(json, objectMapper.constructType(type));
}

public <T> T parse(byte[] json, Type type) {
return parse(json, mapper.constructType(type));
return parse(json, objectMapper.constructType(type));
}

public <T> T parse(String json, TypeReference<T> type) {
return parse(json, mapper.constructType(type));
return parse(json, objectMapper.constructType(type));
}

public <T> T parse(byte[] json, TypeReference<T> type) {
return parse(json, mapper.constructType(type));
return parse(json, objectMapper.constructType(type));
}

// ----------------------------------------------------static methods
Expand All @@ -206,7 +206,7 @@ public static Object[] parseArray(String body, Class<?>... types) {
return null;
}

ObjectMapper objectMapper = NORMAL.mapper;
ObjectMapper objectMapper = NORMAL.objectMapper;
JsonNode rootNode = readTree(objectMapper, body);
Assert.isTrue(rootNode.isArray(), "Not array json data.");
ArrayNode arrayNode = (ArrayNode) rootNode;
Expand Down Expand Up @@ -236,7 +236,7 @@ public static Object[] parseMethodArgs(String body, Method method) {
return null;
}

ObjectMapper objectMapper = NORMAL.mapper;
ObjectMapper objectMapper = NORMAL.objectMapper;
JsonNode rootNode = readTree(objectMapper, body);
if (rootNode.isArray()) {
ArrayNode arrayNode = (ArrayNode) rootNode;
Expand Down Expand Up @@ -394,20 +394,20 @@ public static void registerJavaTimeModule(ObjectMapper objectMapper) {

// -----------------------------------------------------------------------private methods

private static JsonNode readTree(ObjectMapper mapper, String body) {
private static JsonNode readTree(ObjectMapper objectMapper, String body) {
try {
return mapper.readTree(body);
return objectMapper.readTree(body);
} catch (JsonProcessingException e) {
return ExceptionUtils.rethrow(e);
}
}

private static Object parse(ObjectMapper mapper, JsonNode jsonNode, Type type) {
private static Object parse(ObjectMapper objectMapper, JsonNode jsonNode, Type type) {
try {
return mapper
.readerFor(mapper.getTypeFactory().constructType(type))
return objectMapper
.readerFor(objectMapper.getTypeFactory().constructType(type))
.with(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.readValue(mapper.treeAsTokens(jsonNode));
.readValue(objectMapper.treeAsTokens(jsonNode));
} catch (IOException e) {
return ExceptionUtils.rethrow(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int retried() {
public String toString() {
return new StringJoiner(", ", DispatchTaskParam.class.getSimpleName() + "[", "]")
.add("executeTaskParam=" + executeTaskParam)
.add(group == null ? "group=null" : "group='" + group + "'")
.add("group=" + (group != null ? "'" + group + "'" : "null"))
.add("retried=" + retried)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ private SupervisorMetricsResponse getMetrics(Supervisor supervisor) {
LOG.warn("Ping supervisor occur error: {} {}", supervisor, e.getMessage());
}

SupervisorMetricsResponse response = (metrics == null) ? new SupervisorMetricsResponse() : ServerMetricsConverter.INSTANCE.convert(metrics);
SupervisorMetricsResponse response;
if (metrics == null) {
response = new SupervisorMetricsResponse();
} else {
response = ServerMetricsConverter.INSTANCE.convert(metrics);
}

response.setHost(supervisor.getHost());
response.setPort(supervisor.getPort());
response.setPingTime(pingTime);
Expand All @@ -159,15 +165,16 @@ private WorkerMetricsResponse getMetrics(Worker worker) {
LOG.warn("Ping worker occur error: {} {}", worker, e.getMessage());
}

if (metrics != null && !SchedGroupService.verifyWorkerSignatureToken(metrics.getSignature(), group)) {
metrics = null;
WorkerMetricsResponse response;
if (metrics == null || !SchedGroupService.verifyWorkerSignatureToken(metrics.getSignature(), group)) {
response = new WorkerMetricsResponse(worker.getWorkerId());
} else {
response = ServerMetricsConverter.INSTANCE.convert(metrics);
}

WorkerMetricsResponse response = (metrics == null) ? new WorkerMetricsResponse() : ServerMetricsConverter.INSTANCE.convert(metrics);
response.setHost(worker.getHost());
response.setPort(worker.getPort());
response.setPingTime(pingTime);
response.setWorkerId(metrics != null ? metrics.getWorkerId() : worker.getWorkerId());
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package cn.ponfee.disjob.supervisor.application.response;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
Expand All @@ -18,6 +19,7 @@
*/
@Getter
@Setter
@NoArgsConstructor
public class WorkerMetricsResponse extends ServerMetricsResponse {
private static final long serialVersionUID = -8325148543854446360L;

Expand All @@ -34,4 +36,8 @@ public class WorkerMetricsResponse extends ServerMetricsResponse {
private Long queueTaskCount;
private Long completedTaskCount;

public WorkerMetricsResponse(String workerId) {
this.workerId = workerId;
}

}

0 comments on commit 2fe04bc

Please sign in to comment.