From 950cfbfa7d895b728f432500027df274d6b1d6c7 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 05 Mar 2013 16:50:35 +0000
Subject: [PATCH] OPENDJ-66 (CR-1365) DS does not failover between replication servers in different groups when configured explicitly for one of the groups
---
opends/src/server/org/opends/server/util/StaticUtils.java | 96 ++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 88 insertions(+), 8 deletions(-)
diff --git a/opends/src/server/org/opends/server/util/StaticUtils.java b/opends/src/server/org/opends/server/util/StaticUtils.java
index b6a252a..1910b2b 100644
--- a/opends/src/server/org/opends/server/util/StaticUtils.java
+++ b/opends/src/server/org/opends/server/util/StaticUtils.java
@@ -27,21 +27,41 @@
*/
package org.opends.server.util;
-import static org.opends.messages.CoreMessages.*;
-import static org.opends.messages.UtilityMessages.*;
-import static org.opends.server.loggers.debug.DebugLogger.*;
-import static org.opends.server.util.ServerConstants.*;
-
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
-import java.net.*;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.NetworkInterface;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.RandomAccess;
+import java.util.StringTokenizer;
+import java.util.TimeZone;
import org.opends.messages.Message;
import org.opends.messages.MessageBuilder;
@@ -66,6 +86,11 @@
import org.opends.server.util.args.Argument;
import org.opends.server.util.args.ArgumentException;
+import static org.opends.messages.CoreMessages.*;
+import static org.opends.messages.UtilityMessages.*;
+import static org.opends.server.loggers.debug.DebugLogger.*;
+import static org.opends.server.util.ServerConstants.*;
+
/**
* This class defines a number of static utility methods that may be used
@@ -4612,5 +4637,60 @@
}
}
}
+
+ /**
+ * Returns an {@link Iterable} returning the passed in {@link Iterator}. THis
+ * allows using methods returning Iterators with foreach statements.
+ * <p>
+ * For example, consider a method with this signature:
+ * <p>
+ * <code>public Iterator<String> myIteratorMethod();</code>
+ * <p>
+ * Classical use with for or while loop:
+ *
+ * <pre>
+ * for (Iterator<String> it = myIteratorMethod(); it.hasNext();)
+ * {
+ * String s = it.next();
+ * // use it
+ * }
+ *
+ * Iterator<String> it = myIteratorMethod();
+ * while(it.hasNext();)
+ * {
+ * String s = it.next();
+ * // use it
+ * }
+ * </pre>
+ *
+ * Improved use with foreach:
+ *
+ * <pre>
+ * for (String s : StaticUtils.toIterable(myIteratorMethod()))
+ * {
+ * }
+ * </pre>
+ *
+ * </p>
+ *
+ * @param <T>
+ * the generic type of the passed in Iterator and for the returned
+ * Iterable.
+ * @param iterator
+ * the Iterator that will be returned by the Iterable.
+ * @return an Iterable returning the passed in Iterator
+ */
+ public static <T> Iterable<T> toIterable(final Iterator<T> iterator)
+ {
+ return new Iterable<T>()
+ {
+
+ @Override
+ public Iterator<T> iterator()
+ {
+ return iterator;
+ }
+ };
+ }
}
--
Gitblit v1.10.0