public class DefaultClusterView extends java.lang.Object implements ClusterView
Besides implementing the interface methods it also adds add/remove of InstanceDescriptions as well as implementing equals and hashCode.
Constructor and Description |
---|
DefaultClusterView(java.lang.String id) |
Modifier and Type | Method and 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 listed
|
int |
hashCode() |
boolean |
removeInstanceDescription(InstanceDescription instance)
Removes the given instance from this cluster.
|
java.lang.String |
toString() |
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String getId()
ClusterView
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 '_'.
getId
in interface ClusterView
public void addInstanceDescription(DefaultInstanceDescription instance)
instance
- the instance to add to this clusterpublic java.util.List<InstanceDescription> getInstances()
ClusterView
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.
getInstances
in interface ClusterView
public InstanceDescription getLeader()
ClusterView
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)
getLeader
in interface ClusterView
public boolean removeInstanceDescription(InstanceDescription instance)
Note that the instance will still have a pointer to this cluster however.
instance
- the instance to remove from this clusterpublic InstanceDescription getLocalInstance()
java.lang.IllegalStateException
- if multiple local instances are listedCopyright © 2022 The Apache Software Foundation. All rights reserved.