Skip to content

Commit c7346ba

Browse files
authored
Fix the ClusterListener, ServerListener, ServerMonitorListener API docs relevant to thread-safety (#1208)
JAVA-5185
1 parent 92c90c6 commit c7346ba

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

driver-core/src/main/com/mongodb/event/ClusterListener.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
/**
2222
* A listener for cluster-related events.
2323
* <p>
24-
* It does not have to be thread-safe. All events received by {@link ClusterListener}, {@link ServerListener},
24+
* All events received by {@link ClusterListener}, {@link ServerListener},
2525
* {@link ServerMonitorListener} are totally ordered (and the event order implies the happens-before order), provided that the listeners
26-
* are not shared by different {@code MongoClient}s. This means that even if you have a single class implementing all of
27-
* {@link ClusterListener}, {@link ServerListener}, {@link ServerMonitorListener}, it does not have to be thread-safe.
26+
* are not shared by different {@code MongoClient}s. This guarantee holds even if you have a single class implementing
27+
* all of {@link ClusterListener}, {@link ServerListener}, {@link ServerMonitorListener}. However, this guarantee does not mean that
28+
* implementations automatically do not need to synchronize memory accesses to prevent data races.
29+
* For example, if data that the listener collects in memory is accessed outside of the normal execution of the listener
30+
* by the {@code MongoClient}, then reading and writing actions must be synchronized.
2831
* </p>
2932
* @see ServerListener
3033
* @see ServerMonitorListener

driver-core/src/main/com/mongodb/event/ServerListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* A listener for server-related events
2323
* <p>
24-
* It does not have to be thread-safe, see {@link ClusterListener} for the details regarding the order of events.
24+
* See {@link ClusterListener} for the details regarding the order of events and memory synchronization.
2525
* </p>
2626
* @see ClusterListener
2727
* @see ServerMonitorListener

driver-core/src/main/com/mongodb/event/ServerMonitorListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* A listener for server monitor-related events
2525
* <p>
26-
* It does not have to be thread-safe, see {@link ClusterListener} for the details regarding the order of events.
26+
* See {@link ClusterListener} for the details regarding the order of events and memory synchronization.
2727
* </p>
2828
* @see ClusterListener
2929
* @see ServerListener

0 commit comments

Comments
 (0)