Conversation
|
|
||
| timeTraceLogger.trace("setting status to connecting"); | ||
| updateStatus(Status.CONNECTING); | ||
| updateStatus(Status.CONNECTING, resolved, cur); |
There was a problem hiding this comment.
cur is the NatsUri from the server pool. resolved is either cur or a host resolved to an ip address
| } | ||
|
|
||
| processConnectionEvent(Events.RESUBSCRIBED); | ||
| processConnectionEvent(Events.RESUBSCRIBED, uriDetail(currentServer)); |
There was a problem hiding this comment.
uri detail is a helper that converts the parameter to a string, making sure it's not null. Just a macro so I didn't have to have a lot of if == null checks
| } | ||
| else { | ||
| double seconds = ((double)-remainingNanos) / 1_000_000_000.0; | ||
| double seconds = ((double) -remainingNanos) / 1_000_000_000.0; |
There was a problem hiding this comment.
Um, thanks intellij?
| // writer.stop | ||
| void tryToConnect(NatsUri cur, NatsUri resolved, long now) { | ||
| currentServer = null; | ||
| clearCurrentServer(); |
There was a problem hiding this comment.
clearCurrentServer sets current server to null after setting the lastServer variable, which helps reporting statuses during re/connect when current server needs to be null.
| // https://github.com/nats-io/nats.java#linux-platform-note | ||
| timeTraceLogger.trace("TLS upgrade took: %.3f (s)", | ||
| ((double) (NatsSystemClock.nanoTime() - start)) / NANOS_PER_SECOND); | ||
| ((double) (NatsSystemClock.nanoTime() - start)) / NANOS_PER_SECOND); |
There was a problem hiding this comment.
again, thanks intellij
| future.get(timeoutNanos, TimeUnit.NANOSECONDS); | ||
| } finally { | ||
| } | ||
| finally { |
There was a problem hiding this comment.
I must have formatted this entire method.
| private void clearCurrentServer() { | ||
| if (currentServer != null) { | ||
| lastServer = currentServer; | ||
| } |
There was a problem hiding this comment.
I know this looks weird, but this makes sure lastServer is retained when clearServer is called when currentServer is already null, it can happen.
| if (!urls.isEmpty()) { | ||
| if (serverPool.acceptDiscoveredUrls(urls)) { | ||
| processConnectionEvent(Events.DISCOVERED_SERVERS); | ||
| processConnectionEvent(Events.DISCOVERED_SERVERS, urls.toString()); |
There was a problem hiding this comment.
now the connection event can see the discovered servers
|
|
||
| if (serverInfo.isLameDuckMode()) { | ||
| processConnectionEvent(Events.LAME_DUCK); | ||
| processConnectionEvent(Events.LAME_DUCK, uriDetail(currentServer)); |
There was a problem hiding this comment.
can see the server being lame ducked
| this.callbackRunner.execute(() -> { | ||
| try { | ||
| listener.connectionEvent(this, type); | ||
| listener.connectionEvent(this, type, uriDetails); |
There was a problem hiding this comment.
This is the call to the new method in the ConnectionListener
| */ | ||
| default void connectionEvent(Connection conn, Events type, String uriDetails) { | ||
| connectionEvent(conn, type); | ||
| } |
There was a problem hiding this comment.
default impl required for backward compatibility. I've verified that there is no issue, I have lambda implementations of connection listener in unit tests, examples, tons of my scratch classes that are not checked in, etc. so I know this is safe to do and won't break anyone.
A new method with a default implementation is added to ConnectionListener. The caller of connection listeners now calls the new method allowing implementors to have extra details about the uri related to this connection event. This information was not always available from the Connection object server info, for instance on reconnect, the connection will be stale, and the details contain information about the uri trying to be connected to and the host uri if the try to connect uri is an ip address resolved from the host uri.