Change-Id: Id075e6f1e2adff994017398f79b4555ac00dfcec
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
func (c *Control) rmrSend(params *xapp.RMRParams) (err error) {
status := false
i := 1
func (c *Control) rmrSend(params *xapp.RMRParams) (err error) {
status := false
i := 1
for ; i <= 10 && status == false; i++ {
for ; i <= 10 && status == false; i++ {
status = xapp.Rmr.Send(params, false)
status = xapp.Rmr.Send(params, false)
if status == false {
xapp.Logger.Info("rmr.Send() failed. Retry count %v, Mtype: %v, SubId: %v, Xid %s",i, params.Mtype, params.SubId, params.Xid)
time.Sleep(500 * time.Millisecond)
if status == false {
xapp.Logger.Info("rmr.Send() failed. Retry count %v, Mtype: %v, SubId: %v, Xid %s",i, params.Mtype, params.SubId, params.Xid)
time.Sleep(500 * time.Millisecond)
err = errors.New("rmr.Send() failed")
xapp.Rmr.Free(params.Mbuf)
}
err = errors.New("rmr.Send() failed")
xapp.Rmr.Free(params.Mbuf)
}
/*
if !xapp.Rmr.Send(params, false) {
/*
if !xapp.Rmr.Send(params, false) {
-var registryMutex = &sync.Mutex{}
type Registry struct {
register map[uint16]bool
counter uint16
type Registry struct {
register map[uint16]bool
counter uint16
}
// This method should run as a constructor
}
// This method should run as a constructor
// Reserves and returns the next free sequence number
func (r *Registry) ReserveSequenceNumber() (uint16, bool) {
// Check is current SequenceNumber valid
// Reserves and returns the next free sequence number
func (r *Registry) ReserveSequenceNumber() (uint16, bool) {
// Check is current SequenceNumber valid
- registryMutex.Lock()
- defer registryMutex.Unlock()
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
sequenceNumber := r.counter
if _, ok := r.register[sequenceNumber]; ok {
xapp.Logger.Error("Invalid SeqenceNumber sequenceNumber: %v",sequenceNumber)
sequenceNumber := r.counter
if _, ok := r.register[sequenceNumber]; ok {
xapp.Logger.Error("Invalid SeqenceNumber sequenceNumber: %v",sequenceNumber)
// This function checks the validity of the given subscription id
func (r *Registry) IsValidSequenceNumber(sn uint16) bool {
// This function checks the validity of the given subscription id
func (r *Registry) IsValidSequenceNumber(sn uint16) bool {
- registryMutex.Lock()
- defer registryMutex.Unlock()
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
xapp.Logger.Debug("Registry map: %v", r.register)
if _, ok := r.register[sn]; ok {
return true
xapp.Logger.Debug("Registry map: %v", r.register)
if _, ok := r.register[sn]; ok {
return true
// This function sets the give id as confirmed in the register
func (r *Registry) setSubscriptionToConfirmed(sn uint16) {
// This function sets the give id as confirmed in the register
func (r *Registry) setSubscriptionToConfirmed(sn uint16) {
- registryMutex.Lock()
- defer registryMutex.Unlock()
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
r.register[sn] = true
}
//This function sets the given id as unused in the register
func (r *Registry) deleteSubscription(sn uint16) {
r.register[sn] = true
}
//This function sets the given id as unused in the register
func (r *Registry) deleteSubscription(sn uint16) {
- registryMutex.Lock()
- defer registryMutex.Unlock()
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
r.register[sn] = false
}
//This function releases the given id as unused in the register
func (r *Registry) releaseSequenceNumber(sn uint16) bool {
r.register[sn] = false
}
//This function releases the given id as unused in the register
func (r *Registry) releaseSequenceNumber(sn uint16) bool {
- registryMutex.Lock()
- defer registryMutex.Unlock()
- if r.register[sn] {
- return false
- } else {
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ if _, ok := r.register[sn]; ok {
delete(r.register, sn)
return true
delete(r.register, sn)
return true
+ } else {
+ return false
-var trackerMutex = &sync.Mutex{}
-
/*
Implements a record of ongoing transactions and helper functions to CRUD the records.
*/
type Tracker struct {
transactionTable map[TransactionKey]Transaction
/*
Implements a record of ongoing transactions and helper functions to CRUD the records.
*/
type Tracker struct {
transactionTable map[TransactionKey]Transaction
}
func (t *Tracker) Init() {
}
func (t *Tracker) Init() {
Returns error if there is similar transatcion ongoing.
*/
func (t *Tracker) TrackTransaction(key TransactionKey, xact Transaction) error {
Returns error if there is similar transatcion ongoing.
*/
func (t *Tracker) TrackTransaction(key TransactionKey, xact Transaction) error {
- trackerMutex.Lock()
- defer trackerMutex.Unlock()
+ t.mutex.Lock()
+ defer t.mutex.Unlock()
if _, ok := t.transactionTable[key]; ok {
// TODO: Implement merge related check here. If the key is same but the value is different.
err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %s is ongoing", key.SubID, key.transType)
if _, ok := t.transactionTable[key]; ok {
// TODO: Implement merge related check here. If the key is same but the value is different.
err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %s is ongoing", key.SubID, key.transType)
*/
func (t *Tracker) UpdateTransaction(SubID uint16, transType Action, xact Transaction) error {
key := TransactionKey{SubID, transType}
*/
func (t *Tracker) UpdateTransaction(SubID uint16, transType Action, xact Transaction) error {
key := TransactionKey{SubID, transType}
- trackerMutex.Lock()
- defer trackerMutex.Unlock()
+ t.mutex.Lock()
+ defer t.mutex.Unlock()
if _, ok := t.transactionTable[key]; ok {
// TODO: Implement merge related check here. If the key is same but the value is different.
err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %v is ongoing", key.SubID, key.transType)
if _, ok := t.transactionTable[key]; ok {
// TODO: Implement merge related check here. If the key is same but the value is different.
err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %v is ongoing", key.SubID, key.transType)
*/
func (t *Tracker) RetriveTransaction(subID uint16, act Action) (Transaction, error) {
key := TransactionKey{subID, act}
*/
func (t *Tracker) RetriveTransaction(subID uint16, act Action) (Transaction, error) {
key := TransactionKey{subID, act}
- trackerMutex.Lock()
- defer trackerMutex.Unlock()
+ t.mutex.Lock()
+ defer t.mutex.Unlock()
var xact Transaction
if xact, ok := t.transactionTable[key]; ok {
return xact, nil
var xact Transaction
if xact, ok := t.transactionTable[key]; ok {
return xact, nil
func (t *Tracker) completeTransaction(subID uint16, act Action) (Transaction, error) {
key := TransactionKey{subID, act}
var emptyTransaction Transaction
func (t *Tracker) completeTransaction(subID uint16, act Action) (Transaction, error) {
key := TransactionKey{subID, act}
var emptyTransaction Transaction
- trackerMutex.Lock()
- defer trackerMutex.Unlock()
+ t.mutex.Lock()
+ defer t.mutex.Unlock()
if xact, ok := t.transactionTable[key]; ok {
delete(t.transactionTable, key)
return xact, nil
if xact, ok := t.transactionTable[key]; ok {
delete(t.transactionTable, key)
return xact, nil