1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2009 Oracle.  All rights reserved.
5 *
6 */
7using System;
8using System.Collections.Generic;
9using System.Text;
10
11namespace BerkeleyDB {
12    /// <summary>
13    /// A class representing the address of a replication site used by Berkeley
14    /// DB HA.
15    /// </summary>
16    public class ReplicationHostAddress {
17        /// <summary>
18        /// The site's host identification string, generally a TCP/IP host name.
19        /// </summary>
20        public string Host;
21        /// <summary>
22        /// The port number on which the site is receiving.
23        /// </summary>
24        public uint Port;
25
26        /// <summary>
27        /// Instantiate a new, empty address
28        /// </summary>
29        public ReplicationHostAddress() { }
30        /// <summary>
31        /// Instantiate a new address, parsing the host and port from the given
32        /// string
33        /// </summary>
34        /// <param name="HostAndPort">A string in host:port format</param>
35        public ReplicationHostAddress(string HostAndPort) {
36            int sep = HostAndPort.IndexOf(':');
37            if (sep == -1)
38                throw new ArgumentException(
39                    "Hostname and port must be separated by a colon.");
40            if (sep == 0)
41                throw new ArgumentException(
42                    "Invalid hostname.");
43            try {
44                Port = UInt32.Parse(HostAndPort.Substring(sep + 1));
45            } catch {
46                throw new ArgumentException("Invalid port number.");
47            }
48            Host = HostAndPort.Substring(0, sep);
49        }
50        /// <summary>
51        /// Instantiate a new address
52        /// </summary>
53        /// <param name="Host">The site's host identification string</param>
54        /// <param name="Port">
55        /// The port number on which the site is receiving.
56        /// </param>
57        public ReplicationHostAddress(string Host, uint Port) {
58            this.Host = Host;
59            this.Port = Port;
60        }
61    }
62}
63