• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package ohos.devtools.views.distributed.util;
17 
18 import ohos.devtools.views.applicationtrace.bean.Duration;
19 import ohos.devtools.views.distributed.bean.DistributedFuncBean;
20 import ohos.devtools.views.distributed.bean.DistributedParams;
21 import ohos.devtools.views.distributed.bean.DistributedThreadBean;
22 
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 
28 /**
29  * DistributedCache
30  *
31  * @since 2021/08/07 13:41
32  */
33 public class DistributedCache {
34     /**
35      * durA duration from A database
36      */
37     public static final List<Duration> DUR_A = new ArrayList<>() {
38     };
39 
40     /**
41      * threadsA thread list from A database
42      */
43     public static final List<DistributedThreadBean> THREADS_A = new ArrayList<>() {
44     };
45 
46     /**
47      * threadMapA thread map from A database
48      */
49     public static final Map<Integer, List<DistributedThreadBean>> THREAD_MAP_A = new HashMap<>();
50 
51     /**
52      * funcMapA function map from A database
53      */
54     public static final Map<Integer, List<DistributedFuncBean>> FUNC_MAP_A = new HashMap<>();
55 
56     /**
57      * idFuncBeanMapA function map with name is id and value is function from A database
58      */
59     public static final Map<Integer, DistributedFuncBean> ID_FUNC_BEAN_MAP_A = new HashMap<>();
60 
61     /**
62      * durB duration from B database
63      */
64     public static final List<Duration> DUR_B = new ArrayList<>() {
65     };
66 
67     /**
68      * threadsB thread list from B database
69      */
70     public static final List<DistributedThreadBean> THREADS_B = new ArrayList<>() {
71     };
72 
73     /**
74      * threadMapB thread map from A database
75      */
76     public static final Map<Integer, List<DistributedThreadBean>> THREAD_MAP_B = new HashMap<>();
77 
78     /**
79      * funcMapB function map from B database
80      */
81     public static final Map<Integer, List<DistributedFuncBean>> FUNC_MAP_B = new HashMap<>();
82 
83     /**
84      * idFuncBeanMapB function map with name is id and value is function from B database
85      */
86     public static final Map<Integer, DistributedFuncBean> ID_FUNC_BEAN_MAP_B = new HashMap<>();
87 
88     /**
89      * DistributedParams distribuetedParams map
90      */
91     private static DistributedParams distribuetedParams;
92 
93     /**
94      * threadNamesA thread name list from A database
95      */
96     private static Map<Integer, String> threadNamesA = new HashMap<>();
97 
98     /**
99      * threadNamesB thread name list from B database
100      */
101     private static Map<Integer, String> threadNamesB = new HashMap<>();
102 
103     /**
104      * totalMedianTimes
105      */
106     private static Double totalMedianTimes = 2.0D;
107 
108     /**
109      * delayMedianTimes
110      */
111     private static Double delayMedianTimes = 1.0D;
112 
113     /**
114      * currentDBFlag current db
115      */
116     private static String currentDBFlag = "A";
117 
118     /**
119      * recycleData recycler all data
120      */
recycleData()121     public static void recycleData() {
122         DUR_A.clear();
123         DUR_B.clear();
124         THREADS_A.clear();
125         THREADS_B.clear();
126         threadNamesA.clear();
127         threadNamesB.clear();
128         THREAD_MAP_A.entrySet().stream().forEach(it -> it.getValue().clear());
129         FUNC_MAP_A.entrySet().stream().forEach(it -> it.getValue().clear());
130         THREAD_MAP_B.entrySet().stream().forEach(it -> it.getValue().clear());
131         FUNC_MAP_B.entrySet().stream().forEach(it -> it.getValue().clear());
132         ID_FUNC_BEAN_MAP_A.clear();
133         ID_FUNC_BEAN_MAP_B.clear();
134         THREAD_MAP_A.clear();
135         THREAD_MAP_B.clear();
136         FUNC_MAP_A.clear();
137         FUNC_MAP_B.clear();
138     }
139 
setThreadNamesA(Map<Integer, String> threadNamesA)140     public static void setThreadNamesA(Map<Integer, String> threadNamesA) {
141         DistributedCache.threadNamesA = threadNamesA;
142     }
143 
getThreadNamesB()144     public static Map<Integer, String> getThreadNamesB() {
145         return threadNamesB;
146     }
147 
setThreadNamesB(Map<Integer, String> threadNamesB)148     public static void setThreadNamesB(Map<Integer, String> threadNamesB) {
149         DistributedCache.threadNamesB = threadNamesB;
150     }
151 
getDistribuetedParams()152     public static DistributedParams getDistribuetedParams() {
153         return distribuetedParams;
154     }
155 
setDistribuetedParams(DistributedParams distribuetedParams)156     public static void setDistribuetedParams(DistributedParams distribuetedParams) {
157         DistributedCache.distribuetedParams = distribuetedParams;
158     }
159 
getTotalMedianTimes()160     public static Double getTotalMedianTimes() {
161         return totalMedianTimes;
162     }
163 
setTotalMedianTimes(Double totalMedianTimes)164     public static void setTotalMedianTimes(Double totalMedianTimes) {
165         DistributedCache.totalMedianTimes = totalMedianTimes;
166     }
167 
getDelayMedianTimes()168     public static Double getDelayMedianTimes() {
169         return delayMedianTimes;
170     }
171 
setDelayMedianTimes(Double delayMedianTimes)172     public static void setDelayMedianTimes(Double delayMedianTimes) {
173         DistributedCache.delayMedianTimes = delayMedianTimes;
174     }
175 
getCurrentDBFlag()176     public static String getCurrentDBFlag() {
177         return currentDBFlag;
178     }
179 
setCurrentDBFlag(String currentDBFlag)180     public static void setCurrentDBFlag(String currentDBFlag) {
181         DistributedCache.currentDBFlag = currentDBFlag;
182     }
183 }
184