rishabhdaim commented on code in PR #295: URL: https://github.com/apache/jackrabbit-oak/pull/295#discussion_r963474776
########## oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/MongoConnection.java: ########## @@ -300,4 +324,61 @@ public static ReadConcernLevel readConcernLevel(ReadConcern readConcern) { return ReadConcernLevel.fromString(readConcern.asDocument().getString("level").getValue()); } } + + /** + * Returns {@code true} if the MongoDB server is part of a Replica Set, + * {@code false} otherwise. The Replica Set Status is achieved by the + * ReplicaSetStatusListener, which is triggered whenever the cluster + * description changes. + * + * @param client the mongo client. + * @return {@code true} if part of Replica Set, {@code false} otherwise. + */ + public static boolean isReplicaSet(@NotNull MongoClient client) { + MongoClusterListener listener = getOakClusterListener(client); + if (listener != null) { + return listener.isReplicaSet(); + } + LOG.warn("Method isReplicaSet called for a MongoClient without any OakClusterListener!"); + return false; + } + + /** + * Returns the {@ServerAddress} of the MongoDB cluster. + * + * @param client the mongo client. + * @return {@ServerAddress} of the cluster. {@null} if not connected or no listener was available. + */ + public static ServerAddress getAddress(@NotNull MongoClient client) { + MongoClusterListener listener = getOakClusterListener(client); + if (listener != null) { + return listener.getServerAddress(); + } + LOG.warn("Method getAddress called for a MongoClient without any OakClusterListener!"); + return null; + } + + /** + * Returns the {@ServerAddress} of the MongoDB cluster primary node. + * + * @param client the mongo client. + * @return {@ServerAddress} of the primary. {@null} if not connected or no listener was available. + */ + public static ServerAddress getPrimaryAddress(@NotNull MongoClient client) { + MongoClusterListener listener = getOakClusterListener(client); + if (listener != null) { + return listener.getPrimaryAddress(); + } + return null; + } + + private static MongoClusterListener getOakClusterListener(@NotNull MongoClient client) { Review Comment: Make the return type of this API optional and make the client use fluent coding api's. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org