From 67405dde9ba213331dab1fc46cb18c485070fd5b Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Fri, 05 Jun 2009 09:04:50 +0000
Subject: [PATCH] svn merge -r5333:5417 https://opends.dev.java.net/svn/opends/branches/b2.0

---
 opends/src/server/org/opends/server/replication/server/ReplicationServer.java |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
index a704537..348680a 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -45,6 +45,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -154,6 +155,8 @@
    */
   private static final DebugTracer TRACER = getTracer();
 
+  private static HashSet<Integer> localPorts = new HashSet<Integer>();
+
   /**
    * Creates a new Replication server using the provided configuration entry.
    *
@@ -216,6 +219,8 @@
     DirectoryServer.registerRestoreTaskListener(this);
     DirectoryServer.registerExportTaskListener(this);
     DirectoryServer.registerImportTaskListener(this);
+
+    localPorts.add(replicationPort);
   }
 
 
@@ -525,6 +530,8 @@
    */
   public void shutdown()
   {
+    localPorts.remove(replicationPort);
+
     if (shutdown)
       return;
 
@@ -1211,4 +1218,41 @@
   {
     remoteMonitorResponsesSemaphore.notifyAll();
   }
+
+  /**
+   * This method allows to check if the Replication Server given
+   * as the parameter is running in the local JVM.
+   *
+   * @param server   The Replication Server that should be checked.
+   *
+   * @return         a boolean indicating if the Replication Server given
+   *                 as the parameter is running in the local JVM.
+   */
+  public static boolean isLocalReplicationServer(String server)
+  {
+    int separator = server.lastIndexOf(':');
+    if (separator == -1)
+      return false;
+    int port = Integer.parseInt(server.substring(separator + 1));
+    String hostname = server.substring(0, separator);
+    try
+    {
+      InetAddress localAddr = InetAddress.getLocalHost();
+
+      if (localPorts.contains(port)
+          && (InetAddress.getByName(hostname).isLoopbackAddress() ||
+              InetAddress.getByName(hostname).equals(localAddr)))
+      {
+        return true;
+      }
+      else
+      {
+        return false;
+      }
+
+    } catch (UnknownHostException e)
+    {
+      return false;
+    }
+  }
 }

--
Gitblit v1.10.0