Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f0762b

Browse files
committed
AJ-213 - Added debug properties for manager events: file, func, line and sequenceNumber
1 parent e9eccba commit 5f0762b

File tree

1 file changed

+129
-16
lines changed

1 file changed

+129
-16
lines changed

src/main/java/org/asteriskjava/manager/event/ManagerEvent.java

Lines changed: 129 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
package org.asteriskjava.manager.event;
1818

1919
import java.lang.reflect.Method;
20-
import java.util.Date;
21-
import java.util.EventObject;
22-
import java.util.Map;
20+
import java.util.*;
2321

2422
import org.asteriskjava.util.ReflectionUtil;
2523

@@ -41,7 +39,7 @@ public abstract class ManagerEvent extends EventObject
4139
/**
4240
* Serializable version identifier.
4341
*/
44-
static final long serialVersionUID = 1L;
42+
static final long serialVersionUID = 2L;
4543

4644
/**
4745
* AMI authorization class.
@@ -60,6 +58,12 @@ public abstract class ManagerEvent extends EventObject
6058
*/
6159
private String server;
6260

61+
// AJ-213 only used when debugging is turned on
62+
private String file;
63+
private Integer line;
64+
private String func;
65+
private Integer sequenceNumber;
66+
6367
public ManagerEvent(Object source)
6468
{
6569
super(source);
@@ -167,24 +171,110 @@ public final void setServer(String server)
167171
this.server = server;
168172
}
169173

174+
/**
175+
* Returns the name of the file in Asterisk's source code that triggered this event. For example
176+
* <code>pbx.c</code>.<p>
177+
* This property is only available if debugging for the Manager API has been turned on in Asterisk. This can be
178+
* done by calling <code>manager debug on</code> on Asterisk's command line interface or by adding
179+
* <code>debug=on</code> to Asterisk's <code>manager.conf</code>. This feature is availble in Asterisk since 1.6.0.
180+
*
181+
* @return the name of the file in that triggered this event or <code>null</code> if debgging is turned off.
182+
* @see #getFunc()
183+
* @see #getLine()
184+
* @since 1.0.0
185+
*/
186+
public String getFile()
187+
{
188+
return file;
189+
}
190+
191+
public void setFile(String file)
192+
{
193+
this.file = file;
194+
}
195+
196+
/**
197+
* Returns the line number in Asterisk's source code where this event was triggered.<p>
198+
* This property is only available if debugging for the Manager API has been turned on in Asterisk. This can be
199+
* done by calling <code>manager debug on</code> on Asterisk's command line interface or by adding
200+
* <code>debug=on</code> to Asterisk's <code>manager.conf</code>. This feature is availble in Asterisk since 1.6.0.
201+
*
202+
* @return the line number where this event was triggered or <code>null</code> if debgging is turned off.
203+
* @see #getFile()
204+
* @see #getFunc()
205+
* @since 1.0.0
206+
*/
207+
public Integer getLine()
208+
{
209+
return line;
210+
}
211+
212+
public void setLine(Integer line)
213+
{
214+
this.line = line;
215+
}
216+
217+
/**
218+
* Returns the name of the C function in Asterisk's source code that triggered this event. For example
219+
* <code>pbx_builtin_setvar_helper</code><p>
220+
* This property is only available if debugging for the Manager API has been turned on in Asterisk. This can be
221+
* done by calling <code>manager debug on</code> on Asterisk's command line interface or by adding
222+
* <code>debug=on</code> to Asterisk's <code>manager.conf</code>. This feature is availble in Asterisk since 1.6.0.
223+
*
224+
* @return the name of the C function that triggered this event or <code>null</code> if debgging is turned off.
225+
* @see #getFile()
226+
* @see #getLine()
227+
* @since 1.0.0
228+
*/
229+
public String getFunc()
230+
{
231+
return func;
232+
}
233+
234+
public void setFunc(String func)
235+
{
236+
this.func = func;
237+
}
238+
239+
/**
240+
* Returns the sequence numbers of this event. Sequence numbers are only incremented while debugging is enabled.<p>
241+
* This property is only available if debugging for the Manager API has been turned on in Asterisk. This can be
242+
* done by calling <code>manager debug on</code> on Asterisk's command line interface or by adding
243+
* <code>debug=on</code> to Asterisk's <code>manager.conf</code>. This feature is availble in Asterisk since 1.6.0.
244+
*
245+
* @return the sequence number of this event or <code>null</code> if debgging is turned off.
246+
* @see #getFile()
247+
* @see #getLine()
248+
* @since 1.0.0
249+
*/
250+
public Integer getSequenceNumber()
251+
{
252+
return sequenceNumber;
253+
}
254+
255+
public void setSequenceNumber(Integer sequenceNumber)
256+
{
257+
this.sequenceNumber = sequenceNumber;
258+
}
259+
170260
@Override
171261
public String toString()
172262
{
173-
StringBuffer sb;
174-
Map<String, Method> getters;
263+
final List<String> localProperties = Arrays.asList(
264+
"datereceived", "privilege", "file", "func", "line", "sequenceNumber", "source", "class");
265+
final StringBuilder sb = new StringBuilder(getClass().getName() + "[");
266+
appendPropertyIfNotNull(sb, "file", getFile());
267+
appendPropertyIfNotNull(sb, "func", getFunc());
268+
appendPropertyIfNotNull(sb, "line", getLine());
269+
appendPropertyIfNotNull(sb, "sequenceNumber", getSequenceNumber());
270+
appendPropertyIfNotNull(sb, "dateReceived", getDateReceived());
271+
appendPropertyIfNotNull(sb, "privilege", getPrivilege());
175272

176-
sb = new StringBuffer(getClass().getName() + "[");
177-
sb.append("dateReceived=").append(getDateReceived()).append(",");
178-
if (getPrivilege() != null)
179-
{
180-
sb.append("privilege='").append(getPrivilege()).append("',");
181-
}
182-
getters = ReflectionUtil.getGetters(getClass());
183-
for (Map.Entry<String, Method> entry: getters.entrySet())
273+
final Map<String, Method> getters = ReflectionUtil.getGetters(getClass());
274+
for (Map.Entry<String, Method> entry : getters.entrySet())
184275
{
185276
final String attribute = entry.getKey();
186-
if ("class".equals(attribute) || "datereceived".equals(attribute) || "privilege".equals(attribute)
187-
|| "source".equals(attribute))
277+
if (localProperties.contains(attribute))
188278
{
189279
continue;
190280
}
@@ -205,4 +295,27 @@ public String toString()
205295

206296
return sb.toString();
207297
}
298+
299+
protected void appendPropertyIfNotNull(StringBuilder sb, String property, Object value)
300+
{
301+
if (value != null)
302+
{
303+
appendProperty(sb, property, value);
304+
}
305+
}
306+
307+
private void appendProperty(StringBuilder sb, String property, Object value)
308+
{
309+
sb.append(property).append("=");
310+
if (value == null)
311+
{
312+
sb.append("null");
313+
}
314+
else
315+
{
316+
sb.append("'").append(value).append("'");
317+
}
318+
sb.append(",");
319+
320+
}
208321
}

0 commit comments

Comments
 (0)