Code Review
/
ric-plt
/
submgr.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Merge "RICPLT-3008 Subscription register free id list"
[ric-plt/submgr.git]
/
pkg
/
control
/
registry.go
diff --git
a/pkg/control/registry.go
b/pkg/control/registry.go
index
2c5bd8c
..
c27e6a2
100644
(file)
--- a/
pkg/control/registry.go
+++ b/
pkg/control/registry.go
@@
-31,18
+31,21
@@
import (
type Registry struct {
mutex sync.Mutex
register map[uint16]*Subscription
type Registry struct {
mutex sync.Mutex
register map[uint16]*Subscription
-
counter
uint16
+
subIds []
uint16
rtmgrClient *RtmgrClient
}
// This method should run as a constructor
rtmgrClient *RtmgrClient
}
// This method should run as a constructor
-func (r *Registry) Initialize(
seedsn uint16
) {
+func (r *Registry) Initialize() {
r.register = make(map[uint16]*Subscription)
r.register = make(map[uint16]*Subscription)
- r.counter = seedsn
+ var i uint16
+ for i = 0; i < 65535; i++ {
+ r.subIds = append(r.subIds, i+1)
+ }
}
// Reserves and returns the next free sequence number
}
// Reserves and returns the next free sequence number
-func (r *Registry) ReserveSubscription(endPoint RmrEndpoint, meid *xapp.RMRMeid) (*Subscription, error) {
+func (r *Registry) ReserveSubscription(endPoint
*
RmrEndpoint, meid *xapp.RMRMeid) (*Subscription, error) {
// Check is current SequenceNumber valid
// Allocate next SequenceNumber value and retry N times
r.mutex.Lock()
// Check is current SequenceNumber valid
// Allocate next SequenceNumber value and retry N times
r.mutex.Lock()
@@
-50,17
+53,14
@@
func (r *Registry) ReserveSubscription(endPoint RmrEndpoint, meid *xapp.RMRMeid)
var subs *Subscription = nil
var retrytimes uint16 = 1000
for ; subs == nil && retrytimes > 0; retrytimes-- {
var subs *Subscription = nil
var retrytimes uint16 = 1000
for ; subs == nil && retrytimes > 0; retrytimes-- {
- sequenceNumber := r.counter
- if r.counter == 65535 {
- r.counter = 0
- } else {
- r.counter++
- }
+ sequenceNumber := r.subIds[0]
+ r.subIds = r.subIds[1:]
if _, ok := r.register[sequenceNumber]; ok == false {
subs := &Subscription{
if _, ok := r.register[sequenceNumber]; ok == false {
subs := &Subscription{
+ registry: r,
Seq: sequenceNumber,
Active: false,
Seq: sequenceNumber,
Active: false,
- RmrEndpoint: endPoint,
+ RmrEndpoint:
*
endPoint,
Meid: meid,
Trans: nil,
}
Meid: meid,
Trans: nil,
}
@@
-68,7
+68,7
@@
func (r *Registry) ReserveSubscription(endPoint RmrEndpoint, meid *xapp.RMRMeid)
// Update routing
r.mutex.Unlock()
// Update routing
r.mutex.Unlock()
- err := subs.UpdateRoute(CREATE
, r.rtmgrClient
)
+ err := subs.UpdateRoute(CREATE)
r.mutex.Lock()
if err != nil {
if _, ok := r.register[sequenceNumber]; ok {
r.mutex.Lock()
if err != nil {
if _, ok := r.register[sequenceNumber]; ok {
@@
-79,7
+79,7
@@
func (r *Registry) ReserveSubscription(endPoint RmrEndpoint, meid *xapp.RMRMeid)
return subs, nil
}
}
return subs, nil
}
}
- return nil, fmt.Errorf("Registry: Failed to reserves subcription. RmrEndpoint: %s, Meid: %s", endPoint, meid.RanName)
+ return nil, fmt.Errorf("Registry: Failed to reserves sub
s
cription. RmrEndpoint: %s, Meid: %s", endPoint, meid.RanName)
}
func (r *Registry) GetSubscription(sn uint16) *Subscription {
}
func (r *Registry) GetSubscription(sn uint16) *Subscription {
@@
-96,16
+96,8
@@
func (r *Registry) DelSubscription(sn uint16) bool {
r.mutex.Lock()
defer r.mutex.Unlock()
if _, ok := r.register[sn]; ok {
r.mutex.Lock()
defer r.mutex.Unlock()
if _, ok := r.register[sn]; ok {
- subs := r.register[sn]
+ r.subIds = append(r.subIds, sn)
delete(r.register, sn)
delete(r.register, sn)
-
- // Update routing
- r.mutex.Unlock()
- err := subs.UpdateRoute(DELETE, r.rtmgrClient)
- r.mutex.Lock()
- if err != nil {
- xapp.Logger.Error("Registry: Failed to del route. SubId: %d, RmrEndpoint: %s", subs.Seq, subs.RmrEndpoint)
- }
return true
}
return false
return true
}
return false