Class DefaultClusterView
- java.lang.Object
-
- org.apache.sling.discovery.commons.providers.DefaultClusterView
-
- All Implemented Interfaces:
ClusterView
- Direct Known Subclasses:
LocalClusterView
public class DefaultClusterView extends java.lang.Object implements ClusterView
Default implementation of the ClusterView interface.Besides implementing the interface methods it also adds add/remove of InstanceDescriptions as well as implementing equals and hashCode.
-
-
Constructor Summary
Constructors Constructor Description DefaultClusterView(java.lang.String id)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addInstanceDescription(DefaultInstanceDescription instance)
Add the given instance to this cluster and set the cluster on the instance (back pointer)boolean
equals(java.lang.Object obj)
java.lang.String
getId()
Returns a stable id of the cluster represented by this cluster view.java.util.List<InstanceDescription>
getInstances()
Provides the list of InstanceDescriptions with a stable ordering.InstanceDescription
getLeader()
Provides the InstanceDescription belonging to the leader instance.InstanceDescription
getLocalInstance()
Returns the local InstanceDescription or null if no local instance is listedint
hashCode()
boolean
removeInstanceDescription(InstanceDescription instance)
Removes the given instance from this cluster.java.lang.String
toString()
-
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getId
public java.lang.String getId()
Description copied from interface:ClusterView
Returns a stable id of the cluster represented by this cluster view.Similar to the SlingID, this id is persisted and thus remains stable accross instance/cluster restarts.
When an instance joins a cluster, it will inherit the id from the joined cluster (thus incurs a cluster id change).
Note: When instances part from a cluster (eg due to a network partitioning) the cluster id is retained. This results in potentially multiple clusters with the same id. This fact could be used to detect such partitioning/split brain situations. It also implies though that the cluster id is not guaranteed to be unique in a topology!
Addition in 1.0.4: this id must consist only of alphanumeric characters plus dash '-' and underscore '_'.
- Specified by:
getId
in interfaceClusterView
- Returns:
- an id of this cluster view
- See Also:
- SLING-3164
-
addInstanceDescription
public void addInstanceDescription(DefaultInstanceDescription instance)
Add the given instance to this cluster and set the cluster on the instance (back pointer)- Parameters:
instance
- the instance to add to this cluster
-
getInstances
public java.util.List<InstanceDescription> getInstances()
Description copied from interface:ClusterView
Provides the list of InstanceDescriptions with a stable ordering.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.
- Specified by:
getInstances
in interfaceClusterView
- Returns:
- the list of InstanceDescriptions (with a stable ordering)
-
getLeader
public InstanceDescription getLeader()
Description copied from interface:ClusterView
Provides the InstanceDescription belonging to the leader instance.Every ClusterView is guaranteed to have one and only one leader.
The leader is stable: once a leader is elected it stays leader unless it leaves the cluster (due to shutdown/crash/network problems)
- Specified by:
getLeader
in interfaceClusterView
- Returns:
- the InstanceDescription belonging to the leader instance
-
removeInstanceDescription
public boolean removeInstanceDescription(InstanceDescription instance)
Removes the given instance from this cluster.Note that the instance will still have a pointer to this cluster however.
- Parameters:
instance
- the instance to remove from this cluster
-
getLocalInstance
public InstanceDescription getLocalInstance()
Returns the local InstanceDescription or null if no local instance is listed- Returns:
- the local InstanceDescription or null if no local instance is listed
- Throws:
java.lang.IllegalStateException
- if multiple local instances are listed
-
-