1
2
3
4
5 package net.sf.asterisk.manager;
6
7 import java.io.Serializable;
8
9 /***
10 * Represents an Asterisk server that is connected via the Manager API.
11 *
12 * @author PY
13 * @version $Id: AsteriskServer.java,v 1.4 2005/03/04 22:21:04 srt Exp $
14 */
15 public class AsteriskServer implements Serializable
16 {
17 /***
18 * Serializable version identifier
19 */
20 private static final long serialVersionUID = 3257284738393125176L;
21
22 /***
23 * The hostname to use if none is provided.
24 */
25 private static final String DEFAULT_HOSTNAME = "localhost";
26
27 /***
28 * The port to use if none is provided.
29 */
30 private static final int DEFAULT_PORT = 5038;
31
32 /***
33 * The hostname of the Asterisk server.
34 */
35 private String hostname;
36
37 /***
38 * The port on the Asterisk server the Asterisk Manager API is listening on.
39 */
40 private int port;
41
42 /***
43 * Creates a new AsteriskServer with default hostname and default port.
44 */
45 public AsteriskServer()
46 {
47 this.hostname = DEFAULT_HOSTNAME;
48 this.port = DEFAULT_PORT;
49 }
50
51 /***
52 * Creates a new Asterisk server with the given hostname and port.
53 *
54 * @param hostname the hostname of the Asterisk server
55 * @param port the port on the Asterisk server the Asterisk Manager API is listening on
56 */
57 public AsteriskServer(final String hostname, final int port)
58 {
59 this.hostname = hostname;
60 this.port = port;
61 }
62
63 /***
64 * Returns the hostname.
65 *
66 * @return the hostname
67 */
68 public final String getHostname()
69 {
70 return hostname;
71 }
72
73 /***
74 * Sets the hostname.
75 *
76 * @param hostname the hostname to set
77 */
78 public final void setHostname(final String hostname)
79 {
80 this.hostname = hostname;
81 }
82
83 /***
84 * Returns the port.
85 *
86 * @return the port
87 */
88 public final int getPort()
89 {
90 return port;
91 }
92
93 /***
94 * Sets the port.
95 *
96 * @param port the port to set.
97 */
98 public final void setPort(final int port)
99 {
100 this.port = port;
101 }
102
103 public boolean equals(Object o)
104 {
105 if (o == null || !(o instanceof AsteriskServer))
106 {
107 return false;
108 }
109
110 AsteriskServer s = (AsteriskServer) o;
111 if (this.getHostname() != null)
112 {
113 if (!this.getHostname().equals(s.getHostname()))
114 {
115 return false;
116 }
117 }
118 else
119 {
120 if (s.getHostname() != null)
121 {
122 return false;
123 }
124 }
125
126 if (this.getPort() != s.getPort())
127 {
128 return false;
129 }
130
131 return true;
132 }
133
134 public String toString()
135 {
136 return "AsteriskServer[hostname='" + hostname + "',port=" + port + "]";
137 }
138 }