X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Ftransaction.go;h=1298925e3a6401ac80c565a83c6f6ed637ee332a;hb=d708a43badb0742684b22866977f14cc1c03a1ba;hp=a0a260f5f20df41d76d0e830824d75c67a2c5df2;hpb=422d018f94aedd9f4c001176b5ff06c786de28eb;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/transaction.go b/pkg/control/transaction.go index a0a260f..1298925 100644 --- a/pkg/control/transaction.go +++ b/pkg/control/transaction.go @@ -20,28 +20,43 @@ package control import ( - "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/packer" + "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" + "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "strconv" "sync" "time" ) +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type TransactionIf interface { + String() string + Release() + SendEvent(interface{}, time.Duration) (bool, bool) + WaitEvent(time.Duration) (interface{}, bool) +} + //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- -type TransactionBase struct { - mutex sync.Mutex // - Seq uint64 // - tracker *Tracker //tracker instance - Meid *xapp.RMRMeid //meid transaction related - Mtype int //Encoded message type to be send - Payload *packer.PackedData //Encoded message to be send +type Transaction struct { + mutex sync.Mutex // + Seq uint64 //transaction sequence + tracker *Tracker //tracker instance + Meid *xapp.RMRMeid //meid transaction related + Mtype int //Encoded message type to be send + Payload *e2ap.PackedData //Encoded message to be send EventChan chan interface{} } -func (t *TransactionBase) SendEvent(event interface{}, waittime time.Duration) (bool, bool) { +func (t *Transaction) String() string { + return "trans(" + strconv.FormatUint(uint64(t.Seq), 10) + "/" + (&xapptweaks.RMRMeid{t.Meid}).String() + ")" +} + +func (t *Transaction) SendEvent(event interface{}, waittime time.Duration) (bool, bool) { if waittime > 0 { select { case t.EventChan <- event: @@ -55,7 +70,7 @@ func (t *TransactionBase) SendEvent(event interface{}, waittime time.Duration) ( return true, false } -func (t *TransactionBase) WaitEvent(waittime time.Duration) (interface{}, bool) { +func (t *Transaction) WaitEvent(waittime time.Duration) (interface{}, bool) { if waittime > 0 { select { case event := <-t.EventChan: @@ -68,13 +83,13 @@ func (t *TransactionBase) WaitEvent(waittime time.Duration) (interface{}, bool) return event, false } -func (t *TransactionBase) GetMtype() int { +func (t *Transaction) GetMtype() int { t.mutex.Lock() defer t.mutex.Unlock() return t.Mtype } -func (t *TransactionBase) GetMeid() *xapp.RMRMeid { +func (t *Transaction) GetMeid() *xapp.RMRMeid { t.mutex.Lock() defer t.mutex.Unlock() if t.Meid != nil { @@ -83,12 +98,30 @@ func (t *TransactionBase) GetMeid() *xapp.RMRMeid { return nil } -func (t *TransactionBase) GetPayload() *packer.PackedData { +func (t *Transaction) GetPayload() *e2ap.PackedData { t.mutex.Lock() defer t.mutex.Unlock() return t.Payload } +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type TransactionSubs struct { + Transaction // +} + +func (t *TransactionSubs) String() string { + return "transsubs(" + t.Transaction.String() + ")" +} + +func (t *TransactionSubs) Release() { + t.mutex.Lock() + xapp.Logger.Debug("RELEASE %s", t.String()) + t.tracker = nil + t.mutex.Unlock() +} + //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- @@ -104,26 +137,21 @@ func (key *TransactionXappKey) String() string { //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- -type Transaction struct { - TransactionBase // - XappKey *TransactionXappKey // +type TransactionXapp struct { + Transaction + XappKey *TransactionXappKey + SubId uint32 } -func (t *Transaction) StringImpl() string { +func (t *TransactionXapp) String() string { var transkey string = "transkey(N/A)" if t.XappKey != nil { transkey = t.XappKey.String() } - return "trans(" + strconv.FormatUint(uint64(t.Seq), 10) + "/" + t.Meid.RanName + "/" + transkey + ")" + return "transxapp(" + t.Transaction.String() + "/" + transkey + "/" + strconv.FormatUint(uint64(t.SubId), 10) + ")" } -func (t *Transaction) String() string { - t.mutex.Lock() - defer t.mutex.Unlock() - return t.StringImpl() -} - -func (t *Transaction) GetEndpoint() *RmrEndpoint { +func (t *TransactionXapp) GetEndpoint() *RmrEndpoint { t.mutex.Lock() defer t.mutex.Unlock() if t.XappKey != nil { @@ -132,7 +160,7 @@ func (t *Transaction) GetEndpoint() *RmrEndpoint { return nil } -func (t *Transaction) GetXid() string { +func (t *TransactionXapp) GetXid() string { t.mutex.Lock() defer t.mutex.Unlock() if t.XappKey != nil { @@ -141,7 +169,7 @@ func (t *Transaction) GetXid() string { return "" } -func (t *Transaction) GetSrc() string { +func (t *TransactionXapp) GetSrc() string { t.mutex.Lock() defer t.mutex.Unlock() if t.XappKey != nil { @@ -150,9 +178,15 @@ func (t *Transaction) GetSrc() string { return "" } -func (t *Transaction) Release() { +func (t *TransactionXapp) GetSubId() uint32 { + t.mutex.Lock() + defer t.mutex.Unlock() + return t.SubId +} + +func (t *TransactionXapp) Release() { t.mutex.Lock() - xapp.Logger.Debug("Transaction: Release %s", t.StringImpl()) + xapp.Logger.Debug("RELEASE %s", t.String()) tracker := t.tracker xappkey := t.XappKey t.tracker = nil