This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.api-1.0.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-api.git

commit 0e6b1ef0043399347a13ca2f1329bfc2c3fb835a
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Mon Apr 15 08:57:46 2013 +0000

    Clarify contracts
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/discovery/api@1467906
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/discovery/ClusterView.java    | 11 ++++++--
 .../org/apache/sling/discovery/TopologyView.java   | 29 +++++++++++++---------
 .../discovery/impl/NoClusterDiscoveryService.java  | 16 ++++++------
 3 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/apache/sling/discovery/ClusterView.java 
b/src/main/java/org/apache/sling/discovery/ClusterView.java
index a12424d..64744a1 100644
--- a/src/main/java/org/apache/sling/discovery/ClusterView.java
+++ b/src/main/java/org/apache/sling/discovery/ClusterView.java
@@ -35,8 +35,12 @@ public interface ClusterView {
     String getId();
 
     /**
-     * Provides the list of InstanceDescriptions ordered by Sling Id.
-     * @return the list of InstanceDescriptions ordered by Sling Id
+     * Provides the list of InstanceDescriptions with a stable ordering.
+     * <p>
+     * Stable ordering implies that unless an instance leaves the cluster
+     * (due to shutdown/crash/network problems) the instance keeps the
+     * relative position in the list.
+     * @return the list of InstanceDescriptions (with a stable ordering)
      */
     List<InstanceDescription> getInstances();
 
@@ -44,6 +48,9 @@ public interface ClusterView {
         * Provides the InstanceDescription belonging to the leader instance.
         * <p>
         * Every ClusterView is guaranteed to have one and only one leader.
+        * <p>
+        * The leader is stable: once a leader is elected it stays leader
+        * unless it leaves the cluster (due to shutdown/crash/network problems)
         * @return the InstanceDescription belonging to the leader instance
         */
     InstanceDescription getLeader();
diff --git a/src/main/java/org/apache/sling/discovery/TopologyView.java 
b/src/main/java/org/apache/sling/discovery/TopologyView.java
index 0e8f1aa..8b95f79 100644
--- a/src/main/java/org/apache/sling/discovery/TopologyView.java
+++ b/src/main/java/org/apache/sling/discovery/TopologyView.java
@@ -20,6 +20,7 @@ package org.apache.sling.discovery;
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Set;
 
 /**
  * A topology view is a cross-cluster list of instances and clusters
@@ -39,30 +40,34 @@ public interface TopologyView {
        boolean isCurrent();
 
        /**
-        * Provides the InstanceDescription belonging to *this* instance.
-        * @return the InstanceDescription belonging to *this* instance
+        * Provides the InstanceDescription belonging to <b>this</b> instance.
+        * @return the InstanceDescription belonging to <b>this</b> instance
         */
        InstanceDescription getOwnInstance();
 
     /**
-     * Provides the list of InstanceDescriptions ordered by Sling Id.
-     * @return the list of InstanceDescriptions ordered by Sling Id or null if 
there are no instances
+     * Provides the set of InstanceDescriptions in the entire topology,
+     * without any particular order
+     * @return the set of InstanceDescriptions in the entire topology,
+     * without any particular order
      */
-       List<InstanceDescription> getInstances();
+       Set<InstanceDescription> getInstances();
 
        /**
-        * Search the current topology for instances which the provided 
InstancePicker has accepted.
+        * Searches through this topology and picks those accepted by the 
provided
+        * <code>InstanceFilter</code> - and returns them without any 
particular order
         * @param filter the filter to use
-        * @return the list of InstanceDescriptions which were accepted by the 
InstanceFilter
+        * @return the set of InstanceDescriptions which were accepted by the 
InstanceFilter,
+        * without any particular order
         */
-       List<InstanceDescription> findInstances(InstanceFilter filter);
+       Set<InstanceDescription> findInstances(InstanceFilter filter);
 
     /**
      * Provides the collection of ClusterViews.
      * <p>
-     * Note that all InstanceDescriptions belong to a ClusterView, even if 
-     * they are only a "cluster of 1" (ie not really a cluster).
-     * @return the collection of ClusterViews
+     * Note that all InstanceDescriptions belong to exactly one ClusterView - 
+     * including InstanceDescriptions that form "a cluster of 1"
+     * @return the set of ClusterViews, without any particular order
      */
-       Collection<ClusterView> getClusterViews();
+       Set<ClusterView> getClusterViews();
 }
diff --git 
a/src/main/java/org/apache/sling/discovery/impl/NoClusterDiscoveryService.java 
b/src/main/java/org/apache/sling/discovery/impl/NoClusterDiscoveryService.java
index 8f6fd55..555f118 100644
--- 
a/src/main/java/org/apache/sling/discovery/impl/NoClusterDiscoveryService.java
+++ 
b/src/main/java/org/apache/sling/discovery/impl/NoClusterDiscoveryService.java
@@ -23,10 +23,12 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
@@ -133,7 +135,7 @@ public class NoClusterDiscoveryService implements 
DiscoveryService {
                                return clusters.iterator().next();
                        }
         };
-        final List<InstanceDescription> instances = new 
ArrayList<InstanceDescription>();
+        final Set<InstanceDescription> instances = new 
HashSet<InstanceDescription>();
         instances.add(myDescription);
 
         final DiscoveryAware[] registeredServices;
@@ -146,7 +148,7 @@ public class NoClusterDiscoveryService implements 
DiscoveryService {
                 }
 
                 public List<InstanceDescription> getInstances() {
-                    return instances;
+                    return new LinkedList<InstanceDescription>(instances);
                 }
 
                                public String getId() {
@@ -163,12 +165,12 @@ public class NoClusterDiscoveryService implements 
DiscoveryService {
                                return true;
                        }
 
-                       public List<InstanceDescription> getInstances() {
+                       public Set<InstanceDescription> getInstances() {
                                return instances;
                        }
 
-                       public List<InstanceDescription> 
findInstances(InstanceFilter picker) {
-                               List<InstanceDescription> result = new 
LinkedList<InstanceDescription>();
+                       public Set<InstanceDescription> 
findInstances(InstanceFilter picker) {
+                               Set<InstanceDescription> result = new 
HashSet<InstanceDescription>();
                                for (Iterator<InstanceDescription> it = 
getTopology().getInstances().iterator(); it.hasNext();) {
                                        InstanceDescription instance = 
it.next();
                                        if (picker.accept(instance)) {
@@ -178,8 +180,8 @@ public class NoClusterDiscoveryService implements 
DiscoveryService {
                                return result;
                        }
 
-                       public List<ClusterView> getClusterViews() {
-                               LinkedList<ClusterView> clusters = new 
LinkedList<ClusterView>();
+                       public Set<ClusterView> getClusterViews() {
+                               Set<ClusterView> clusters = new 
HashSet<ClusterView>();
                                clusters.add(clusterView);
                                return clusters;
                        }

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to