@@ -7,24 +7,26 @@ import (
77 "github.com/tarantool/go-tarantool/v2"
88)
99
10- type roundRobinStrategy struct {
10+ var _ BalancingPool = (* RoundRobinStrategy )(nil )
11+
12+ type RoundRobinStrategy struct {
1113 conns []* tarantool.Connection
1214 indexById map [string ]uint
1315 mutex sync.RWMutex
1416 size uint64
1517 current uint64
1618}
1719
18- func newRoundRobinStrategy (size int ) * roundRobinStrategy {
19- return & roundRobinStrategy {
20+ func NewRoundRobinStrategy (size int ) BalancingPool {
21+ return & RoundRobinStrategy {
2022 conns : make ([]* tarantool.Connection , 0 , size ),
2123 indexById : make (map [string ]uint , size ),
2224 size : 0 ,
2325 current : 0 ,
2426 }
2527}
2628
27- func (r * roundRobinStrategy ) GetConnection (id string ) * tarantool.Connection {
29+ func (r * RoundRobinStrategy ) GetConnection (id string ) * tarantool.Connection {
2830 r .mutex .RLock ()
2931 defer r .mutex .RUnlock ()
3032
@@ -36,7 +38,7 @@ func (r *roundRobinStrategy) GetConnection(id string) *tarantool.Connection {
3638 return r .conns [index ]
3739}
3840
39- func (r * roundRobinStrategy ) DeleteConnection (id string ) * tarantool.Connection {
41+ func (r * RoundRobinStrategy ) DeleteConnection (id string ) * tarantool.Connection {
4042 r .mutex .Lock ()
4143 defer r .mutex .Unlock ()
4244
@@ -64,14 +66,14 @@ func (r *roundRobinStrategy) DeleteConnection(id string) *tarantool.Connection {
6466 return conn
6567}
6668
67- func (r * roundRobinStrategy ) IsEmpty () bool {
69+ func (r * RoundRobinStrategy ) IsEmpty () bool {
6870 r .mutex .RLock ()
6971 defer r .mutex .RUnlock ()
7072
7173 return r .size == 0
7274}
7375
74- func (r * roundRobinStrategy ) GetNextConnection () * tarantool.Connection {
76+ func (r * RoundRobinStrategy ) GetNextConnection () * tarantool.Connection {
7577 r .mutex .RLock ()
7678 defer r .mutex .RUnlock ()
7779
@@ -81,7 +83,7 @@ func (r *roundRobinStrategy) GetNextConnection() *tarantool.Connection {
8183 return r .conns [r .nextIndex ()]
8284}
8385
84- func (r * roundRobinStrategy ) GetConnections () map [string ]* tarantool.Connection {
86+ func (r * RoundRobinStrategy ) GetConnections () map [string ]* tarantool.Connection {
8587 r .mutex .RLock ()
8688 defer r .mutex .RUnlock ()
8789
@@ -93,7 +95,7 @@ func (r *roundRobinStrategy) GetConnections() map[string]*tarantool.Connection {
9395 return conns
9496}
9597
96- func (r * roundRobinStrategy ) AddConnection (id string , conn * tarantool.Connection ) {
98+ func (r * RoundRobinStrategy ) AddConnection (id string , conn * tarantool.Connection ) {
9799 r .mutex .Lock ()
98100 defer r .mutex .Unlock ()
99101
@@ -106,7 +108,7 @@ func (r *roundRobinStrategy) AddConnection(id string, conn *tarantool.Connection
106108 }
107109}
108110
109- func (r * roundRobinStrategy ) nextIndex () uint64 {
111+ func (r * RoundRobinStrategy ) nextIndex () uint64 {
110112 next := atomic .AddUint64 (& r .current , 1 )
111113 return (next - 1 ) % r .size
112114}
0 commit comments