-
Notifications
You must be signed in to change notification settings - Fork 150
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
Add a flushBuffer API #380
Conversation
Signed-off-by: Colin Sullivan <colin@synadia.com>
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.
I'd raise the underlying exception.
try { | ||
dataPort.flush(); | ||
} catch (Exception e) { | ||
// NOOP |
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.
pass it along? technically you don't know if it got flushed
@@ -29,6 +29,9 @@ | |||
|
|||
import io.nats.client.Options; | |||
|
|||
/** | |||
* This class is not theadsafe. Caller must ensure thread safety. | |||
*/ | |||
public class SocketDataPort implements DataPort { |
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.
private class?
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.
I'm not sure why it was public, perhaps for testing. Good point though. I might take a pass through the classes outside of this PR.
/** | ||
* Immediately flushes the underlying connection buffer if the connection is valid. | ||
*/ | ||
public void flushBuffer(); |
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.
throws IOException?
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.
I was on the fence, but yeah - probably good to let the user handle that.
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.
LGTM
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.
looks ok to me, haven't been in Java for a bit, my only concern is that it works with all the NIO work someone was doing but if this is rebased on that 👍
Signed-off-by: Colin Sullivan <colin@synadia.com>
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.
LGTM
This PR adds a flush buffer API to flush the underlying socket (through the socket output stream).
I did use a synchronized API on the connection writer because research seemed to indicate the best performance with a smaller number of threads - at least in older versions of java. It also fit well with the current architecture since there is no connection level locking. Instead publish synchronization resolves around the message writer and message queue. There's a small chance when publishing and immediately doing a flushBuffer, the flushBuffer will beat the message writer, but without major surgery I'm not sure how to fix that.
Regardless, I was able to exceed capacity of the underlying message queue unless I flushed in the test itself so performance doesn't seem to be impacted much.
CC /@scottf @RichardHightower
Signed-off-by: Colin Sullivan colin@synadia.com