Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #368] Fix Racing condition and memory leak issue in EventMesh SDK LiteConsumer and LiteProducer #369

Merged
merged 16 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Issue #368] use try with resource statement for HttpClient
  • Loading branch information
jinrongluo committed May 27, 2021
commit 7fd537359293b93474ae1601fa60003bd4c7f2eb
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,9 @@ public boolean subscribe(List<String> topicList, String url) throws Exception {
long startTime = System.currentTimeMillis();
String target = selectEventMesh();
String subRes = "";
CloseableHttpClient httpClient = setHttpClient();
try {

try (CloseableHttpClient httpClient = setHttpClient()){
subRes = HttpUtil.post(httpClient, target, subscribeParam);
} catch (Exception ex) {
throw new EventMeshException(ex);
} finally {
httpClient.close();
}

if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -215,13 +211,9 @@ public void run() {
long startTime = System.currentTimeMillis();
String target = selectEventMesh();
String res = "";
CloseableHttpClient httpClient = setHttpClient();
try {

try (CloseableHttpClient httpClient = setHttpClient()) {
res = HttpUtil.post(httpClient, target, requestParam);
} catch (Exception ex) {
throw new EventMeshException(ex);
} finally {
httpClient.close();
}

if (logger.isDebugEnabled()) {
Expand All @@ -248,13 +240,9 @@ public boolean unsubscribe(List<String> topicList, String url) throws Exception
long startTime = System.currentTimeMillis();
String target = selectEventMesh();
String unSubRes = "";
CloseableHttpClient httpClient = setHttpClient();
try {

try (CloseableHttpClient httpClient = setHttpClient()) {
unSubRes = HttpUtil.post(httpClient, target, unSubscribeParam);
} catch (Exception ex) {
throw new EventMeshException(ex);
} finally {
httpClient.close();
}

if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,9 @@ public boolean publish(LiteMessage message) throws Exception {
long startTime = System.currentTimeMillis();
String target = selectEventMesh();
String res = "";
CloseableHttpClient httpClient = setHttpClient();
try {

try (CloseableHttpClient httpClient = setHttpClient()) {
res = HttpUtil.post(httpClient, target, requestParam);
} catch (Exception ex) {
throw new EventMeshException(ex);
} finally {
httpClient.close();
}

if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -188,13 +184,9 @@ public LiteMessage request(LiteMessage message, long timeout) throws Exception {
long startTime = System.currentTimeMillis();
String target = selectEventMesh();
String res = "";
CloseableHttpClient httpClient = setHttpClient();
try {

try (CloseableHttpClient httpClient = setHttpClient()) {
res = HttpUtil.post(httpClient, target, requestParam);
} catch (Exception ex) {
throw new EventMeshException(ex);
} finally {
httpClient.close();
}

if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -246,13 +238,9 @@ public void request(LiteMessage message, RRCallback rrCallback, long timeout) th

long startTime = System.currentTimeMillis();
String target = selectEventMesh();
CloseableHttpClient httpClient = setHttpClient();
try {

try (CloseableHttpClient httpClient = setHttpClient()) {
HttpUtil.post(httpClient, null, target, requestParam, new RRCallbackResponseHandlerAdapter(message, rrCallback, timeout));
} catch (Exception ex) {
throw new EventMeshException(ex);
} finally {
httpClient.close();
}

if (logger.isDebugEnabled()) {
Expand Down