01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2005 Emic Networks.
04: * Contact: sequoia@continuent.org
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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: *
18: * Initial developer(s): Emmanuel Cecchet.
19: * Contributor(s): Gilles Rayrat.
20: */package org.continuent.sequoia.driver;
21:
22: import java.net.InetSocketAddress;
23: import java.net.UnknownHostException;
24:
25: /**
26: * Controller related information, namely the host address and the port on which
27: * the controller is running.<br>
28: * This class actually extends <code>InetSocketAddress</code> with similar
29: * constructor from name and port, which catches name resolution issues to throw
30: * an UnknownHostException.<br>
31: * A second constructor from <code>InetSocketAddress</code> is available to
32: * create a ControllerInfo from (for example) a udp packet.
33: *
34: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
35: * </a>
36: * @version 1.0
37: */
38: public class ControllerInfo extends InetSocketAddress {
39: private static final long serialVersionUID = 1L;
40:
41: /**
42: * Creates a new <code>ControllerInfo</code> object from a hostname and a
43: * port number by trying to resolve given hostname. If resolution fails,
44: * throws and {@link UnknownHostException}
45: *
46: * @param hostname the controller host name
47: * @param port the controller port
48: * @throws UnknownHostException if the given name could not be resolved
49: * @see InetSocketAddress#InetSocketAddress(String, int)
50: */
51: public ControllerInfo(String hostname, int port)
52: throws UnknownHostException {
53: super (hostname, port);
54: if (isUnresolved()) {
55: throw new UnknownHostException("Hostname " + hostname
56: + " could not be resolved");
57: }
58: }
59:
60: /**
61: * Creates a new <code>ControllerInfo</code> object from a given
62: * <code>InetSocketAddress</code>. This constructor actually is a wrapper
63: * of {@link InetSocketAddress#InetSocketAddress(java.net.InetAddress, int)}
64: */
65: public ControllerInfo(InetSocketAddress addr) {
66: super(addr.getAddress(), addr.getPort());
67: }
68: }
|