@@ -82,51 +82,63 @@ func NewStaticLocatorFromStr(groupName string, nodes []string) (*StaticLocator,
8282// ----------------------------------------------------------------------------
8383// implement api methods
8484
85+ // Get returns the current selected supernode, it should be idempotent.
86+ // It should return nil before first calling the Next method.
8587func (s * StaticLocator ) Get () * Supernode {
8688 if s .Group == nil {
8789 return nil
8890 }
8991 return s .Group .GetNode (s .load ())
9092}
9193
94+ // Next chooses the next available supernode for retrying or other
95+ // purpose. The current supernode should be set as this result.
9296func (s * StaticLocator ) Next () * Supernode {
9397 if s .Group == nil || s .load () >= len (s .Group .Nodes ) {
9498 return nil
9599 }
96100 return s .Group .GetNode (s .inc ())
97101}
98102
103+ // Select chooses a supernode based on the giving key.
104+ // It should not affect the result of method 'Get()'.
99105func (s * StaticLocator ) Select (key interface {}) * Supernode {
100106 // unnecessary to implement this method
101107 return nil
102108}
103109
110+ // GetGroup returns the group with the giving name.
104111func (s * StaticLocator ) GetGroup (name string ) * SupernodeGroup {
105112 if s .Group == nil || s .Group .Name != name {
106113 return nil
107114 }
108115 return s .Group
109116}
110117
118+ // All returns all the supernodes.
111119func (s * StaticLocator ) All () []* SupernodeGroup {
112120 if s .Group == nil {
113121 return nil
114122 }
115123 return []* SupernodeGroup {s .Group }
116124}
117125
126+ // Size returns the number of all supernodes.
118127func (s * StaticLocator ) Size () int {
119128 if s .Group == nil {
120129 return 0
121130 }
122131 return len (s .Group .Nodes )
123132}
124133
134+ // Report records the metrics of the current supernode in order to choose a
135+ // more appropriate supernode for the next time if necessary.
125136func (s * StaticLocator ) Report (node string , metrics * SupernodeMetrics ) {
126137 // unnecessary to implement this method
127138 return
128139}
129140
141+ // Refresh refreshes all the supernodes.
130142func (s * StaticLocator ) Refresh () bool {
131143 atomic .StoreInt32 (& s .idx , - 1 )
132144 return true
0 commit comments