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 #446] Use strong reference avoid weak references recycled when GC occurs #4872

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ private void startClientGroupConsumer(Session session) throws Exception {
}
synchronized (lockMap.get(subsystem)) {
log.info("readySession session[{}]", session);
ClientGroupWrapper cgw = session.getClientGroupWrapper().get();

ClientGroupWrapper cgw = this.getClientGroupMap().get(session.getClient().getGroup());
boolean flag = cgw != null && cgw.addGroupConsumerSession(session);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key of clientGroupMap is subsystem, I'm not sure whether the group key here works well.

if (!flag) {
throw new Exception("addGroupConsumerSession fail");
Expand All @@ -279,14 +278,14 @@ private void startClientGroupConsumer(Session session) throws Exception {

private void cleanClientGroupWrapperByCloseSub(Session session) throws Exception {
cleanSubscriptionInSession(session);
ClientGroupWrapper clientGroupWrapper = Objects.requireNonNull(session.getClientGroupWrapper().get());
ClientGroupWrapper clientGroupWrapper = Objects.requireNonNull(this.getClientGroupMap().get(session.getClient().getGroup()));
clientGroupWrapper.removeGroupConsumerSession(session);
handleUnackMsgsInSession(session);
cleanClientGroupWrapperCommon(clientGroupWrapper);
}

private void cleanClientGroupWrapperByClosePub(Session session) throws Exception {
ClientGroupWrapper clientGroupWrapper = Objects.requireNonNull(session.getClientGroupWrapper().get());
ClientGroupWrapper clientGroupWrapper = Objects.requireNonNull(this.getClientGroupMap().get(session.getClient().getGroup()));
clientGroupWrapper.removeGroupProducerSession(session);
cleanClientGroupWrapperCommon(clientGroupWrapper);
}
Expand All @@ -298,7 +297,7 @@ private void cleanClientGroupWrapperByClosePub(Session session) throws Exception
*/
private void cleanSubscriptionInSession(Session session) throws Exception {
for (SubscriptionItem item : session.getSessionContext().getSubscribeTopics().values()) {
ClientGroupWrapper clientGroupWrapper = Objects.requireNonNull(session.getClientGroupWrapper().get());
ClientGroupWrapper clientGroupWrapper = Objects.requireNonNull(this.getClientGroupMap().get(session.getClient().getGroup()));
clientGroupWrapper.removeSubscription(item, session);
if (!clientGroupWrapper.hasSubscription(item.getTopic())) {
clientGroupWrapper.unsubscribe(item);
Expand All @@ -314,7 +313,7 @@ private void cleanSubscriptionInSession(Session session) throws Exception {
private void handleUnackMsgsInSession(Session session) {
// key: seq
ConcurrentHashMap<String, DownStreamMsgContext> unAckMsg = session.getPusher().getUnAckMsg();
ClientGroupWrapper clientGroupWrapper = Objects.requireNonNull(session.getClientGroupWrapper().get());
ClientGroupWrapper clientGroupWrapper = Objects.requireNonNull(this.getClientGroupMap().get(session.getClient().getGroup()));
if (unAckMsg.size() > 0 && !clientGroupWrapper.getGroupConsumerSessions().isEmpty()) {
for (Map.Entry<String, DownStreamMsgContext> entry : unAckMsg.entrySet()) {
DownStreamMsgContext downStreamMsgContext = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.eventmesh.runtime.acl.Acl;
import org.apache.eventmesh.runtime.boot.EventMeshTCPServer;
import org.apache.eventmesh.runtime.constants.EventMeshConstants;
import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper;
import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session;
import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.send.EventMeshTcpSendResult;
import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.send.EventMeshTcpSendStatus;
Expand Down Expand Up @@ -259,8 +260,9 @@ public void onException(OnExceptionContext context) {
// retry
UpStreamMsgContext upStreamMsgContext = new UpStreamMsgContext(
session, event, pkg.getHeader(), startTime, taskExecuteTime);
ClientGroupWrapper cgw = eventMeshTCPServer.getClientSessionGroupMapping().getClientGroupMap().get(session.getClient().getGroup());
Objects.requireNonNull(
session.getClientGroupWrapper().get()).getTcpRetryer()
cgw).getTcpRetryer()
.newTimeout(upStreamMsgContext, 10, TimeUnit.SECONDS);

session.getSender().getFailMsgCount().incrementAndGet();
Expand Down
Loading