3030 * A connection that tracks when it was opened and when it was last used.
3131 */
3232class UsageTrackingConnection implements Connection {
33- private volatile long openedAt = Long . MAX_VALUE ;
34- private volatile long lastUsedAt = Long . MAX_VALUE ;
33+ private final long openedAt ;
34+ private volatile long lastUsedAt ;
3535 private final int generation ;
3636 private volatile Connection wrapped ;
37- private volatile boolean isOpen ;
3837
3938 UsageTrackingConnection (final Connection wrapped , final int generation ) {
4039 this .wrapped = wrapped ;
4140 this .generation = generation ;
41+ openedAt = System .currentTimeMillis ();
42+ lastUsedAt = openedAt ;
4243 }
4344
4445 @ Override
@@ -58,16 +59,6 @@ public ServerAddress getServerAddress() {
5859 return wrapped .getServerAddress ();
5960 }
6061
61- @ Override
62- public void open () {
63- if (!isOpen ) {
64- wrapped .open ();
65- isOpen = true ;
66- openedAt = System .currentTimeMillis ();
67- lastUsedAt = openedAt ;
68- }
69- }
70-
7162 @ Override
7263 public void sendMessage (final List <ByteBuf > byteBuffers ) {
7364 wrapped .sendMessage (byteBuffers );
@@ -83,6 +74,7 @@ public ResponseBuffers receiveMessage(final ResponseSettings responseSettings) {
8374
8475 /**
8576 * Gets the generation of this connection. This can be used by connection pools to track whether the connection is stale.
77+ *
8678 * @return the generation.
8779 */
8880 int getGeneration () {
@@ -91,6 +83,7 @@ int getGeneration() {
9183
9284 /**
9385 * Returns the time at which this connection was opened, or {@code Long.MAX_VALUE} if it has not yet been opened.
86+ *
9487 * @return the time when this connection was opened, in milliseconds since the epoch.
9588 */
9689 long getOpenedAt () {
@@ -99,6 +92,7 @@ long getOpenedAt() {
9992
10093 /**
10194 * Returns the time at which this connection was last used, or {@code Long.MAX_VALUE} if it has not yet been used.
95+ *
10296 * @return the time when this connection was last used, in milliseconds since the epoch.
10397 */
10498 long getLastUsedAt () {
0 commit comments