Skip to content

Commit

Permalink
Add toMillis() private method at ClientConnectionTimings
Browse files Browse the repository at this point in the history
  • Loading branch information
Leewongi0731 committed May 7, 2024
2 parents e2027e2 + 3a3652c commit 43eca15
Showing 1 changed file with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ public long dnsResolutionStartTimeMicros() {
* @return the start time, or {@code -1} if there was no action to resolve a domain name.
*/
public long dnsResolutionStartTimeMillis() {
if (dnsResolutionStartTimeMicros >= 0) {
return TimeUnit.MICROSECONDS.toMillis(dnsResolutionStartTimeMicros);
}
return -1;
return toMillis(dnsResolutionStartTimeMicros);
}

/**
Expand All @@ -138,10 +135,7 @@ public long socketConnectStartTimeMicros() {
* @return the start time, or {@code -1} if there was no action to connect to a remote peer.
*/
public long socketConnectStartTimeMillis() {
if (socketConnectStartTimeMicros >= 0) {
return TimeUnit.MICROSECONDS.toMillis(socketConnectStartTimeMicros);
}
return -1;
return toMillis(socketConnectStartTimeMicros);
}

/**
Expand All @@ -168,10 +162,7 @@ public long tlsHandshakeStartTimeMicros() {
* @return the start time, or {@code -1} if there was no action to TLS handshake.
*/
public long tlsHandshakeStartTimeMillis() {
if (tlsHandshakeStartTimeMicros >= 0) {
return TimeUnit.MICROSECONDS.toMillis(tlsHandshakeStartTimeMicros);
}
return -1;
return toMillis(tlsHandshakeStartTimeMicros);
}

/**
Expand Down Expand Up @@ -200,10 +191,7 @@ public long pendingAcquisitionStartTimeMicros() {
* @return the start time, or {@code -1} if there was no action to get a pending connection.
*/
public long pendingAcquisitionStartTimeMillis() {
if (pendingAcquisitionStartTimeMicros >= 0) {
return TimeUnit.MICROSECONDS.toMillis(pendingAcquisitionStartTimeMicros);
}
return -1;
return toMillis(pendingAcquisitionStartTimeMicros);
}

/**
Expand Down Expand Up @@ -255,4 +243,11 @@ public String toString() {
buf.append('}');
return buf.toString();
}

private static long toMillis(long micro) {
if (micro >= 0) {
return TimeUnit.MICROSECONDS.toMillis(micro);
}
return -1;
}
}

0 comments on commit 43eca15

Please sign in to comment.