001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021 package org.apache.qpid.management.configuration;
022
023 /**
024 * Value object which is holding connection data for a specific broker.
025 *
026 * @author Andrea Gazzarini
027 */
028 public class BrokerConnectionData
029 {
030 private String _host;
031 private int _port;
032 private String _virtualHost;
033 private String _username;
034 private String _password;
035 private int _maxPoolCapacity;
036 private int _initialPoolCapacity;
037 private long _maxWaitTimeout;
038
039 /**
040 * Builds a connection data with the given parameters.
041 *
042 * @param host the hostname where the broker is running.
043 * @param port the port where the broker is running.
044 * @param username the username for connecting with the broker.
045 * @param password the password for connecting with the broker.
046 * @param virtualHost the virtual host.
047 * @param initialPoolCapacity the number of connections that must be immediately opened.
048 * @param maxPoolCapacity the maximum number of opened connection.
049 * @param maxWaitTimeout the maximum amount of time that a client will wait for obtaining a connection.
050 */
051 public BrokerConnectionData(
052 String host,
053 int port,
054 String virtualHost,
055 String username,
056 String password,
057 int initialPoolCapacity,
058 int maxPoolCapacity,
059 long waitTimeout) {
060
061 this._host = host;
062 this._port = port;
063 this._virtualHost = virtualHost;
064 this._username = username;
065 this._password = password;
066 _maxPoolCapacity = maxPoolCapacity;
067 _initialPoolCapacity = initialPoolCapacity;
068 _maxWaitTimeout = waitTimeout;
069 }
070
071 /**
072 * Builds a new empty broker connection data object.
073 */
074 BrokerConnectionData()
075 {
076 }
077
078 /**
079 * Sets the value of host property for this connection data.
080 *
081 * @param host the host name.
082 */
083 void setHost (String host)
084 {
085 this._host = host;
086 }
087
088 /**
089 * Sets the value of port property for this connection data.
090 *
091 * @param port the port.
092 */
093 void setPort (String port)
094 {
095 this._port = Integer.parseInt(port);
096 }
097
098 /**
099 * Sets the value of virtual host property for this connection data.
100 *
101 * @param virtualHost the virtual host.
102 */
103 void setVirtualHost (String virtualHost)
104 {
105 this._virtualHost = virtualHost;
106 }
107
108 /**
109 * Sets the value of username property for this connection data.
110 *
111 * @param username the username.
112 */
113 void setUsername(String username)
114 {
115 this._username = username;
116 }
117
118 /**
119 * Sets the value of password property for this connection data.
120 *
121 * @param password the password.
122 */
123 void setPassword(String password)
124 {
125 this._password = password;
126 }
127
128 /**
129 * Returns the value of the host property.
130 *
131 * @return the value of the host property.
132 */
133 public String getHost ()
134 {
135 return _host;
136 }
137
138 /**
139 * Returns the value of the port property.
140 *
141 * @return the value of the port property.
142 */
143 public int getPort ()
144 {
145 return _port;
146 }
147
148 /**
149 * Returns the value of the virtual host property.
150 *
151 * @return the value of the virtual host property.
152 */
153 public String getVirtualHost ()
154 {
155 return _virtualHost;
156 }
157
158 /**
159 * Returns the value of the username property.
160 *
161 * @return the value of the username property.
162 */
163 public String getUsername ()
164 {
165 return _username;
166 }
167
168 /**
169 * Returns the value of the password property.
170 *
171 * @return the value of the password property.
172 */
173 public String getPassword ()
174 {
175 return _password;
176 }
177
178 // sofia:5663@pippo/sung1
179 @Override
180 public String toString ()
181 {
182 return new StringBuilder()
183 .append(_host)
184 .append(':')
185 .append(_port)
186 .append('@')
187 .append(_virtualHost)
188 .toString();
189 }
190
191 /**
192 * Sets the max number of allowed connections that can be opened.
193 *
194 * @param value the max number of allowed connections that can be opened.
195 * @throws NumberFormatException if the given value is not a valid integer.
196 */
197 public void setMaxPoolCapacity (String value)
198 {
199 _maxPoolCapacity = Integer.parseInt(value);
200 }
201
202 /**
203 * Sets the max wait timeout for retrieving an available connections from the pool.
204 *
205 * @param value the max wait timeout for retrieving an available connections from the pool..
206 * @throws NumberFormatException if the given value is not a valid long.
207 */
208 public void setMaxWaitTimeout (String value)
209 {
210 this._maxWaitTimeout = Long.parseLong(value);
211 }
212
213 /**
214 * Returns the max number of allowed connections that can be opened.
215 *
216 * @return the max number of allowed connections that can be opened.
217 */
218 public int getMaxPoolCapacity ()
219 {
220 return _maxPoolCapacity;
221 }
222
223 /**
224 * Returns the max wait timeout for retrieving an available connections from the pool.
225 *
226 * @return the max wait timeout for retrieving an available connections from the pool.
227 */
228 public long getMaxWaitTimeout ()
229 {
230 return _maxWaitTimeout;
231 }
232
233 /**
234 * Sets the initial connection pool capacity.
235 *
236 * @param capacity the initial connection pool capacity.
237 */
238 public void setInitialPoolCapacity (String capacity)
239 {
240 _initialPoolCapacity = Integer.parseInt(capacity);
241 }
242
243 /**
244 * Returns the initial connection pool capacity.
245 *
246 * @return the initial connection pool capacity.
247 */
248 public int getInitialPoolCapacity ()
249 {
250 return _initialPoolCapacity;
251 }
252
253 @Override
254 public boolean equals(Object object) {
255 try
256 {
257 BrokerConnectionData connectionData = (BrokerConnectionData) object;
258 return (_host.equals(connectionData._host) )
259 && (_port == connectionData._port)
260 && (_virtualHost.equals(connectionData._virtualHost));
261 } catch (Exception exception) {
262 return false;
263 }
264 }
265
266 @Override
267 public int hashCode() {
268 return _host.hashCode()+_port+_virtualHost.hashCode();
269 }
270 }
|