All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.asteriskjava.manager.event.ManagerEvent Maven / Gradle / Ivy

There is a newer version: 3.39.0
Show newest version
/*
 *  Copyright 2004-2006 Stefan Reuter
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.asteriskjava.manager.event;

import java.lang.reflect.Method;
import java.util.*;

import org.asteriskjava.util.ReflectionUtil;

/**
 * Abstract base class for all Events that can be received from the Asterisk
 * server.
 * 

* Events contain data pertaining to an event generated from within the Asterisk * core or an extension module. *

* There is one conrete subclass of ManagerEvent per each supported Asterisk * Event. * * @author srt * @version $Id: ManagerEvent.java 1351 2009-07-21 21:01:45Z srt $ */ public abstract class ManagerEvent extends EventObject { /** * Serializable version identifier. */ static final long serialVersionUID = 2L; /** * AMI authorization class. */ private String privilege; /** * The point in time this event has been received from the Asterisk server. */ private Date dateReceived; private Double timestamp; /** * The server from which this event has been received (only used with AstManProxy). */ private String server; // AJ-213 only used when debugging is turned on private String file; private Integer line; private String func; private Integer sequenceNumber; public ManagerEvent(Object source) { super(source); } /** * Returns the point in time this event was received from the Asterisk * server. *

* Pseudo events that are not directly received from the asterisk server * (for example ConnectEvent and DisconnectEvent) may return * null. */ public Date getDateReceived() { return dateReceived; } /** * Sets the point in time this event was received from the asterisk server. */ public void setDateReceived(Date dateReceived) { this.dateReceived = dateReceived; } /** * Returns the AMI authorization class of this event. *

* This is one or more of system, call, log, verbose, command, agent or * user. Multiple privileges are separated by comma. *

* Note: This property is not available from Asterisk 1.0 servers. * * @since 0.2 */ public String getPrivilege() { return privilege; } /** * Sets the AMI authorization class of this event. * * @since 0.2 */ public void setPrivilege(String privilege) { this.privilege = privilege; } /** * Returns the timestamp for this event. *

* The timestamp property is available in Asterisk since 1.4 if enabled in * manager.conf by setting timestampevents = yes. *

* In contains the time the event was generated in seconds since the epoch. *

* Example: 1159310429.569108 * * @return the timestamp for this event. * @since 0.3 */ public final Double getTimestamp() { return timestamp; } /** * Sets the timestamp for this event. * * @param timestamp the timestamp to set. * @since 0.3 */ public final void setTimestamp(Double timestamp) { this.timestamp = timestamp; } /** * Returns the name of the Asterisk server from which this event has been received. *

* This property is only available when using to AstManProxy. * * @return the name of the Asterisk server from which this event has been received * or null when directly connected to an Asterisk server * instead of AstManProxy. * @since 1.0.0 */ public final String getServer() { return server; } /** * Sets the name of the Asterisk server from which this event has been received. * * @param server the name of the Asterisk server from which this event has been received. * @since 1.0.0 */ public final void setServer(String server) { this.server = server; } /** * Returns the name of the file in Asterisk's source code that triggered this event. For example * pbx.c.

* This property is only available if debugging for the Manager API has been turned on in Asterisk. This can be * done by calling manager debug on on Asterisk's command line interface or by adding * debug=on to Asterisk's manager.conf. This feature is availble in Asterisk since 1.6.0. * * @return the name of the file in that triggered this event or null if debgging is turned off. * @see #getFunc() * @see #getLine() * @since 1.0.0 */ public String getFile() { return file; } public void setFile(String file) { this.file = file; } /** * Returns the line number in Asterisk's source code where this event was triggered.

* This property is only available if debugging for the Manager API has been turned on in Asterisk. This can be * done by calling manager debug on on Asterisk's command line interface or by adding * debug=on to Asterisk's manager.conf. This feature is availble in Asterisk since 1.6.0. * * @return the line number where this event was triggered or null if debgging is turned off. * @see #getFile() * @see #getFunc() * @since 1.0.0 */ public Integer getLine() { return line; } public void setLine(Integer line) { this.line = line; } /** * Returns the name of the C function in Asterisk's source code that triggered this event. For example * pbx_builtin_setvar_helper

* This property is only available if debugging for the Manager API has been turned on in Asterisk. This can be * done by calling manager debug on on Asterisk's command line interface or by adding * debug=on to Asterisk's manager.conf. This feature is availble in Asterisk since 1.6.0. * * @return the name of the C function that triggered this event or null if debgging is turned off. * @see #getFile() * @see #getLine() * @since 1.0.0 */ public String getFunc() { return func; } public void setFunc(String func) { this.func = func; } /** * Returns the sequence numbers of this event. Sequence numbers are only incremented while debugging is enabled.

* This property is only available if debugging for the Manager API has been turned on in Asterisk. This can be * done by calling manager debug on on Asterisk's command line interface or by adding * debug=on to Asterisk's manager.conf. This feature is availble in Asterisk since 1.6.0. * * @return the sequence number of this event or null if debgging is turned off. * @see #getFile() * @see #getLine() * @since 1.0.0 */ public Integer getSequenceNumber() { return sequenceNumber; } public void setSequenceNumber(Integer sequenceNumber) { this.sequenceNumber = sequenceNumber; } @Override public String toString() { final List ignoredProperties = Arrays.asList( "file", "func", "line", "sequenceNumber", "datereceived", "privilege", "source", "class"); final StringBuilder sb = new StringBuilder(getClass().getName() + "["); appendPropertyIfNotNull(sb, "file", getFile()); appendPropertyIfNotNull(sb, "func", getFunc()); appendPropertyIfNotNull(sb, "line", getLine()); appendPropertyIfNotNull(sb, "sequenceNumber", getSequenceNumber()); appendPropertyIfNotNull(sb, "dateReceived", getDateReceived()); appendPropertyIfNotNull(sb, "privilege", getPrivilege()); final Map getters = ReflectionUtil.getGetters(getClass()); for (Map.Entry entry : getters.entrySet()) { final String property = entry.getKey(); if (ignoredProperties.contains(property)) { continue; } try { final Object value = entry.getValue().invoke(this); appendProperty(sb, property, value); } catch (Exception e) // NOPMD { // swallow } } sb.append("systemHashcode=").append(System.identityHashCode(this)); sb.append("]"); return sb.toString(); } protected void appendPropertyIfNotNull(StringBuilder sb, String property, Object value) { if (value != null) { appendProperty(sb, property, value); } } private void appendProperty(StringBuilder sb, String property, Object value) { sb.append(property).append("="); if (value == null) { sb.append("null"); } else { sb.append("'").append(value).append("'"); } sb.append(","); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy