This is an automated email from the ASF dual-hosted git repository.
kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new e57ee65 [Improvement] Optimized close of IO (#5336)
e57ee65 is described below
commit e57ee658e842ab8c5cd111f35cd6c71ed7065ecd
Author: luoyuan <[email protected]>
AuthorDate: Wed Apr 21 22:47:16 2021 +0800
[Improvement] Optimized close of IO (#5336)
* [improvement]modify all methods that refer to LogClientService in the
code.
* delete unused code
* [Improvement] Optimized close of IO
---
.../api/service/impl/ProjectServiceImpl.java | 1 -
.../common/utils/PropertyUtils.java | 9 +-------
.../server/log/LoggerRequestProcessor.java | 24 +++++++---------------
3 files changed, 8 insertions(+), 26 deletions(-)
diff --git
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
index 3365b94..dcc2374 100644
---
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
+++
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
@@ -24,7 +24,6 @@ import org.apache.dolphinscheduler.api.service.ProjectService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.UserType;
-import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.ProjectUser;
diff --git
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
index 199655e..0b417a4 100644
---
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
+++
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
@@ -57,19 +57,12 @@ public class PropertyUtils {
*/
public static synchronized void loadPropertyFile(String... propertyFiles) {
for (String fileName : propertyFiles) {
- InputStream fis = null;
- try {
- fis = PropertyUtils.class.getResourceAsStream(fileName);
+ try (InputStream fis =
PropertyUtils.class.getResourceAsStream(fileName);) {
properties.load(fis);
} catch (IOException e) {
logger.error(e.getMessage(), e);
- if (fis != null) {
- IOUtils.closeQuietly(fis);
- }
System.exit(1);
- } finally {
- IOUtils.closeQuietly(fis);
}
}
}
diff --git
a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessor.java
b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessor.java
index c9350bf..f6e23f0 100644
---
a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessor.java
+++
b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessor.java
@@ -17,7 +17,6 @@
package org.apache.dolphinscheduler.server.log;
-import org.apache.dolphinscheduler.common.utils.IOUtils;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.common.utils.LoggerUtils;
import org.apache.dolphinscheduler.remote.command.Command;
@@ -44,9 +43,6 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -56,7 +52,7 @@ import org.slf4j.LoggerFactory;
import io.netty.channel.Channel;
/**
- * logger request process logic
+ * logger request process logic
*/
public class LoggerRequestProcessor implements NettyRequestProcessor {
@@ -139,11 +135,8 @@ public class LoggerRequestProcessor implements
NettyRequestProcessor {
* @throws Exception exception
*/
private byte[] getFileContentBytes(String filePath) {
- InputStream in = null;
- ByteArrayOutputStream bos = null;
- try {
- in = new FileInputStream(filePath);
- bos = new ByteArrayOutputStream();
+ try (InputStream in = new FileInputStream(filePath);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) != -1) {
@@ -151,10 +144,7 @@ public class LoggerRequestProcessor implements
NettyRequestProcessor {
}
return bos.toByteArray();
} catch (IOException e) {
- logger.error("get file bytes error",e);
- } finally {
- IOUtils.closeQuietly(bos);
- IOUtils.closeQuietly(in);
+ logger.error("get file bytes error", e);
}
return new byte[0];
}
@@ -168,14 +158,14 @@ public class LoggerRequestProcessor implements
NettyRequestProcessor {
* @return part file content
*/
private List<String> readPartFileContent(String filePath,
- int skipLine,
- int limit) {
+ int skipLine,
+ int limit) {
File file = new File(filePath);
if (file.exists() && file.isFile()) {
try (Stream<String> stream = Files.lines(Paths.get(filePath))) {
return
stream.skip(skipLine).limit(limit).collect(Collectors.toList());
} catch (IOException e) {
- logger.error("read file error",e);
+ logger.error("read file error", e);
}
} else {
logger.info("file path: {} not exists", filePath);