18
18
19
19
import org .bson .util .annotations .Immutable ;
20
20
21
+ import java .text .DecimalFormat ;
21
22
import java .util .Collections ;
22
23
import java .util .HashSet ;
23
24
import java .util .Map ;
32
33
import static com .mongodb .ServerType .ShardRouter ;
33
34
import static com .mongodb .ServerType .StandAlone ;
34
35
import static com .mongodb .ServerType .Unknown ;
35
- import static java .util .concurrent .TimeUnit .MILLISECONDS ;
36
- import static java .util .concurrent .TimeUnit .NANOSECONDS ;
37
36
import static org .bson .util .Assertions .notNull ;
38
37
39
38
@@ -64,7 +63,7 @@ class ServerDescription {
64
63
private final int maxMessageSize ;
65
64
private final Tags tags ;
66
65
private final String setName ;
67
- private final long averagePingTimeNanos ;
66
+ private final long averageLatencyNanos ;
68
67
private final boolean ok ;
69
68
private final ServerConnectionState state ;
70
69
private final ServerVersion version ;
@@ -86,7 +85,7 @@ static class Builder {
86
85
private Tags tags = Tags .freeze (new Tags ());
87
86
private String setName ;
88
87
private Integer setVersion ;
89
- private long averagePingTimeNanos ;
88
+ private long averageLatency ;
90
89
private boolean ok ;
91
90
private ServerConnectionState state ;
92
91
private ServerVersion version = new ServerVersion ();
@@ -144,8 +143,8 @@ public Builder tags(final Tags tags) {
144
143
return this ;
145
144
}
146
145
147
- public Builder averagePingTime (final long averagePingTime , final TimeUnit timeUnit ) {
148
- this .averagePingTimeNanos = timeUnit .toNanos (averagePingTime );
146
+ public Builder averageLatency (final long averageLatency , final TimeUnit timeUnit ) {
147
+ this .averageLatency = timeUnit .toNanos (averageLatency );
149
148
return this ;
150
149
}
151
150
@@ -355,8 +354,8 @@ public Integer getSetVersion() {
355
354
return setVersion ;
356
355
}
357
356
358
- public long getAveragePingTimeNanos () {
359
- return averagePingTimeNanos ;
357
+ public long getAverageLatencyNanos () {
358
+ return averageLatencyNanos ;
360
359
}
361
360
362
361
/**
@@ -469,7 +468,7 @@ public String toString() {
469
468
+ ", tags=" + tags
470
469
+ ", setName='" + setName + '\''
471
470
+ ", setVersion='" + setVersion + '\''
472
- + ", averagePingTimeNanos =" + averagePingTimeNanos
471
+ + ", averageLatencyNanos =" + averageLatencyNanos
473
472
+ ", ok=" + ok
474
473
+ ", state=" + state
475
474
+ ", version=" + version
@@ -483,11 +482,15 @@ public String getShortDescription() {
483
482
+ "address=" + address
484
483
+ ", type=" + type
485
484
+ (tags .isEmpty () ? "" : tags )
486
- + (state == Connected ? (", averagePingTime =" + NANOSECONDS . convert ( averagePingTimeNanos , MILLISECONDS ) + " ms" ) : "" )
485
+ + (state == Connected ? (", averageLatency =" + getAverageLatencyFormattedInMilliseconds ( ) + " ms" ) : "" )
487
486
+ ", state=" + state
488
487
+ '}' ;
489
488
}
490
489
490
+ private String getAverageLatencyFormattedInMilliseconds () {
491
+ return new DecimalFormat ("#0.0" ).format (averageLatencyNanos / 1000.0 / 1000.0 );
492
+ }
493
+
491
494
ServerDescription (final Builder builder ) {
492
495
address = notNull ("address" , builder .address );
493
496
type = notNull ("type" , builder .type );
@@ -503,7 +506,7 @@ public String getShortDescription() {
503
506
tags = builder .tags ;
504
507
setName = builder .setName ;
505
508
setVersion = builder .setVersion ;
506
- averagePingTimeNanos = builder .averagePingTimeNanos ;
509
+ averageLatencyNanos = builder .averageLatency ;
507
510
ok = builder .ok ;
508
511
minWireVersion = builder .minWireVersion ;
509
512
maxWireVersion = builder .maxWireVersion ;
0 commit comments