2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
23 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/packer"
24 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 type TransactionBase struct {
37 tracker *Tracker //tracker instance
38 Meid *xapp.RMRMeid //meid transaction related
39 Mtype int //Encoded message type to be send
40 Payload *packer.PackedData //Encoded message to be send
41 EventChan chan interface{}
44 func (t *TransactionBase) SendEvent(event interface{}, waittime time.Duration) (bool, bool) {
47 case t.EventChan <- event:
49 case <-time.After(waittime):
58 func (t *TransactionBase) WaitEvent(waittime time.Duration) (interface{}, bool) {
61 case event := <-t.EventChan:
63 case <-time.After(waittime):
67 event := <-t.EventChan
71 func (t *TransactionBase) GetMtype() int {
73 defer t.mutex.Unlock()
77 func (t *TransactionBase) GetMeid() *xapp.RMRMeid {
79 defer t.mutex.Unlock()
86 func (t *TransactionBase) GetPayload() *packer.PackedData {
88 defer t.mutex.Unlock()
92 //-----------------------------------------------------------------------------
94 //-----------------------------------------------------------------------------
95 type TransactionXappKey struct {
97 Xid string // xapp xid in req
100 func (key *TransactionXappKey) String() string {
101 return "transkey(" + key.RmrEndpoint.String() + "/" + key.Xid + ")"
104 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
107 type Transaction struct {
109 XappKey *TransactionXappKey //
112 func (t *Transaction) String() string {
113 var transkey string = "transkey(N/A)"
114 if t.XappKey != nil {
115 transkey = t.XappKey.String()
117 return "trans(" + strconv.FormatUint(uint64(t.Seq), 10) + "/" + t.Meid.RanName + "/" + transkey + ")"
120 func (t *Transaction) GetEndpoint() *RmrEndpoint {
122 defer t.mutex.Unlock()
123 if t.XappKey != nil {
124 return &t.XappKey.RmrEndpoint
129 func (t *Transaction) GetXid() string {
131 defer t.mutex.Unlock()
132 if t.XappKey != nil {
138 func (t *Transaction) GetSrc() string {
140 defer t.mutex.Unlock()
141 if t.XappKey != nil {
142 return t.XappKey.RmrEndpoint.String()
147 func (t *Transaction) Release() {
149 xapp.Logger.Debug("Transaction: Release %s", t.String())
155 if tracker != nil && xappkey != nil {
156 tracker.UnTrackTransaction(*xappkey)