jchen21 commented on a change in pull request #7206:
URL: https://github.com/apache/geode/pull/7206#discussion_r771041033
##########
File path:
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientUserAuths.java
##########
@@ -97,21 +93,20 @@ public long putSubject(@NotNull Subject subject, long
existingUniqueId) {
return newId;
}
- public ClientUserAuths(int clientProxyHashcode) {
- m_seed = clientProxyHashcode;
- uniqueIdGenerator = new Random(m_seed + System.currentTimeMillis());
- m_firstId = uniqueIdGenerator.nextLong();
+ public ClientUserAuths(SubjectIdGenerator idGenerator) {
+ this.idGenerator = idGenerator;
}
- synchronized long getNextID() {
- final long uniqueId = uniqueIdGenerator.nextLong();
- if (uniqueId == m_firstId) {
- uniqueIdGenerator = new Random(m_seed + System.currentTimeMillis());
- m_firstId = uniqueIdGenerator.nextLong();
+ private synchronized long getNextID() {
+ long uniqueId = idGenerator.generateId();
+ if (uniqueId == 0) {
+ uniqueId = idGenerator.generateId();
+ }
+ if (uniqueId == -1) {
// now every user need to reauthenticate as we are short of Ids..
// though possibility of this is rare.
uniqueIdVsUserAuth.clear();
- return m_firstId;
+ return idGenerator.generateId();
Review comment:
What if `idGenerator.generateId()` return `-1` again? Chances are very
slim though.
##########
File path:
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientUserAuths.java
##########
@@ -97,21 +93,20 @@ public long putSubject(@NotNull Subject subject, long
existingUniqueId) {
return newId;
}
- public ClientUserAuths(int clientProxyHashcode) {
- m_seed = clientProxyHashcode;
- uniqueIdGenerator = new Random(m_seed + System.currentTimeMillis());
- m_firstId = uniqueIdGenerator.nextLong();
+ public ClientUserAuths(SubjectIdGenerator idGenerator) {
+ this.idGenerator = idGenerator;
}
- synchronized long getNextID() {
- final long uniqueId = uniqueIdGenerator.nextLong();
- if (uniqueId == m_firstId) {
- uniqueIdGenerator = new Random(m_seed + System.currentTimeMillis());
- m_firstId = uniqueIdGenerator.nextLong();
+ private synchronized long getNextID() {
+ long uniqueId = idGenerator.generateId();
+ if (uniqueId == 0) {
+ uniqueId = idGenerator.generateId();
+ }
+ if (uniqueId == -1) {
Review comment:
If you would, you can refer to `IDS_EXHAUSTED`.
##########
File path:
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientUserAuths.java
##########
@@ -97,21 +93,20 @@ public long putSubject(@NotNull Subject subject, long
existingUniqueId) {
return newId;
}
- public ClientUserAuths(int clientProxyHashcode) {
- m_seed = clientProxyHashcode;
- uniqueIdGenerator = new Random(m_seed + System.currentTimeMillis());
- m_firstId = uniqueIdGenerator.nextLong();
+ public ClientUserAuths(SubjectIdGenerator idGenerator) {
+ this.idGenerator = idGenerator;
}
- synchronized long getNextID() {
- final long uniqueId = uniqueIdGenerator.nextLong();
- if (uniqueId == m_firstId) {
- uniqueIdGenerator = new Random(m_seed + System.currentTimeMillis());
- m_firstId = uniqueIdGenerator.nextLong();
+ private synchronized long getNextID() {
+ long uniqueId = idGenerator.generateId();
+ if (uniqueId == 0) {
+ uniqueId = idGenerator.generateId();
Review comment:
What if `idGenerator.generateId()` return `0` again? Chances are very
slim though.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]