summaryrefslogtreecommitdiff
path: root/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java
blob: b7966207478fa939739a539d219f855b7d9001df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
package org.apache.qpid.management.configuration;

/**
 * Value object which is holding connection data for a specific broker.
 * 
 * @author Andrea Gazzarini
 */
public class BrokerConnectionData
{
    private String _host;
    private int _port;
    private String _virtualHost;
    private String _username;
    private String _password;
    private int _maxPoolCapacity;
    private int _initialPoolCapacity;
    private long _maxWaitTimeout;
    
    /**
     * Builds a connection data with the given parameters.
     * 
 	 * @param host the hostname where the broker is running.
	 * @param port the port where the broker is running.
	 * @param username the username for connecting with the broker.
	 * @param password the password for connecting with the broker.
	 * @param virtualHost the virtual host.
	 * @param initialPoolCapacity the number of connections that must  be immediately opened.
	 * @param maxPoolCapacity the maximum number of opened connection.
	 * @param maxWaitTimeout the maximum amount of time that a client will wait for obtaining a connection.
     */
    public BrokerConnectionData(
    		String host, 
    		int port, 
    		String virtualHost,
			String username, 
			String password, 
			int initialPoolCapacity,
			int maxPoolCapacity, 
			long waitTimeout) {

    	this._host = host;
		this._port = port;
		this._virtualHost = virtualHost;
		this._username = username;
		this._password = password;
		_maxPoolCapacity = maxPoolCapacity;
		_initialPoolCapacity = initialPoolCapacity;
		_maxWaitTimeout = waitTimeout;
	}

	/**
     * Builds a new empty broker connection data object.
     */
    BrokerConnectionData()
    {
    }
    
    /**
     * Sets the value of host property for this connection data.
     * 
     * @param host the host name.
     */
    void setHost (String host)
    {
        this._host = host;
    }

    /**
     * Sets the value of port property for this connection data.
     * 
     * @param port the port.
     */
    void setPort (String port)
    {
        this._port = Integer.parseInt(port);
    }

    /**
     * Sets the value of virtual host property for this connection data.
     * 
     * @param virtualHost the virtual host.
     */
    void setVirtualHost (String virtualHost)
    {
        this._virtualHost = virtualHost;
    }
    
    /**
     * Sets the value of username property for this connection data.
     * 
     * @param username the username.
     */
    void setUsername(String username)
    {
        this._username = username;
    }
    
    /**
     * Sets the value of password property for this connection data.
     * 
     * @param password the password.
     */
    void setPassword(String password) 
    {
        this._password = password;
    }

    /**
     * Returns the value of the host property.
     * 
     * @return the value of the host property.
     */
    public String getHost ()
    {
        return _host;
    }

    /**
     * Returns the value of the port property.
     * 
     * @return the value of the port  property.
     */
    public int getPort ()
    {
        return _port;
    }

    /**
     * Returns the value of the virtual host property.
     * 
     * @return the value of the virtual host property.
     */
    public String getVirtualHost ()
    {
        return _virtualHost;
    }

    /**
     * Returns the value of the username property.
     * 
     * @return the value of the username property.
     */
    public String getUsername ()
    {
        return _username;
    }

    /**
     * Returns the value of the password property.
     * 
     * @return the value of the password property.
     */
    public String getPassword ()
    {
        return _password;
    }
    
    // sofia:5663@pippo/sung1
    @Override
    public String toString ()
    {
        return new StringBuilder()
            .append(_host)
            .append(':')
            .append(_port)
            .append('@')
            .append(_virtualHost)
            .toString();
    }

    /**
     * Sets the max number of allowed connections that can be opened. 
     * 
     * @param value the max number of allowed connections that can be opened.
     * @throws NumberFormatException if the given value is not a valid integer.
     */
    public void setMaxPoolCapacity (String value)
    {
        _maxPoolCapacity = Integer.parseInt(value);
    }
    
    /**
     * Sets the max wait timeout for retrieving an available connections from the pool. 
     * 
     * @param value the max wait timeout for retrieving an available connections from the pool..
     * @throws NumberFormatException if the given value is not a valid long.
     */
    public void setMaxWaitTimeout (String value)
    {
        this._maxWaitTimeout = Long.parseLong(value);
    }
    
    /**
     * Returns the max number of allowed connections that can be opened.
     * 
     * @return the max number of allowed connections that can be opened.
     */
    public int getMaxPoolCapacity ()
    {
        return _maxPoolCapacity;
    }
    
    /**
     * Returns the max wait timeout for retrieving an available connections from the pool.
     * 
     * @return the max wait timeout for retrieving an available connections from the pool.
     */
    public long getMaxWaitTimeout () 
    {
        return _maxWaitTimeout;
    }

    /**
     * Sets the initial connection pool capacity.
     * 
     * @param capacity the initial connection pool capacity.
     */
    public void setInitialPoolCapacity (String capacity)
    {
        _initialPoolCapacity = Integer.parseInt(capacity);
    }
    
    /**
     * Returns the initial connection pool capacity.
     * 
     * @return the initial connection pool capacity.
     */
    public int getInitialPoolCapacity ()
    {
        return _initialPoolCapacity;
    }
    
    @Override
    public boolean equals(Object object) {
    	try 
    	{
			BrokerConnectionData connectionData = (BrokerConnectionData) object;
			return (_host.equals(connectionData._host) )
					&& (_port == connectionData._port)
					&& (_virtualHost.equals(connectionData._virtualHost));
		} catch (Exception exception) {
			return false;
		}
    }
    
    @Override
    public int hashCode() {
    	return _host.hashCode()+_port+_virtualHost.hashCode();
    }
}