X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Ftracker.go;h=087b7811a22f2bb9710aa47bba528829a911a5d3;hb=0388dd945789dae802aaa93c5062e3ae4c45ddf1;hp=0e6941d7d37ce31e7d99d9152c75d2d56d7051eb;hpb=0d064ecdb5239a875857b5910f7f6e83f827d7a6;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/tracker.go b/pkg/control/tracker.go index 0e6941d..087b781 100644 --- a/pkg/control/tracker.go +++ b/pkg/control/tracker.go @@ -22,82 +22,15 @@ package control import ( "fmt" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" - "strconv" "sync" ) -//----------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------- -type TransactionXappKey struct { - RmrEndpoint - Xid string // xapp xid in req -} - -func (key *TransactionXappKey) String() string { - return key.RmrEndpoint.String() + "/" + key.Xid -} - -//----------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------- -type Transaction struct { - tracker *Tracker // tracker instance - Subs *Subscription - RmrEndpoint RmrEndpoint - Xid string // xapp xid in req - OrigParams *xapp.RMRParams // request orginal params - RespReceived bool - ForwardRespToXapp bool - mutex sync.Mutex -} - -func (t *Transaction) String() string { - t.mutex.Lock() - defer t.mutex.Unlock() - var subId string = "?" - if t.Subs != nil { - subId = strconv.FormatUint(uint64(t.Subs.Seq), 10) - } - return subId + "/" + t.RmrEndpoint.String() + "/" + t.Xid -} - -func (t *Transaction) CheckResponseReceived() bool { - t.mutex.Lock() - defer t.mutex.Unlock() - if t.RespReceived == false { - t.RespReceived = true - return false - } - return true -} - -func (t *Transaction) RetryTransaction() { - t.mutex.Lock() - defer t.mutex.Unlock() - t.RespReceived = false -} - -func (t *Transaction) Release() { - t.mutex.Lock() - defer t.mutex.Unlock() - if t.Subs != nil { - t.Subs.UnSetTransaction(t) - } - if t.tracker != nil { - xappkey := TransactionXappKey{t.RmrEndpoint, t.Xid} - t.tracker.UnTrackTransaction(xappkey) - } - t.Subs = nil - t.tracker = nil -} - //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- type Tracker struct { - transactionXappTable map[TransactionXappKey]*Transaction mutex sync.Mutex + transactionXappTable map[TransactionXappKey]*Transaction } func (t *Tracker) Init() { @@ -125,18 +58,10 @@ func (t *Tracker) TrackTransaction(subs *Subscription, endpoint RmrEndpoint, par return nil, err } - if subs.SetTransaction(trans) == false { - othTrans := subs.GetTransaction() - err := fmt.Errorf("Tracker: Subscription %s got already transaction ongoing: %s, transaction %s not created", subs, othTrans, trans) - return nil, err - } - trans.Subs = subs - if (trans.Subs.RmrEndpoint.Addr != trans.RmrEndpoint.Addr) || (trans.Subs.RmrEndpoint.Port != trans.RmrEndpoint.Port) { - err := fmt.Errorf("Tracker: Subscription endpoint %s mismatch with trans: %s", subs, trans) - trans.Subs.UnSetTransaction(nil) + err := subs.SetTransaction(trans) + if err != nil { return nil, err } - trans.tracker = t t.transactionXappTable[xappkey] = trans return trans, nil