-
Notifications
You must be signed in to change notification settings - Fork 582
637: Configurable correlatorId generation for RPCClient #638
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
Conversation
Change-Id: I17d7a214d3336ad6e5fe890857a48b457ea599b6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by comment. I don't know this code, so apologies if this feedback does not make sense for some reason.
@@ -79,12 +80,14 @@ | |||
} | |||
}; | |||
|
|||
public static Supplier<String> DEFAULT_CORRELATION_ID_GENERATOR = new IncrementingCorrelationIdGenerator(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As-is this static instance may be used by more than one RpcClient
instance. In that case Supplier#get
may be invoked concurrently, as the synchronized (_continuationMap)
block only ensures exclusive access for doCall
invocations on the same client. This is a problem because as-is IncrementingCorrelationIdGenerator
is not thread-safe.
One option would be to replace int _correlationId
with an AtomicInteger
(or perhaps more appropriately, an AtomicLong
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. This should not be static. Will remove that.
Change-Id: I3bb119f3f7debeb0d45ff81dc9154e26635f03bb
@@ -389,14 +389,6 @@ public String getRoutingKey() { | |||
return _continuationMap; | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change. The last correlation ID must be kept in some way, likely by keeping the _correlationId
property and update it in the synchronized block.
Change-Id: Ib1f90d5a25f1c5db32ff9c838cfbeb35aac5d671
if (_correlationIdGenerator instanceof IncrementingCorrelationIdGenerator) { | ||
return ((IncrementingCorrelationIdGenerator) _correlationIdGenerator).getCorrelationId(); | ||
} else { | ||
throw new UnsupportedOperationException(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super fan of this code TBH. Maybe keeping a reference to the last correlation ID (a string) and trying to convert it to an integer when getCorrelationId()
is called would do the job as well. This is a best-effort approach anyway, but it avoids relying on some implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is implementation is only there for BW compatiblity, So i don't think it's a problem that it only works for the 'default' id generator. I marked the method as deprecated anyway.
Thanks! |
Change-Id: I17d7a214d3336ad6e5fe890857a48b457ea599b6
Proposed Changes
#637
Types of Changes
What types of changes does your code introduce to this project?
Put an
x
in the boxes that applyDid remove the 'getCorrelatorId' method from RpcClient. Since i don't see a use for, did not bother adding compatiblity hacks
Checklist
Put an
x
in the boxes that apply. You can also fill these out after creatingthe PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.
CONTRIBUTING.md
documentTried it. But gave up after a few hours. I don't have time to troubleshoot all environment issues that pop up when trying to run the 'unit' tests
Further Comments