blob: f686b44630a4cdae29622cbf2c3915c5d63c399a [file] [log] [blame]
Juha Hyttinen0388dd92020-01-09 14:14:16 +02001/*
2==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
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==================================================================================
18*/
19
20package control
21
22import (
23 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
24 "strconv"
25 "sync"
26)
27
28//-----------------------------------------------------------------------------
29//
30//-----------------------------------------------------------------------------
31type TransactionXappKey struct {
32 RmrEndpoint
33 Xid string // xapp xid in req
34}
35
36func (key *TransactionXappKey) String() string {
37 return key.RmrEndpoint.String() + "/" + key.Xid
38}
39
40//-----------------------------------------------------------------------------
41//
42//-----------------------------------------------------------------------------
43type Transaction struct {
44 mutex sync.Mutex
45 tracker *Tracker // tracker instance
46 Subs *Subscription
47 RmrEndpoint RmrEndpoint
48 Xid string // xapp xid in req
49 OrigParams *xapp.RMRParams // request orginal params
50 RespReceived bool
51 ForwardRespToXapp bool
52}
53
54func (t *Transaction) String() string {
55 t.mutex.Lock()
56 defer t.mutex.Unlock()
57 var subId string = "?"
58 if t.Subs != nil {
59 subId = strconv.FormatUint(uint64(t.Subs.Seq), 10)
60 }
61 return subId + "/" + t.RmrEndpoint.String() + "/" + t.Xid
62}
63
64func (t *Transaction) CheckResponseReceived() bool {
65 t.mutex.Lock()
66 defer t.mutex.Unlock()
67 if t.RespReceived == false {
68 t.RespReceived = true
69 return false
70 }
71 return true
72}
73
74func (t *Transaction) RetryTransaction() {
75 t.mutex.Lock()
76 defer t.mutex.Unlock()
77 t.RespReceived = false
78}
79
80func (t *Transaction) Release() {
81 t.mutex.Lock()
82 defer t.mutex.Unlock()
83 if t.Subs != nil {
84 t.Subs.UnSetTransaction(t)
85 }
86 if t.tracker != nil {
87 xappkey := TransactionXappKey{t.RmrEndpoint, t.Xid}
88 t.tracker.UnTrackTransaction(xappkey)
89 }
90 t.Subs = nil
91 t.tracker = nil
92}