[DMAAP-CLIENT] First sonar issues review part2
[dmaap/messagerouter/dmaapclient.git] / src / main / java / org / onap / dmaap / mr / tools / MRCommandContext.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  *  ================================================================================
7  *  Modifications Copyright © 2021 Orange.
8  *  ================================================================================
9  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  you may not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License.
19  *  ============LICENSE_END=========================================================
20  *
21  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  *
23  *******************************************************************************/
24
25 package org.onap.dmaap.mr.tools;
26
27 import com.att.nsa.apiClient.http.HttpClient;
28 import com.att.nsa.apiClient.http.HttpTracer;
29 import com.att.nsa.cmdtool.CommandContext;
30 import java.util.Collection;
31 import java.util.LinkedList;
32 import org.onap.dmaap.mr.client.MRClient;
33
34 public class MRCommandContext implements CommandContext {
35     public MRCommandContext() {
36         fApiKey = null;
37         fApiPwd = null;
38
39         fCluster = new LinkedList<>();
40         fCluster.add("localhost");
41     }
42
43     @Override
44     public void requestShutdown() {
45         fShutdown = true;
46     }
47
48     @Override
49     public boolean shouldContinue() {
50         return !fShutdown;
51     }
52
53     public void setAuth(String key, String pwd) {
54         fApiKey = key;
55         fApiPwd = pwd;
56     }
57
58     public void clearAuth() {
59         setAuth(null, null);
60     }
61
62     public boolean checkClusterReady() {
63         return (fCluster.isEmpty());
64     }
65
66     public Collection<String> getCluster() {
67         return new LinkedList<>(fCluster);
68     }
69
70     public void clearCluster() {
71         fCluster.clear();
72     }
73
74     public void addClusterHost(String host) {
75         fCluster.add(host);
76     }
77
78     public String getApiKey() {
79         return fApiKey;
80     }
81
82     public String getApiPwd() {
83         return fApiPwd;
84     }
85
86     public void useTracer(HttpTracer t) {
87         fTracer = t;
88     }
89
90     public void noTracer() {
91         fTracer = null;
92     }
93
94     public void applyTracer(MRClient cc) {
95         if (cc instanceof HttpClient && fTracer != null) {
96             ((HttpClient) cc).installTracer(fTracer);
97         }
98     }
99
100     private boolean fShutdown;
101     private String fApiKey;
102     private String fApiPwd;
103     private final LinkedList<String> fCluster;
104     private HttpTracer fTracer = null;
105 }