X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Ftransaction.go;h=df4d7db4147a34c101a05330b2d5a3184bb5dd74;hb=a9bf76cb8dec6e52e7699edf1631c214647f8beb;hp=a0a260f5f20df41d76d0e830824d75c67a2c5df2;hpb=422d018f94aedd9f4c001176b5ff06c786de28eb;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/transaction.go b/pkg/control/transaction.go index a0a260f..df4d7db 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/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 + ReqId RequestId // + 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) + "/" + t.Meid.RanName + "/" + t.ReqId.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,19 @@ func (t *TransactionBase) WaitEvent(waittime time.Duration) (interface{}, bool) return event, false } -func (t *TransactionBase) GetMtype() int { +func (t *Transaction) GetReqId() *RequestId { + t.mutex.Lock() + defer t.mutex.Unlock() + return &t.ReqId +} + +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 +104,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 +143,20 @@ func (key *TransactionXappKey) String() string { //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- -type Transaction struct { - TransactionBase // - XappKey *TransactionXappKey // +type TransactionXapp struct { + Transaction // + XappKey *TransactionXappKey // } -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 + ")" -} - -func (t *Transaction) String() string { - t.mutex.Lock() - defer t.mutex.Unlock() - return t.StringImpl() + return "transxapp(" + t.Transaction.String() + "/" + transkey + ")" } -func (t *Transaction) GetEndpoint() *RmrEndpoint { +func (t *TransactionXapp) GetEndpoint() *RmrEndpoint { t.mutex.Lock() defer t.mutex.Unlock() if t.XappKey != nil { @@ -132,7 +165,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 +174,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 +183,9 @@ func (t *Transaction) GetSrc() string { return "" } -func (t *Transaction) Release() { +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