e5127695505fef308e8c3ab00c54d723c2fa52dd
[dmaap/messagerouter/dmaapclient.git] / src / main / java / com / att / nsa / 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  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
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  *  ============LICENSE_END=========================================================
18  *
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package com.att.nsa.mr.tools;
23
24 import java.util.Collection;
25 import java.util.LinkedList;
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 com.att.nsa.mr.client.MRClient;
31
32 public class MRCommandContext implements CommandContext
33 {
34         public MRCommandContext ()
35         {
36                 fApiKey = null;
37                 fApiPwd = null;
38
39                 fCluster = new LinkedList<> ();
40                 fCluster.add ( "localhost" );
41         }
42
43         @Override
44         public void requestShutdown ()
45         {
46                 fShutdown = true;
47         }
48
49         @Override
50         public boolean shouldContinue ()
51         {
52                 return !fShutdown;
53         }
54
55         public void setAuth ( String key, String pwd ) { fApiKey = key; fApiPwd = pwd; }
56         public void clearAuth () { setAuth(null,null); }
57         
58         public boolean checkClusterReady ()
59         {
60                 return ( fCluster.isEmpty());
61         }
62
63         public Collection<String> getCluster ()
64         {
65                 return new LinkedList<> ( fCluster );
66         }
67
68         public void clearCluster ()
69         {
70                 fCluster.clear ();
71         }
72
73         public void addClusterHost ( String host )
74         {
75                 fCluster.add ( host );
76         }
77
78         public String getApiKey () { return fApiKey; }
79         public String getApiPwd () { return fApiPwd; }
80
81         public void useTracer ( HttpTracer t )
82         {
83                 fTracer = t;
84         }
85         public void noTracer () { fTracer = null; }
86
87         public void applyTracer ( MRClient cc )
88         {
89                 if ( cc instanceof HttpClient && fTracer != null )
90                 {
91                         ((HttpClient)cc).installTracer ( fTracer );
92                 }
93         }
94
95         private boolean fShutdown;
96         private String fApiKey;
97         private String fApiPwd;
98         private final LinkedList<String> fCluster;
99         private HttpTracer fTracer = null;
100 }