mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
06.12.2025 d7e652c1013c88be63967d2c849bd066f38cdd0c
opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationBroker.java
@@ -13,6 +13,7 @@
 *
 * Copyright 2006-2010 Sun Microsystems, Inc.
 * Portions Copyright 2011-2016 ForgeRock AS.
 * Portions Copyright 2025 Wren Security.
 */
package org.opends.server.replication.service;
@@ -3251,14 +3252,30 @@
    return monitor.getMonitorInstanceName();
  }
  /**
   * Updates the currently connected replication server reference.
   * <p>
   * If the new replication server differs from the previous one, this method will:
   * <ul>
   * <li>deregister the replication monitor associated with the old server,
   * <li>close the old replication session,
   * <li>and register a replication monitor for the new server.
   *
   * @param newRS The new {@link ConnectedRS} instance to set as the currently connected replication server.
   * @return The newly set {@link ConnectedRS} instance.
   */
  private ConnectedRS setConnectedRS(final ConnectedRS newRS)
  {
    final ConnectedRS oldRS = connectedRS.getAndSet(newRS);
    if (!oldRS.equals(newRS) && oldRS.isConnected())
    ConnectedRS oldRS = connectedRS.get();
    if (!oldRS.equals(newRS))
    {
      // monitor name is changing, deregister before registering again
      deregisterReplicationMonitor();
      oldRS.session.close();
      if (oldRS.isConnected())
      {
        oldRS.session.close();
      }
      connectedRS.set(newRS);
      registerReplicationMonitor();
    }
    return newRS;