Skip to content

Commit

Permalink
[Java] Add flag on ClientSession to indicate there has been a request…
Browse files Browse the repository at this point in the history
… to close it
  • Loading branch information
JPWatson committed Apr 20, 2018
1 parent 16ed17b commit 6c7519b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ public class ClientSession
private final long id;
private final int responseStreamId;
private final String responseChannel;
private Publication responsePublication;
private final byte[] encodedPrincipal;
private final DirectBufferVector[] vectors = new DirectBufferVector[2];
private final DirectBufferVector messageBuffer = new DirectBufferVector();
private final SessionHeaderEncoder sessionHeaderEncoder = new SessionHeaderEncoder();
private final Cluster cluster;
private Publication responsePublication;
private boolean isClosing;

ClientSession(
final long sessionId,
Expand Down Expand Up @@ -107,6 +108,16 @@ public byte[] encodedPrincipal()
return encodedPrincipal;
}

/**
* Indicates that a request to close this session has been made.
*
* @return whether a request to close this session has been made.
*/
public boolean isClosing()
{
return isClosing;
}

/**
* Non-blocking publish of a partial buffer containing a message to a cluster.
*
Expand Down Expand Up @@ -145,6 +156,11 @@ void connect(final Aeron aeron)
responsePublication = aeron.addPublication(responseChannel, responseStreamId);
}

void markClosing()
{
this.isClosing = true;
}

void disconnect()
{
CloseHelper.close(responsePublication);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ public Collection<ClientSession> clientSessions()

public boolean closeSession(final long clusterSessionId)
{
if (sessionByIdMap.containsKey(clusterSessionId))
final ClientSession clientSession = sessionByIdMap.get(clusterSessionId);
if (clientSession != null && !clientSession.isClosing())
{
clientSession.markClosing();

serviceControlPublisher.closeSession(clusterSessionId);
return true;
}
Expand Down

0 comments on commit 6c7519b

Please sign in to comment.