You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/04/15 10:57:47 UTC
svn commit: r1467906 - in
/sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery:
ClusterView.java TopologyView.java impl/NoClusterDiscoveryService.java
Author: cziegeler
Date: Mon Apr 15 08:57:46 2013
New Revision: 1467906
URL: http://svn.apache.org/r1467906
Log:
Clarify contracts
Modified:
sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/ClusterView.java
sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/TopologyView.java
sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/impl/NoClusterDiscoveryService.java
Modified: sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/ClusterView.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/ClusterView.java?rev=1467906&r1=1467905&r2=1467906&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/ClusterView.java (original)
+++ sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/ClusterView.java Mon Apr 15 08:57:46 2013
@@ -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();
Modified: sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/TopologyView.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/TopologyView.java?rev=1467906&r1=1467905&r2=1467906&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/TopologyView.java (original)
+++ sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/TopologyView.java Mon Apr 15 08:57:46 2013
@@ -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();
}
Modified: sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/impl/NoClusterDiscoveryService.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/impl/NoClusterDiscoveryService.java?rev=1467906&r1=1467905&r2=1467906&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/impl/NoClusterDiscoveryService.java (original)
+++ sling/trunk/contrib/extensions/discovery/api/src/main/java/org/apache/sling/discovery/impl/NoClusterDiscoveryService.java Mon Apr 15 08:57:46 2013
@@ -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 i
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 i
}
public List<InstanceDescription> getInstances() {
- return instances;
+ return new LinkedList<InstanceDescription>(instances);
}
public String getId() {
@@ -163,12 +165,12 @@ public class NoClusterDiscoveryService i
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 i
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;
}