1 /*
2 * Copyright 2004-2006 Stefan Reuter
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package org.asteriskjava.manager.event;
18
19 /**
20 * A QueueMemberEvent is triggered in response to a QueueStatusAction and
21 * contains information about a member of a queue.
22 * <p>
23 * It is implemented in <code>apps/app_queue.c</code>
24 *
25 * @see org.asteriskjava.manager.action.QueueStatusAction
26 * @author srt
27 * @version $Id$
28 */
29 public class QueueMemberEvent extends ResponseEvent
30 {
31 public static final int AST_DEVICE_UNKNOWN = 0;
32
33 /**
34 * Queue member is available.
35 */
36 public static final int AST_DEVICE_NOT_INUSE = 1;
37 public static final int AST_DEVICE_INUSE = 2;
38 public static final int AST_DEVICE_BUSY = 3;
39 public static final int AST_DEVICE_INVALID = 4;
40 public static final int AST_DEVICE_UNAVAILABLE = 5;
41 public static final int AST_DEVICE_RINGING = 6;
42 public static final int AST_DEVICE_RINGINUSE = 7;
43 public static final int AST_DEVICE_ONHOLD = 8;
44
45 public static final String MEMBERSHIP_STATIC = "static";
46 public static final String MEMBERSHIP_DYNAMIC = "dynamic";
47
48 /**
49 * Serializable version identifier.
50 */
51 private static final long serialVersionUID = 0L;
52 private String queue;
53 private String location;
54 private String membership;
55 private String name;
56 private Integer penalty;
57 private Integer callsTaken;
58 private Long lastCall;
59 private Integer status;
60 private Boolean paused;
61
62 /**
63 * @param source
64 */
65 public QueueMemberEvent(Object source)
66 {
67 super(source);
68 }
69
70 /**
71 * Returns the name of the queue.
72 *
73 * @return the name of the queue.
74 */
75 public String getQueue()
76 {
77 return queue;
78 }
79
80 /**
81 * Sets the name of the queue.
82 *
83 * @param queue the name of the queue.
84 */
85 public void setQueue(String queue)
86 {
87 this.queue = queue;
88 }
89
90 /**
91 * Returns the name of the member's interface.
92 * <p>
93 * E.g. the channel name or agent group (for example "Agent/@1").
94 *
95 * @return the name of the member's interface.
96 */
97 public String getLocation()
98 {
99 return location;
100 }
101
102 /**
103 * Sets the name of the member's interface.
104 *
105 * @param location the name of the member's interface.
106 */
107 public void setLocation(String location)
108 {
109 this.location = location;
110 }
111
112 /**
113 * Returns if this member has been dynamically added by the QueueAdd command
114 * (in the dialplan or via the Manager API) or if this member is has been
115 * statically defined in <code>queues.conf</code>.
116 *
117 * @return "dynamic" if the added member is a dynamic queue member, "static"
118 * if the added member is a static queue member.
119 */
120 public String getMembership()
121 {
122 return membership;
123 }
124
125 /**
126 * Convenience method that checks whether this member has been statically
127 * defined in <code>queues.conf</code>.
128 *
129 * @return <code>true</code> if this member has been statically defined in
130 * <code>queues.conf</code>, <code>false</code> otherwise.
131 * @since 0.3
132 */
133 public boolean isStatic()
134 {
135 return MEMBERSHIP_STATIC.equals(membership);
136 }
137
138 /**
139 * Convenience method that checks whether this member has been dynamically
140 * added by the QueueAdd command.
141 *
142 * @return <code>true</code> if this member has been dynamically added by
143 * the QueueAdd command, <code>false</code> otherwise.
144 * @since 0.3
145 */
146 public boolean isDynamic()
147 {
148 return MEMBERSHIP_DYNAMIC.equals(membership);
149 }
150
151 /**
152 * Sets if this member has been dynamically or statically added.
153 *
154 * @param membership "dynamic" if the added member is a dynamic queue
155 * member, "static" if the added member is a static queue member.
156 */
157 public void setMembership(String membership)
158 {
159 this.membership = membership;
160 }
161
162 /**
163 * Returns the penalty for the added member. When calls are distributed
164 * members with higher penalties are considered last.
165 *
166 * @return the penalty for the added member.
167 */
168 public Integer getPenalty()
169 {
170 return penalty;
171 }
172
173 /**
174 * Sets the penalty for this member.
175 *
176 * @param penalty the penalty for this member.
177 */
178 public void setPenalty(Integer penalty)
179 {
180 this.penalty = penalty;
181 }
182
183 /**
184 * Returns the number of calls answered by the member.
185 *
186 * @return the number of calls answered by the member.
187 */
188 public Integer getCallsTaken()
189 {
190 return callsTaken;
191 }
192
193 /**
194 * Sets the number of calls answered by the added member.
195 *
196 * @param callsTaken the number of calls answered by the added member.
197 */
198 public void setCallsTaken(Integer callsTaken)
199 {
200 this.callsTaken = callsTaken;
201 }
202
203 /**
204 * Returns the time the last successful call answered by the added member
205 * was hungup.
206 *
207 * @return the time (in seconds since 01/01/1970) the last successful call
208 * answered by the added member was hungup.
209 */
210 public Long getLastCall()
211 {
212 return lastCall;
213 }
214
215 /**
216 * Sets the time the last successful call answered by this member was
217 * hungup.
218 *
219 * @param lastCall the time (in seconds since 01/01/1970) the last
220 * successful call answered by the added member was hungup.
221 */
222 public void setLastCall(Long lastCall)
223 {
224 this.lastCall = lastCall;
225 }
226
227 /**
228 * Returns the status of this queue member.
229 * <p>
230 * Available since Asterisk 1.2
231 * <p>
232 * Valid status codes are:
233 * <dl>
234 * <dt>AST_DEVICE_UNKNOWN (0)</dt>
235 * <dd>Device valid but unknown channel state</dd>
236 * <dt>AST_DEVICE_NOT_INUSE (1)</dt>
237 * <dd>Device is not used</dd>
238 * <dt>AST_DEVICE_INUSE (2)</dt>
239 * <dd>Device is in use</dd>
240 * <dt>AST_DEVICE_BUSY (3)</dt>
241 * <dd>Device is Busy</dd>
242 * <dt>AST_DEVICE_INVALID (4)</dt>
243 * <dd>Device is invalid</dd>
244 * <dt>AST_DEVICE_UNAVAILABLE (5)</dt>
245 * <dd>Device is unavaiable</dd>
246 * <dt>AST_DEVICE_RINGING (6)</dt>
247 * <dd>Device is ringing</dd>
248 * <dt>AST_DEVICE_RINGINUSE (7)</dt>
249 * <dd>Device is ringing and in use</dd>
250 * <dt>AST_DEVICE_ONHOLD (8)</dt>
251 * <dd>Device is on hold</dd>
252
253 * </dl>
254 *
255 * @return the status of this queue member or <code>null</code> if this
256 * attribute is not supported by your version of Asterisk.
257 * @since 0.2
258 */
259 public Integer getStatus()
260 {
261 return status;
262 }
263
264 /**
265 * Sets the status of this queue member.
266 *
267 * @param status the status of this queue member
268 * @since 0.2
269 */
270 public void setStatus(Integer status)
271 {
272 this.status = status;
273 }
274
275 /**
276 * Is this queue member paused (not accepting calls)?
277 * <p>
278 * Available since Asterisk 1.2.
279 *
280 * @return <code>Boolean.TRUE</code> if this member has been paused,
281 * <code>Boolean.FALSE</code> if not or <code>null</code> if
282 * pausing is not supported by your version of Asterisk.
283 * @since 0.2
284 */
285 public Boolean getPaused()
286 {
287 return paused;
288 }
289
290 /**
291 * Sets if this member has been paused.
292 *
293 * @since 0.2
294 */
295 public void setPaused(Boolean paused)
296 {
297 this.paused = paused;
298 }
299
300 /**
301 * Returns the name of the member.
302 *
303 * @return the name of the member supplied for logging when the member is added
304 * @since 1.0.0
305 */
306 public String getName()
307 {
308 return name;
309 }
310
311 public void setName(String name)
312 {
313 this.name = name;
314 }
315
316 /**
317 * Returns the name of the member.
318 *
319 * @return the name of the member supplied for logging when the member is added
320 * @deprecated since 1.0.0. Use {@link #getName()} instead.
321 */
322 @Deprecated public String getMemberName()
323 {
324 return name;
325 }
326
327 // Renamed to "name" in Asterisk 1.6
328 public void setMemberName(String memberName)
329 {
330 this.name = memberName;
331 }
332 }