Browse Source

Pull request #1: DEC-15615 fix: 连接没有及时释放导致连接池占满

Merge in PG2/plugin-repository-s3 from ~ZED/plugin-repository-s3:master to master

* commit '76eda8c29a53401655d0ba87d6dd5a0c97a9e307':
  DEC-15615 fix: 连接没有及时释放导致连接池占满
master
zed 4 years ago
parent
commit
9955d99b59
  1. 3
      plugin.xml
  2. 42
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

3
plugin.xml

@ -5,12 +5,13 @@
<main-package>com.fanruan.fs</main-package> <main-package>com.fanruan.fs</main-package>
<active>yes</active> <active>yes</active>
<hidden>no</hidden> <hidden>no</hidden>
<version>1.2.0</version> <version>1.2.1</version>
<env-version>10.0</env-version> <env-version>10.0</env-version>
<jartime>2020-01-27</jartime> <jartime>2020-01-27</jartime>
<vendor>richie</vendor> <vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description> <description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description>
<change-notes><![CDATA[ <change-notes><![CDATA[
[2020-10-29]修复连接不释放问题。<br/>
[2020-08-17]修复key不存在时报错的问题。<br/> [2020-08-17]修复key不存在时报错的问题。<br/>
[2020-07-09]修复zip文件上传之后为空的问题。<br/> [2020-07-09]修复zip文件上传之后为空的问题。<br/>
[2020-07-06]修复华为云OBS显示的问。<br> [2020-07-06]修复华为云OBS显示的问。<br>

42
src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

@ -60,10 +60,15 @@ public class S3ResourceRepository extends BaseResourceRepository {
GetObjectRequest request = new GetObjectRequest(bucket, path); GetObjectRequest request = new GetObjectRequest(bucket, path);
try { try {
S3Object s3Object = s3.getObject(request); S3Object s3Object = s3.getObject(request);
try {
return s3Object2FileEntry(s3Object, path); return s3Object2FileEntry(s3Object, path);
} finally {
s3Object.close();
}
} catch (Exception e) { } catch (Exception e) {
LogKit.info("{} not exist!", path); LogKit.info("{} not exist!", path);
} }
return null; return null;
} }
@ -116,7 +121,12 @@ public class S3ResourceRepository extends BaseResourceRepository {
public InputStream read(String filePath) throws ResourceIOException { public InputStream read(String filePath) throws ResourceIOException {
GetObjectRequest request = new GetObjectRequest(bucket, filePath); GetObjectRequest request = new GetObjectRequest(bucket, filePath);
try { try {
return s3.getObject(request).getObjectContent(); S3Object s3Object = s3.getObject(request);
try {
return s3Object.getObjectContent();
} finally {
s3Object.close();
}
} catch (Exception e) { } catch (Exception e) {
return new ByteArrayInputStream(new byte[0]); return new ByteArrayInputStream(new byte[0]);
} }
@ -234,20 +244,38 @@ public class S3ResourceRepository extends BaseResourceRepository {
@Override @Override
public long lastModified(String path) { public long lastModified(String path) {
try {
S3Object s3Object = s3.getObject(bucket, path); S3Object s3Object = s3.getObject(bucket, path);
if (s3Object == null) { if (s3Object != null) {
return -1L; try {
}
return s3Object.getObjectMetadata().getLastModified().getTime(); return s3Object.getObjectMetadata().getLastModified().getTime();
} finally {
s3Object.close();
}
}
} catch (Exception e) {
LogKit.info("{} not exist!", path);
}
return -1L;
} }
@Override @Override
public long length(String path) { public long length(String path) {
try {
S3Object s3Object = s3.getObject(bucket, path); S3Object s3Object = s3.getObject(bucket, path);
if (s3Object == null) { if (s3Object != null) {
return -1L; try {
}
return s3Object.getObjectMetadata().getContentLength(); return s3Object.getObjectMetadata().getContentLength();
} finally {
s3Object.close();
}
}
} catch (Exception e) {
LogKit.info("{} not exist!", path);
}
return -1L;
} }
@Override @Override

Loading…
Cancel
Save