asterisk-java-cvs Mailing List for Asterisk-Java Library (Page 80)
Brought to you by:
srt
You can subscribe to this list here.
2005 |
Jan
(4) |
Feb
(75) |
Mar
(211) |
Apr
(70) |
May
(12) |
Jun
(7) |
Jul
(96) |
Aug
(90) |
Sep
(11) |
Oct
(42) |
Nov
(45) |
Dec
(4) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(20) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(32) |
Aug
|
Sep
(4) |
Oct
(2) |
Nov
(10) |
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(4) |
Jul
(3) |
Aug
(73) |
Sep
(13) |
Oct
(4) |
Nov
(1) |
Dec
(7) |
2009 |
Jan
(1) |
Feb
(2) |
Mar
(48) |
Apr
(21) |
May
(14) |
Jun
(11) |
Jul
(9) |
Aug
(2) |
Sep
(11) |
Oct
(14) |
Nov
(6) |
Dec
(4) |
2010 |
Jan
(3) |
Feb
(2) |
Mar
|
Apr
|
May
(3) |
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
(9) |
Nov
|
Dec
(12) |
2011 |
Jan
(1) |
Feb
(5) |
Mar
(7) |
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(10) |
Sep
|
Oct
(5) |
Nov
|
Dec
|
2012 |
Jan
(3) |
Feb
|
Mar
(3) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(3) |
Oct
|
Nov
(2) |
Dec
(2) |
2013 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
(2) |
Nov
|
Dec
(1) |
2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(5) |
2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
(25) |
May
(10) |
Jun
(4) |
Jul
(7) |
Aug
(4) |
Sep
(1) |
Oct
(1) |
Nov
(3) |
Dec
(1) |
2016 |
Jan
|
Feb
(42) |
Mar
(6) |
Apr
(15) |
May
(3) |
Jun
(1) |
Jul
(11) |
Aug
|
Sep
|
Oct
(17) |
Nov
(2) |
Dec
|
2017 |
Jan
|
Feb
(4) |
Mar
(1) |
Apr
(3) |
May
(2) |
Jun
(3) |
Jul
(7) |
Aug
(11) |
Sep
(5) |
Oct
(7) |
Nov
(4) |
Dec
(4) |
2018 |
Jan
(11) |
Feb
(11) |
Mar
(3) |
Apr
|
May
(9) |
Jun
(6) |
Jul
(17) |
Aug
(9) |
Sep
(2) |
Oct
(4) |
Nov
(3) |
Dec
(3) |
2019 |
Jan
(13) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(5) |
Jun
|
Jul
(1) |
Aug
(6) |
Sep
|
Oct
|
Nov
(3) |
Dec
|
2020 |
Jan
(2) |
Feb
(72) |
Mar
(8) |
Apr
(11) |
May
(12) |
Jun
(3) |
Jul
(12) |
Aug
(3) |
Sep
(5) |
Oct
(4) |
Nov
|
Dec
(9) |
2021 |
Jan
|
Feb
(31) |
Mar
(6) |
Apr
(3) |
May
|
Jun
(2) |
Jul
|
Aug
(2) |
Sep
|
Oct
(9) |
Nov
|
Dec
(32) |
2022 |
Jan
(5) |
Feb
(7) |
Mar
(2) |
Apr
(3) |
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
(2) |
Oct
(111) |
Nov
(105) |
Dec
(26) |
2023 |
Jan
(25) |
Feb
(6) |
Mar
(10) |
Apr
(54) |
May
(41) |
Jun
(24) |
Jul
(6) |
Aug
(11) |
Sep
(9) |
Oct
(8) |
Nov
(55) |
Dec
(34) |
2024 |
Jan
(6) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(89) |
Sep
(48) |
Oct
(31) |
Nov
(9) |
Dec
(19) |
2025 |
Jan
(12) |
Feb
(18) |
Mar
(9) |
Apr
(7) |
May
|
Jun
(7) |
Jul
(5) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Stefan R. <sr...@us...> - 2005-07-26 11:37:57
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1942/src/java/net/sf/asterisk/manager Modified Files: DefaultAsteriskManager.java Log Message: Allow skipping of Queue initialization for faster startup on buggy, i.e. 1.0 Asterisk servers. Index: DefaultAsteriskManager.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultAsteriskManager.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -p -r1.9 -r1.10 --- DefaultAsteriskManager.java 24 Jul 2005 18:06:13 -0000 1.9 +++ DefaultAsteriskManager.java 26 Jul 2005 11:37:49 -0000 1.10 @@ -66,18 +66,28 @@ public class DefaultAsteriskManager private final Map channels; /** - * Sequence to track calls. + * A map of ACD queues by there name. */ - private int callSequence; - private final Map queues; + /** + * Creates a new instance. + */ public DefaultAsteriskManager() { this.channels = Collections.synchronizedMap(new HashMap()); this.queues = Collections.synchronizedMap(new HashMap()); } + /** + * Creates a new instance. + */ + public DefaultAsteriskManager(ManagerConnection connection) + { + this(); + this.connection = connection; + } + public void setManagerConnection(ManagerConnection connection) { this.connection = connection; @@ -86,10 +96,19 @@ public class DefaultAsteriskManager public void initialize() throws TimeoutException, IOException, AuthenticationFailedException { + initialize(false); + } + + public void initialize(boolean skipQueues) throws TimeoutException, + IOException, AuthenticationFailedException + { connection.login(); initializeChannels(); - initializeQueues(); + if (!skipQueues) + { + initializeQueues(); + } connection.addEventHandler(this); } @@ -251,6 +270,8 @@ public class DefaultAsteriskManager } } + /* Private helper methods */ + protected void addChannel(Channel channel) { channels.put(channel.getId(), channel); @@ -414,15 +435,18 @@ public class DefaultAsteriskManager */ private Channel getChannelByName(String name) { - // TODO must get unique Channel channel = null; - Iterator channelIterator = channels.values().iterator(); - while (channelIterator.hasNext()) + + synchronized (channels) { - Channel tmp = (Channel) channelIterator.next(); - if (tmp.getName() != null && tmp.getName().equals(name)) + Iterator channelIterator = channels.values().iterator(); + while (channelIterator.hasNext()) { - channel = tmp; + Channel tmp = (Channel) channelIterator.next(); + if (tmp.getName() != null && tmp.getName().equals(name)) + { + channel = tmp; + } } } return channel; |
From: Stefan R. <sr...@us...> - 2005-07-26 11:36:23
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1539/src/java/net/sf/asterisk/manager/event Modified Files: DialEvent.java Log Message: Added note to javadoc about default caller id values Index: DialEvent.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/event/DialEvent.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- DialEvent.java 10 Mar 2005 22:19:27 -0000 1.3 +++ DialEvent.java 26 Jul 2005 11:35:58 -0000 1.4 @@ -18,10 +18,12 @@ package net.sf.asterisk.manager.event; /** * A dial event is triggered whenever a phone attempts to dial someone.<br> - * This event is implemented in <code>apps/app_dial.c</code> + * This event is implemented in <code>apps/app_dial.c</code>.<br> + * Available since Asterisk 1.2. * * @author Asteria Solutions Group, Inc. <http://www.asteriasgi.com/> * @version $Id$ + * @since 0.2 */ public class DialEvent extends ManagerEvent { @@ -113,7 +115,7 @@ public class DialEvent extends ManagerEv /** * Returns the Caller*ID. * - * @return the Caller*ID. + * @return the Caller*ID or "<unknown>" if none has been set. */ public String getCallerId() { @@ -133,7 +135,7 @@ public class DialEvent extends ManagerEv /** * Returns the Caller*ID Name. * - * @return the Caller*ID Name. + * @return the Caller*ID Name or "<unknown>" if none has been set. */ public String getCallerIdName() { |
From: Stefan R. <sr...@us...> - 2005-07-26 10:04:10
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14666/src/java/net/sf/asterisk/manager/action Modified Files: OriginateAction.java Log Message: Added note about events being generated only if async == true Index: OriginateAction.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action/OriginateAction.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- OriginateAction.java 16 Jul 2005 23:30:51 -0000 1.7 +++ OriginateAction.java 26 Jul 2005 10:04:00 -0000 1.8 @@ -1,301 +1,302 @@ -/* - * Copyright 2004-2005 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 net.sf.asterisk.manager.action; - -import net.sf.asterisk.manager.event.OriginateEvent; - -/** - * The OriginateAction generates an outgoing call to the extension in the given - * context with the given priority or to a given application with optional - * parameters.<br> - * If you want to connect to an extension use the properties context, exten and - * priority. If you want to connect to an application use the properties - * application and data if needed. Note that no call detail record will be - * written when directly connecting to an application, so it may be better to - * connect to an extension that starts the application you wish to connect to.<br> - * The response to this action is sent when the channel has been answered and - * asterisk starts connecting it to the given extension. So be careful not to - * choose a too short timeout when waiting for the response.<br> - * If the origination succeeds an OriginateSuccessEvent is generated, if it - * fails an OriginateFailureEvent is generated. The action id of these events - * equals the action id of this OriginateAction. - * - * @see net.sf.asterisk.manager.event.OriginateSuccessEvent - * @see net.sf.asterisk.manager.event.OriginateFailureEvent - * @author srt - * @version $Id$ - */ -public class OriginateAction extends AbstractManagerAction - implements - EventGeneratingAction -{ - /** - * Serializable version identifier - */ - static final long serialVersionUID = 8194597741743334704L; - - private String channel; - private String exten; - private String context; - private Integer priority; - private Long timeout; - private String callerId; - private Boolean callingPres; - private String variable; - private String account; - private String application; - private String data; - private Boolean async; - - /** - * Returns the name of this action, i.e. "Originate". - */ - public String getAction() - { - return "Originate"; - } - - /** - * Returns the account code to use for the originated call. - */ - public String getAccount() - { - return account; - } - - /** - * Sets the account code to use for the originated call.<br> - * The account code is included in the call detail record generated for this - * call and will be used for billing. - */ - public void setAccount(String account) - { - this.account = account; - } - - /** - * Returns the caller id to set on the outgoing channel. - */ - public String getCallerId() - { - return callerId; - } - - /** - * Sets the caller id to set on the outgoing channel. - */ - public void setCallerId(String callerId) - { - this.callerId = callerId; - } - - /** - * Returns <code>true</code> if Caller ID presentation is set on the - * outgoing channel. - */ - public Boolean getCallingPres() - { - return callingPres; - } - - /** - * Set to <code>true</code> if you want Caller ID presentation to be set - * on the outgoing channel. - */ - public void setCallingPres(Boolean callingPres) - { - this.callingPres = callingPres; - } - - /** - * Returns the name of the channel to connect to the outgoing call. - */ - public String getChannel() - { - return channel; - } - - /** - * Sets the name of the channel to connect to the outgoing call.<br> - * This property is required. - */ - public void setChannel(String channel) - { - this.channel = channel; - } - - /** - * Returns the name of the context of the extension to connect to. - */ - public String getContext() - { - return context; - } - - /** - * Sets the name of the context of the extension to connect to.<br> - * If you set the context you also have to set the exten and priority - * properties. - */ - public void setContext(String context) - { - this.context = context; - } - - /** - * Returns the extension to connect to. - */ - public String getExten() - { - return exten; - } - - /** - * Sets the extension to connect to.<br> - * If you set the extension you also have to set the context and priority - * properties. - */ - public void setExten(String exten) - { - this.exten = exten; - } - - /** - * Returns the priority of the extension to connect to. - */ - public Integer getPriority() - { - return priority; - } - - /** - * Sets the priority of the extension to connect to. If you set the priority - * you also have to set the context and exten properties. - */ - public void setPriority(Integer priority) - { - this.priority = priority; - } - - /** - * Returns the name of the application to connect to. - */ - public String getApplication() - { - return application; - } - - /** - * Sets the name of the application to connect to. - */ - public void setApplication(String application) - { - this.application = application; - } - - /** - * Returns the parameters to pass to the application. - */ - public String getData() - { - return data; - } - - /** - * Sets the parameters to pass to the application. - */ - public void setData(String data) - { - this.data = data; - } - - /** - * Returns the timeout for the origination. - */ - public Long getTimeout() - { - return timeout; - } - - /** - * Sets the timeout (in milliseconds) for the origination.<br> - * The channel must be answered within this time, otherwise the origination - * is considered to have failed and an OriginateFailureEvent is generated.<br> - * If not set, Asterisk assumes a default value of 30000 meaning 30 seconds. - * - * @param timeout the timeout in milliseconds - * @deprecated use {@see #setTimeout(Long)} instead. - */ - public void setTimeout(Integer timeout) - { - this.timeout = new Long(timeout.longValue()); - } - - /** - * Sets the timeout (in milliseconds) for the origination.<br> - * The channel must be answered within this time, otherwise the origination - * is considered to have failed and an OriginateFailureEvent is generated.<br> - * If not set, Asterisk assumes a default value of 30000 meaning 30 seconds. - * - * @param timeout the timeout in milliseconds - */ - public void setTimeout(Long timeout) - { - this.timeout = timeout; - } - - /** - * Returns the variables to set on the originated call. - */ - public String getVariable() - { - return variable; - } - - /** - * Sets the variables to set on the originated call.<br> - * Variable assignments are of the form "VARNAME=VALUE". You can specify - * multiple variable assignments separated by the '|' character.<br> - * Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and - * VAR2 to "def". - */ - public void setVariable(String variable) - { - this.variable = variable; - } - - /** - * Returns true if this is a fast origination. - */ - public Boolean getAsync() - { - return async; - } - - /** - * Set to true for fast origination. - */ - public void setAsync(Boolean async) - { - this.async = async; - } - - public Class getActionCompleteEventClass() - { - return OriginateEvent.class; - } -} +/* + * Copyright 2004-2005 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 net.sf.asterisk.manager.action; + +import net.sf.asterisk.manager.event.OriginateEvent; + +/** + * The OriginateAction generates an outgoing call to the extension in the given + * context with the given priority or to a given application with optional + * parameters.<br> + * If you want to connect to an extension use the properties context, exten and + * priority. If you want to connect to an application use the properties + * application and data if needed. Note that no call detail record will be + * written when directly connecting to an application, so it may be better to + * connect to an extension that starts the application you wish to connect to.<br> + * The response to this action is sent when the channel has been answered and + * asterisk starts connecting it to the given extension. So be careful not to + * choose a too short timeout when waiting for the response.<br> + * If you set async to <code>true</code> Asterisk reports an OriginateSuccess- + * and OriginateFailureEvents. The action id of these events equals the action + * id of this OriginateAction. + * + * @see net.sf.asterisk.manager.event.OriginateSuccessEvent + * @see net.sf.asterisk.manager.event.OriginateFailureEvent + * @author srt + * @version $Id$ + */ +public class OriginateAction extends AbstractManagerAction + implements + EventGeneratingAction +{ + /** + * Serializable version identifier + */ + static final long serialVersionUID = 8194597741743334704L; + + private String channel; + private String exten; + private String context; + private Integer priority; + private Long timeout; + private String callerId; + private Boolean callingPres; + private String variable; + private String account; + private String application; + private String data; + private Boolean async; + + /** + * Returns the name of this action, i.e. "Originate". + */ + public String getAction() + { + return "Originate"; + } + + /** + * Returns the account code to use for the originated call. + */ + public String getAccount() + { + return account; + } + + /** + * Sets the account code to use for the originated call.<br> + * The account code is included in the call detail record generated for this + * call and will be used for billing. + */ + public void setAccount(String account) + { + this.account = account; + } + + /** + * Returns the caller id to set on the outgoing channel. + */ + public String getCallerId() + { + return callerId; + } + + /** + * Sets the caller id to set on the outgoing channel. + */ + public void setCallerId(String callerId) + { + this.callerId = callerId; + } + + /** + * Returns <code>true</code> if Caller ID presentation is set on the + * outgoing channel. + */ + public Boolean getCallingPres() + { + return callingPres; + } + + /** + * Set to <code>true</code> if you want Caller ID presentation to be set + * on the outgoing channel. + */ + public void setCallingPres(Boolean callingPres) + { + this.callingPres = callingPres; + } + + /** + * Returns the name of the channel to connect to the outgoing call. + */ + public String getChannel() + { + return channel; + } + + /** + * Sets the name of the channel to connect to the outgoing call.<br> + * This property is required. + */ + public void setChannel(String channel) + { + this.channel = channel; + } + + /** + * Returns the name of the context of the extension to connect to. + */ + public String getContext() + { + return context; + } + + /** + * Sets the name of the context of the extension to connect to.<br> + * If you set the context you also have to set the exten and priority + * properties. + */ + public void setContext(String context) + { + this.context = context; + } + + /** + * Returns the extension to connect to. + */ + public String getExten() + { + return exten; + } + + /** + * Sets the extension to connect to.<br> + * If you set the extension you also have to set the context and priority + * properties. + */ + public void setExten(String exten) + { + this.exten = exten; + } + + /** + * Returns the priority of the extension to connect to. + */ + public Integer getPriority() + { + return priority; + } + + /** + * Sets the priority of the extension to connect to. If you set the priority + * you also have to set the context and exten properties. + */ + public void setPriority(Integer priority) + { + this.priority = priority; + } + + /** + * Returns the name of the application to connect to. + */ + public String getApplication() + { + return application; + } + + /** + * Sets the name of the application to connect to. + */ + public void setApplication(String application) + { + this.application = application; + } + + /** + * Returns the parameters to pass to the application. + */ + public String getData() + { + return data; + } + + /** + * Sets the parameters to pass to the application. + */ + public void setData(String data) + { + this.data = data; + } + + /** + * Returns the timeout for the origination. + */ + public Long getTimeout() + { + return timeout; + } + + /** + * Sets the timeout (in milliseconds) for the origination.<br> + * The channel must be answered within this time, otherwise the origination + * is considered to have failed and an OriginateFailureEvent is generated.<br> + * If not set, Asterisk assumes a default value of 30000 meaning 30 seconds. + * + * @param timeout the timeout in milliseconds + * @deprecated use {@see #setTimeout(Long)} instead. + */ + public void setTimeout(Integer timeout) + { + this.timeout = new Long(timeout.longValue()); + } + + /** + * Sets the timeout (in milliseconds) for the origination.<br> + * The channel must be answered within this time, otherwise the origination + * is considered to have failed and an OriginateFailureEvent is generated.<br> + * If not set, Asterisk assumes a default value of 30000 meaning 30 seconds. + * + * @param timeout the timeout in milliseconds + */ + public void setTimeout(Long timeout) + { + this.timeout = timeout; + } + + /** + * Returns the variables to set on the originated call. + */ + public String getVariable() + { + return variable; + } + + /** + * Sets the variables to set on the originated call.<br> + * Variable assignments are of the form "VARNAME=VALUE". You can specify + * multiple variable assignments separated by the '|' character.<br> + * Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and + * VAR2 to "def". + */ + public void setVariable(String variable) + { + this.variable = variable; + } + + /** + * Returns true if this is a fast origination. + */ + public Boolean getAsync() + { + return async; + } + + /** + * Set to true for fast origination. Only with fast origination Asterisk + * will send OriginateSuccess- and OriginateFailureEvents. + */ + public void setAsync(Boolean async) + { + this.async = async; + } + + public Class getActionCompleteEventClass() + { + return OriginateEvent.class; + } +} |
From: Stefan R. <sr...@us...> - 2005-07-26 09:04:16
|
Update of /cvsroot/asterisk-java/asterisk-java/xdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3192/xdocs Modified Files: index.xml Log Message: Added link to Asterisk Desktop Manager in related Projects Added note about Asterisk-Java 0.2 being available with Asterisk release 1.2 Removed note about MAGI (which seems to be dead) Index: index.xml =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/xdocs/index.xml,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -p -r1.19 -r1.20 --- index.xml 23 Jul 2005 08:27:27 -0000 1.19 +++ index.xml 26 Jul 2005 09:03:59 -0000 1.20 @@ -53,14 +53,12 @@ License, Version 2.0</a>.</p> </subsection> <subsection name="Status"> - <p>Asterisk-Java 0.1 has been realeased and is available - from the <a + <p>Asterisk-Java 0.1 has been in late april realeased and is + available from the <a href="http://sourceforge.net/projects/asterisk-java/">sourceforge project page</a>.</p> - <p>The plan for 0.2 includes optional support for David Pollak's - <a href="http://lists.digium.com/pipermail/asterisk-dev/2005-March/010309.html">MAGI</a> - interface (AGI over the Manager API) as soon as it is integrated - into Asterisk's CVS HEAD.</p> + <p>Asterisk-Java 0.2 will be available with the upcoming + Asterisk release 1.2.</p> <p>Ideas for the future include a stateful higher level API that supports operations like "get list of currently active calls" or "place call" with objects like "Call" or @@ -105,6 +103,12 @@ cvs -z3 -d:pserver:ano...@cv...urcef <a href="http://www.easymock.org/">EasyMock</a> in addition.</p> </subsection> <subsection name="Related Projects"> + <p><a href="http://adm.hamnett.org/">Asterisk Desktop Manageer</a>, or + ADM for short, brings the power of Asterisk to the user's desktop. It + is written in Java, uses the Eclipse SWT library and is based on + Asterisk-Java.<br/> + Available under the GNU General Public License (GPL). + </p> <p><a href="http://www3.mb.sympatico.ca/~chadk/">Asterisk-Java for Mono/.NET</a> is a port of Asterisk-Java to C# for Mono, Microsoft's .NET Framework and anything else that implements the basic |
From: Stefan R. <sr...@us...> - 2005-07-24 18:06:22
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10764/src/java/net/sf/asterisk/manager Modified Files: DefaultAsteriskManager.java Log Message: Removed System.out.println() left over from debugging Index: DefaultAsteriskManager.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultAsteriskManager.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -p -r1.8 -r1.9 --- DefaultAsteriskManager.java 17 Jul 2005 07:08:28 -0000 1.8 +++ DefaultAsteriskManager.java 24 Jul 2005 18:06:13 -0000 1.9 @@ -213,8 +213,6 @@ public class DefaultAsteriskManager */ public void handleEvent(ManagerEvent event) { - System.out.println("received: " + event); - if (event instanceof ConnectEvent) { handleConnectEvent((ConnectEvent) event); |
From: Stefan R. <sr...@us...> - 2005-07-24 07:54:02
|
Update of /cvsroot/asterisk-java/asterisk-java In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21673 Modified Files: ChangeLog Log Message: Added note about event generating actions Index: ChangeLog =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/ChangeLog,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- ChangeLog 16 Jul 2005 13:19:34 -0000 1.4 +++ ChangeLog 24 Jul 2005 07:53:52 -0000 1.5 @@ -5,6 +5,10 @@ Asterisk-Java 0.2 * Changed ManagerAction to be an interface rather that an abstract base class. If you extended ManagerAction, please use AbstractManagerAction instead. + * Added support for event generating Actions, i.e. Actions + that send their result as a series of Event rather than + the usual ManagerResults. See the sendEventGeneratingAction() + methods in ManagerConnection for more information. Asterisk-Java 0.1 * Added accessors for raw attributes in ManagerResponse |
From: Stefan R. <sr...@us...> - 2005-07-23 10:13:33
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26389/src/java/net/sf/asterisk/fastagi/impl Modified Files: AGIRequestImpl.java Log Message: fixed synchronize Index: AGIRequestImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl/AGIRequestImpl.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -p -r1.5 -r1.6 --- AGIRequestImpl.java 23 Jul 2005 08:27:27 -0000 1.5 +++ AGIRequestImpl.java 23 Jul 2005 10:13:24 -0000 1.6 @@ -64,24 +64,21 @@ public class AGIRequestImpl implements S private String parameters; private String script; - private boolean callerIdCreated; /** * Creates a new AGIRequestImpl. + * + * @param environment the first lines as received from Asterisk containing + * the environment. */ - public AGIRequestImpl() - { - throw new IllegalArgumentException("Environment must not be null."); - } - - public AGIRequestImpl(final Collection lines) + public AGIRequestImpl(final Collection environment) { - if (lines == null) + if (environment == null) { throw new IllegalArgumentException("Environment must not be null."); } - request = buildMap(lines); + request = buildMap(environment); } /** |
From: Stefan R. <sr...@us...> - 2005-07-23 08:27:35
|
Update of /cvsroot/asterisk-java/asterisk-java/xdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8632/xdocs Modified Files: index.xml Log Message: Changed use of deprecated encode/decode methods Index: index.xml =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/xdocs/index.xml,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -p -r1.18 -r1.19 --- index.xml 10 Jul 2005 17:26:15 -0000 1.18 +++ index.xml 23 Jul 2005 08:27:27 -0000 1.19 @@ -90,8 +90,7 @@ cvs -z3 -d:pserver:ano...@cv...urcef </subsection> <subsection name="Requirements"> <p>At runtime Asterisk-Java requires a Java Runtime - Environment (JRE) of at least version 1.4 (1.3 might work - when using log4j, though that has not been verified). It has + Environment (JRE) of at least version 1.4. It has been successfully tested on Sun's JVM and Bea's JRockit.</p> <p>Of course you also need a working Asterisk server. When using the Manager API be sure that it has been enabled (see |
From: Stefan R. <sr...@us...> - 2005-07-23 08:27:35
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8632/src/java/net/sf/asterisk/fastagi/impl Modified Files: AGIRequestImpl.java Log Message: Changed use of deprecated encode/decode methods Index: AGIRequestImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl/AGIRequestImpl.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- AGIRequestImpl.java 15 Apr 2005 04:47:00 -0000 1.4 +++ AGIRequestImpl.java 23 Jul 2005 08:27:27 -0000 1.5 @@ -17,6 +17,7 @@ package net.sf.asterisk.fastagi.impl; import java.io.Serializable; +import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Collection; @@ -29,6 +30,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import net.sf.asterisk.fastagi.AGIRequest; +import net.sf.asterisk.util.Log; +import net.sf.asterisk.util.LogFactory; /** * Default implementation of the AGIRequest interface. @@ -38,6 +41,7 @@ import net.sf.asterisk.fastagi.AGIReques */ public class AGIRequestImpl implements Serializable, AGIRequest { + private final Log logger = LogFactory.getLog(getClass()); private static final Pattern SCRIPT_PATTERN = Pattern .compile("^([^\\?]*)\\?(.*)$"); private static final Pattern PARAMETER_PATTERN = Pattern @@ -58,6 +62,11 @@ public class AGIRequestImpl implements S */ private Map parameterMap; + private String parameters; + private String script; + + private boolean callerIdCreated; + /** * Creates a new AGIRequestImpl. */ @@ -142,10 +151,13 @@ public class AGIRequestImpl implements S * * @return the name of the script to execute. */ - public String getScript() + public synchronized String getScript() { if (script != null) + { return script; + } + script = (String) request.get("network_script"); if (script != null) { @@ -156,6 +168,7 @@ public class AGIRequestImpl implements S parameters = scriptMatcher.group(2); } } + return script; } @@ -211,8 +224,6 @@ public class AGIRequestImpl implements S return (String) request.get("language"); } - private boolean callerIdCreated; - public String getCallerId() { int lbPosition; @@ -223,7 +234,7 @@ public class AGIRequestImpl implements S rawCallerId = (String) request.get("callerid"); callerIdCreated = true; } - + if (rawCallerId == null) { return null; @@ -250,7 +261,7 @@ public class AGIRequestImpl implements S rawCallerId = (String) request.get("callerid"); callerIdCreated = true; } - + if (rawCallerId == null) { return null; @@ -386,7 +397,7 @@ public class AGIRequestImpl implements S return (String[]) parameterMap.get(name); } - public Map getParameterMap() + public synchronized Map getParameterMap() { if (parameterMap == null) { @@ -395,10 +406,13 @@ public class AGIRequestImpl implements S return parameterMap; } - private String parameters; - private String script; - - private Map parseParameters(String s) + /** + * Parses the given parameter string and caches the result. + * + * @param s the parameter string to parse + * @return a Map made up of parameter names their values + */ + private synchronized Map parseParameters(String s) { Map parameterMap; Map result; @@ -424,13 +438,33 @@ public class AGIRequestImpl implements S parameterMatcher = PARAMETER_PATTERN.matcher(parameter); if (parameterMatcher.matches()) { - name = URLDecoder.decode(parameterMatcher.group(1)); - value = URLDecoder.decode(parameterMatcher.group(2)); + try + { + name = URLDecoder + .decode(parameterMatcher.group(1), "UTF-8"); + value = URLDecoder.decode(parameterMatcher.group(2), + "UTF-8"); + } + catch (UnsupportedEncodingException e) + { + logger.error("Unable to decode parameter '" + parameter + + "'", e); + continue; + } } else { - name = URLDecoder.decode(parameter); - value = ""; + try + { + name = URLDecoder.decode(parameter, "UTF-8"); + value = ""; + } + catch (UnsupportedEncodingException e) + { + logger.error("Unable to decode parameter '" + parameter + + "'", e); + continue; + } } if (parameterMap.get(name) == null) |
From: Stefan R. <sr...@us...> - 2005-07-21 16:49:43
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32575/src/java/net/sf/asterisk/manager/action Modified Files: AgentCallbackLoginAction.java Log Message: Fixed getAction to return correct action string Index: AgentCallbackLoginAction.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action/AgentCallbackLoginAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AgentCallbackLoginAction.java 21 Jul 2005 13:18:29 -0000 1.1 +++ AgentCallbackLoginAction.java 21 Jul 2005 16:49:35 -0000 1.2 @@ -46,7 +46,7 @@ public class AgentCallbackLoginAction ex */ public String getAction() { - return "AgentLogoff"; + return "AgentCallbackLogin"; } /** |
From: Stefan R. <sr...@us...> - 2005-07-21 13:20:38
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14455/src/java/net/sf/asterisk/manager/action Added Files: AgentCallbackLoginAction.java AgentLogoffAction.java Log Message: Added actions for AgentCallbackLogin and ActionLogoff. Note: the patches for Asterisk CVS-HEAD to support this are still pending. --- NEW FILE: AgentCallbackLoginAction.java --- /* * Copyright 2004-2005 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 net.sf.asterisk.manager.action; /** * The AgentCallbackLoginAction aets an agent as logged in with callback.<br> * You can pass an extentsion (and optionally a context) to specify the destination of the callback.<br> * In contrast to the AgentCallbackLogin application that you can use within Asterisk's dialplan, * you don't need to know the agent's password when logging in an agent.<br> * Available since Asterisk 1.2 * * @author srt * @version $Id: AgentCallbackLoginAction.java,v 1.1 2005/07/21 13:18:29 srt Exp $ * @since 0.2 */ public class AgentCallbackLoginAction extends AbstractManagerAction { /** * Serializable version identifier */ private static final long serialVersionUID = 5239805071977668779L; private String agent; private String exten; private String context; private Boolean ackCall; private Long wrapupTime; /** * Returns the name of this action, i.e. "AgentCallbackLogin". * * @return the name of this action */ public String getAction() { return "AgentLogoff"; } /** * Returns the name of the agent to log in, for example "1002". * * @return the name of the agent to log in */ public String getAgent() { return agent; } /** * Sets the name of the agent to log in, for example "1002".<br> * This is property is mandatory. * * @param agent the name of the agent to log in */ public void setAgent(String agent) { this.agent = agent; } /** * Returns the extension to use for callback. * * @return the extension to use for callback. */ public String getExten() { return exten; } /** * Sets the extension to use for callback.<br> * This is property is mandatory. * * @param exten the extension to use for callback. */ public void setExten(String exten) { this.exten = exten; } /** * Returns the context of the extension to use for callback. * * @return the context of the extension to use for callback. */ public String getContext() { return context; } /** * Sets the context of the extension to use for callback. * * @param context the context of the extension to use for callback. */ public void setContext(String context) { this.context = context; } /** * Returns if an acknowledgement is needed when agent is called back. * * @return Boolean.TRUE to 'true' to require an acknowledgement by '#' when agent is called * back, Boolean.FALSE otherwise. */ public Boolean getAckCall() { return ackCall; } /** * Sets if an acknowledgement is needed when agent is called back.<br> * This property is optional, it allows you to override the defaults defined in Asterisk's * configuration. * * @param ackCall Boolean.TRUE to 'true' to require an acknowledgement by '#' when agent is * called back, Boolean.FALSE otherwise. */ public void setAckCall(Boolean ackCall) { this.ackCall = ackCall; } /** * Returns the minimum amount of time after disconnecting before the caller can receive a new * call. * * @return the minimum amount of time after disconnecting before the caller can receive a new * call in milliseconds. */ public Long getWrapupTime() { return wrapupTime; } /** * Sets the minimum amount of time after disconnecting before the caller can receive a new call.<br> * This property is optional, it allows you to override the defaults defined in Asterisk's * configuration. * * @param wrapupTime the minimum amount of time after disconnecting before the caller can * receive a new call in milliseconds. */ public void setWrapupTime(Long wrapupTime) { this.wrapupTime = wrapupTime; } } --- NEW FILE: AgentLogoffAction.java --- /* * Copyright 2004-2005 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 net.sf.asterisk.manager.action; /** * The AgentLogoffAction sets an agent as no longer logged in.<br> * Available since Asterisk 1.2 * * @author srt * @version $Id: AgentLogoffAction.java,v 1.1 2005/07/21 13:18:29 srt Exp $ * @since 0.2 */ public class AgentLogoffAction extends AbstractManagerAction { /** * Serializable version identifier */ private static final long serialVersionUID = 5239805071977668779L; private String agent; /** * Returns the name of this action, i.e. "AgentLogoff". * * @return the name of this action */ public String getAction() { return "AgentLogoff"; } /** * Returns the name of the agent to log off, for example "1002". * * @return the name of the agent to log off */ public String getAgent() { return agent; } /** * Sets the name of the agent to log off, for example "1002".<br> * This is property is mandatory. * * @param agent the name of the agent to log off */ public void setAgent(String agent) { this.agent = agent; } } |
From: Stefan R. <sr...@us...> - 2005-07-18 14:53:46
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19002/src/java/net/sf/asterisk/manager/impl Modified Files: EventBuilderImpl.java Log Message: Added SIPPeersAction and SIPShowPeerAction and corresponding events PeerEntryEvent and PeerlistCompleteEvent Index: EventBuilderImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/impl/EventBuilderImpl.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- EventBuilderImpl.java 16 Jul 2005 13:39:54 -0000 1.7 +++ EventBuilderImpl.java 18 Jul 2005 14:53:08 -0000 1.8 @@ -55,7 +55,9 @@ import net.sf.asterisk.manager.event.Ori import net.sf.asterisk.manager.event.OriginateSuccessEvent; import net.sf.asterisk.manager.event.ParkedCallEvent; import net.sf.asterisk.manager.event.ParkedCallsCompleteEvent; +import net.sf.asterisk.manager.event.PeerEntryEvent; import net.sf.asterisk.manager.event.PeerStatusEvent; +import net.sf.asterisk.manager.event.PeerlistCompleteEvent; import net.sf.asterisk.manager.event.QueueEntryEvent; import net.sf.asterisk.manager.event.QueueMemberEvent; import net.sf.asterisk.manager.event.QueueMemberStatusEvent; @@ -125,6 +127,8 @@ public class EventBuilderImpl implements registerEventClass(OriginateSuccessEvent.class); registerEventClass(ParkedCallEvent.class); registerEventClass(ParkedCallsCompleteEvent.class); + registerEventClass(PeerEntryEvent.class); + registerEventClass(PeerlistCompleteEvent.class); registerEventClass(PeerStatusEvent.class); registerEventClass(QueueEntryEvent.class); registerEventClass(QueueMemberEvent.class); @@ -306,8 +310,22 @@ public class EventBuilderImpl implements } dataType = setter.getParameterTypes()[0]; - - if (dataType.isAssignableFrom(String.class)) + + if (dataType == Boolean.class) + { + String tmp; + + tmp = (String) attributes.get(name); + if (tmp != null && ("yes".equalsIgnoreCase(tmp) || "true".equalsIgnoreCase(tmp))) + { + value = Boolean.TRUE; + } + else + { + value = Boolean.FALSE; + } + } + else if (dataType.isAssignableFrom(String.class)) { value = attributes.get(name); } |
From: Stefan R. <sr...@us...> - 2005-07-18 14:53:34
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19002/src/test/net/sf/asterisk/manager/impl Modified Files: EventBuilderImplTest.java Log Message: Added SIPPeersAction and SIPShowPeerAction and corresponding events PeerEntryEvent and PeerlistCompleteEvent Index: EventBuilderImplTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/impl/EventBuilderImplTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- EventBuilderImplTest.java 21 Apr 2005 23:34:41 -0000 1.3 +++ EventBuilderImplTest.java 18 Jul 2005 14:53:25 -0000 1.4 @@ -183,6 +183,40 @@ public class EventBuilderImplTest extend .getRestart()); } + public void testBuildEventWithBooleanPropertyOfValueYes() + { + Map properties = new HashMap(); + ShutdownEvent event; + + eventBuilder.registerEventClass(ShutdownEvent.class); + properties.put("event", "shutdown"); + properties.put("restart", "yes"); + event = (ShutdownEvent) eventBuilder.buildEvent(this, properties); + + assertNotNull(event); + assertEquals("Returned event is of wrong type", ShutdownEvent.class, + event.getClass()); + assertEquals("Boolean property not set correctly", Boolean.TRUE, event + .getRestart()); + } + + public void testBuildEventWithBooleanPropertyOfValueNo() + { + Map properties = new HashMap(); + ShutdownEvent event; + + eventBuilder.registerEventClass(ShutdownEvent.class); + properties.put("event", "shutdown"); + properties.put("restart", "NO"); + event = (ShutdownEvent) eventBuilder.buildEvent(this, properties); + + assertNotNull(event); + assertEquals("Returned event is of wrong type", ShutdownEvent.class, + event.getClass()); + assertEquals("Boolean property not set correctly", Boolean.FALSE, event + .getRestart()); + } + public void testBuildEventWithUnregisteredEvent() { Map properties = new HashMap(); |
From: Stefan R. <sr...@us...> - 2005-07-18 14:53:34
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19002/src/java/net/sf/asterisk/manager/action Modified Files: DBGetAction.java Added Files: SIPPeersAction.java SIPShowPeerAction.java Log Message: Added SIPPeersAction and SIPShowPeerAction and corresponding events PeerEntryEvent and PeerlistCompleteEvent --- NEW FILE: SIPPeersAction.java --- /* * Copyright 2004-2005 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 net.sf.asterisk.manager.action; import net.sf.asterisk.manager.event.PeerlistCompleteEvent; /** * Retrieves a list of all defined SIP peers.<br> * For each peer that is found a PeerEntryEvent is sent by Asterisk containing * the details. When all peers have been reported a PeerlistCompleteEvent is sent.<br> * Available since Asterisk 1.2 * * @see net.sf.asterisk.manager.event.PeerEntryEvent * @see net.sf.asterisk.manager.event.PeerlistCompleteEvent * @author srt * @version $Id: SIPPeersAction.java,v 1.1 2005/07/18 14:53:24 srt Exp $ * @since 0.2 */ public class SIPPeersAction extends AbstractManagerAction implements EventGeneratingAction { /** * Serial version identifier */ private static final long serialVersionUID = 921037572305993779L; public String getAction() { return "SIPPeers"; } public Class getActionCompleteEventClass() { return PeerlistCompleteEvent.class; } } --- NEW FILE: SIPShowPeerAction.java --- /* * Copyright 2004-2005 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 net.sf.asterisk.manager.action; import net.sf.asterisk.manager.event.PeerlistCompleteEvent; /** * Retrieves a the details about a given SIP peer.<br> * For a PeerEntryEvent is sent by Asterisk containing the details of the peer followed by a * PeerlistCompleteEvent.<br> * Available since Asterisk 1.2 * * @see net.sf.asterisk.manager.event.PeerEntryEvent * @see net.sf.asterisk.manager.event.PeerlistCompleteEvent * @author srt * @version $Id: SIPShowPeerAction.java,v 1.1 2005/07/18 14:53:25 srt Exp $ * @since 0.2 */ public class SIPShowPeerAction extends AbstractManagerAction implements EventGeneratingAction { /** * Serial version identifier */ private static final long serialVersionUID = 921037572305993779L; private String peer; public String getAction() { return "SIPPeer"; } /** * Returns the name of the peer to retrieve.<br> * This parameter is mandatory. * * @return the name of the peer to retrieve. */ public String getPeer() { return peer; } /** * Sets the name of the peer to retrieve.<br> * This parameter is mandatory. * * @param peer the name of the peer to retrieve. */ public void setPeer(String peer) { this.peer = peer; } public Class getActionCompleteEventClass() { return PeerlistCompleteEvent.class; } } Index: DBGetAction.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action/DBGetAction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- DBGetAction.java 16 Jul 2005 14:25:48 -0000 1.2 +++ DBGetAction.java 18 Jul 2005 14:53:08 -0000 1.3 @@ -24,6 +24,7 @@ import net.sf.asterisk.manager.event.DBG * the value, otherwise a ManagerError indicates that no entry matches.<br> * Available since Asterisk 1.2 * + * @see net.sf.asterisk.manager.event.DBGetResponseEvent * @author srt * @version $Id$ * @since 0.2 |
From: Stefan R. <sr...@us...> - 2005-07-18 14:53:19
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19002/src/java/net/sf/asterisk/manager/event Added Files: PeerEntryEvent.java PeerlistCompleteEvent.java Log Message: Added SIPPeersAction and SIPShowPeerAction and corresponding events PeerEntryEvent and PeerlistCompleteEvent --- NEW FILE: PeerEntryEvent.java --- /* * Copyright 2004-2005 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 net.sf.asterisk.manager.event; /** * A PeerEntryEvent is triggered in response to a SIPPeersAction or SIPShowPeerAction and contains * information about a peer.<br> * It is implemented in <code>channels/chan_sip.c</code> * * @author srt * @version $Id: PeerEntryEvent.java,v 1.1 2005/07/18 14:53:08 srt Exp $ * @since 0.2 */ public class PeerEntryEvent extends ResponseEvent { /** * Serial version identifier */ private static final long serialVersionUID = 1443711349135777437L; private String channelType; private String objectName; private String chanObjectType; private String ipAddress; private int ipPort; private Boolean dynamic; private Boolean natSupport; private Boolean acl; private String status; /** * Creates a new instance. * * @param source */ public PeerEntryEvent(Object source) { super(source); } /** * For SIP peers this is "SIP". * * @return */ public String getChannelType() { return channelType; } public void setChannelType(String channelType) { this.channelType = channelType; } public String getObjectName() { return objectName; } public void setObjectName(String objectName) { this.objectName = objectName; } /** * For SIP peers this is either "peer" or "user". * * @return */ public String getChanObjectType() { return chanObjectType; } public void setChanObjectType(String chanObjectType) { this.chanObjectType = chanObjectType; } /** * Returns the IP address of the peer. * * @return the IP address of the peer or "-none-" if none is available. */ public String getIpAddress() { return ipAddress; } /** * Sets the IP address of the peer. * * @param ipAddress the IP address of the peer. */ public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; } public int getIpPort() { return ipPort; } public void setIpPort(int ipPort) { this.ipPort = ipPort; } public Boolean getDynamic() { return dynamic; } public void setDynamic(Boolean dynamic) { this.dynamic = dynamic; } public Boolean getNatSupport() { return natSupport; } public void setNatSupport(Boolean natSupport) { this.natSupport = natSupport; } public Boolean getAcl() { return acl; } public void setAcl(Boolean acl) { this.acl = acl; } /** * Returns the status of this peer.<br> * For SIP peers this is one of: * <dl> * <dt>"UNREACHABLE"</dt> * <dd></dd> * <dt>"LAGGED (%d ms)"</dt> * <dd></dd> * <dt>"OK (%d ms)"</dt> * <dd></dd> * <dt>"UNKNOWN"</dt> * <dd></dd> * <dt>"Unmonitored"</dt> * <dd></dd> * </dl> * * @return the status of this peer. */ public String getStatus() { return status; } /** * Sets the status of this peer. * * @param status the status of this peer. */ public void setStatus(String status) { this.status = status; } } --- NEW FILE: PeerlistCompleteEvent.java --- /* * Copyright 2004-2005 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 net.sf.asterisk.manager.event; /** * A PeerlistCompleteEvent is triggered after the details of all peers has been reported in response * to an SIPPeersAction or SIPShowPeerAction.<br> * Available since Asterisk 1.2 * * @see net.sf.asterisk.manager.event.PeerEntryEvent * @see net.sf.asterisk.manager.action.SIPPeersAction * @see net.sf.asterisk.manager.action.SIPShowPeerAction * @author srt * @version $Id: PeerlistCompleteEvent.java,v 1.1 2005/07/18 14:53:08 srt Exp $ * @since 0.2 */ public class PeerlistCompleteEvent extends ResponseEvent { /** * Serial version identifier */ private static final long serialVersionUID = -1177773673509373296L; private Integer listItems; /** * Creates a new instance. * * @param source */ public PeerlistCompleteEvent(Object source) { super(source); } /** * Returns the number of PeerEvents that have been reported. * * @return the number of PeerEvents that have been reported. */ public Integer getListItems() { return listItems; } /** * Sets the number of PeerEvents that have been reported. * * @param listItems the number of PeerEvents that have been reported. */ public void setListItems(Integer listItems) { this.listItems = listItems; } } |
From: Stefan R. <sr...@us...> - 2005-07-18 12:11:31
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/response In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17340/src/java/net/sf/asterisk/manager/response Modified Files: ExtensionStateResponse.java Log Message: added toString() Index: ExtensionStateResponse.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/response/ExtensionStateResponse.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- ExtensionStateResponse.java 23 Feb 2005 22:50:58 -0000 1.2 +++ ExtensionStateResponse.java 18 Jul 2005 12:11:05 -0000 1.3 @@ -70,4 +70,22 @@ public class ExtensionStateResponse exte { this.status = status; } + + public String toString() + { + StringBuffer sb; + + sb = new StringBuffer(getClass().getName() + ": "); + sb.append("actionId='" + getActionId() + "'; "); + sb.append("message='" + getMessage() + "'; "); + sb.append("response='" + getResponse() + "'; "); + sb.append("uniqueId='" + getUniqueId() + "'; "); + sb.append("exten='" + getExten() + "'; "); + sb.append("context='" + getContext() + "'; "); + sb.append("hint='" + getHint() + "'; "); + sb.append("status='" + getStatus() + "'; "); + sb.append("systemHashcode=" + System.identityHashCode(this)); + + return sb.toString(); + } } |
From: Stefan R. <sr...@us...> - 2005-07-17 07:08:40
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5100/src/java/net/sf/asterisk/manager Modified Files: DefaultAsteriskManager.java Log Message: Index: DefaultAsteriskManager.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultAsteriskManager.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- DefaultAsteriskManager.java 16 Jul 2005 23:26:58 -0000 1.7 +++ DefaultAsteriskManager.java 17 Jul 2005 07:08:28 -0000 1.8 @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.Map; import net.sf.asterisk.manager.action.OriginateAction; +import net.sf.asterisk.manager.action.QueueStatusAction; import net.sf.asterisk.manager.action.StatusAction; import net.sf.asterisk.manager.event.ConnectEvent; import net.sf.asterisk.manager.event.DisconnectEvent; @@ -119,7 +120,7 @@ public class DefaultAsteriskManager try { - re = connection.sendEventGeneratingAction(new StatusAction()); + re = connection.sendEventGeneratingAction(new QueueStatusAction()); } catch (EventTimeoutException e) { |
From: Stefan R. <sr...@us...> - 2005-07-17 00:10:44
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4484/src/java/net/sf/asterisk/manager Modified Files: DefaultManagerConnection.java Log Message: Don't wait for events being sent when receiving a ManagerError in response to an EventGeneratingAction. Index: DefaultManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultManagerConnection.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -p -r1.22 -r1.23 --- DefaultManagerConnection.java 16 Jul 2005 22:04:54 -0000 1.22 +++ DefaultManagerConnection.java 17 Jul 2005 00:10:30 -0000 1.23 @@ -1187,6 +1187,10 @@ public class DefaultManagerConnection im synchronized (events) { events.setRepsonse(response); + if (response instanceof ManagerError) + { + events.setComplete(true); + } // finished? if (events.isComplete()) |
From: Stefan R. <sr...@us...> - 2005-07-16 23:31:00
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29727/src/java/net/sf/asterisk/manager/action Modified Files: OriginateAction.java Log Message: Fixed scrambled file Index: OriginateAction.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action/OriginateAction.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- OriginateAction.java 16 Jul 2005 23:30:13 -0000 1.6 +++ OriginateAction.java 16 Jul 2005 23:30:51 -0000 1.7 @@ -240,7 +240,7 @@ public class OriginateAction extends Abs * @param timeout the timeout in milliseconds * @deprecated use {@see #setTimeout(Long)} instead. */ - public c + public void setTimeout(Integer timeout) { this.timeout = new Long(timeout.longValue()); } |
From: Stefan R. <sr...@us...> - 2005-07-16 23:30:22
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29601/src/java/net/sf/asterisk/manager/action Modified Files: OriginateAction.java Log Message: added deprecated setTimeout(Integer) method for backward compatibility Index: OriginateAction.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action/OriginateAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -p -r1.5 -r1.6 --- OriginateAction.java 16 Jul 2005 23:27:46 -0000 1.5 +++ OriginateAction.java 16 Jul 2005 23:30:13 -0000 1.6 @@ -236,6 +236,22 @@ public class OriginateAction extends Abs * The channel must be answered within this time, otherwise the origination * is considered to have failed and an OriginateFailureEvent is generated.<br> * If not set, Asterisk assumes a default value of 30000 meaning 30 seconds. + * + * @param timeout the timeout in milliseconds + * @deprecated use {@see #setTimeout(Long)} instead. + */ + public c + { + this.timeout = new Long(timeout.longValue()); + } + + /** + * Sets the timeout (in milliseconds) for the origination.<br> + * The channel must be answered within this time, otherwise the origination + * is considered to have failed and an OriginateFailureEvent is generated.<br> + * If not set, Asterisk assumes a default value of 30000 meaning 30 seconds. + * + * @param timeout the timeout in milliseconds */ public void setTimeout(Long timeout) { |
From: Stefan R. <sr...@us...> - 2005-07-16 23:28:25
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29252/src/java/net/sf/asterisk/manager/action Modified Files: OriginateAction.java Log Message: Changed type of timeout attribute to Long Index: OriginateAction.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/action/OriginateAction.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- OriginateAction.java 16 Jul 2005 14:25:48 -0000 1.4 +++ OriginateAction.java 16 Jul 2005 23:27:46 -0000 1.5 @@ -19,40 +19,40 @@ package net.sf.asterisk.manager.action; import net.sf.asterisk.manager.event.OriginateEvent; /** - * The OriginateAction generates an outgoing call to the extension in the given context with the - * given priority or to a given application with optional parameters.<br> - * - * If you want to connect to an extension use the properties context, exten and priority. If you - * want to connect to an application use the properties application and data if needed. Note that no - * call detail record will be written when directly connecting to an application, so it may be - * better to connect to an extension that starts the application you wish to connect to.<br> - * - * The response to this action is sent when the channel has been answered and asterisk starts - * connecting it to the given extension. So be careful not to choose a too short timeout when - * waiting for the response.<br> - * - * If the origination succeeds an OriginateSuccessEvent is generated, if it fails an - * OriginateFailureEvent is generated. The action id of these events equals the action id of this - * OriginateAction. + * The OriginateAction generates an outgoing call to the extension in the given + * context with the given priority or to a given application with optional + * parameters.<br> + * If you want to connect to an extension use the properties context, exten and + * priority. If you want to connect to an application use the properties + * application and data if needed. Note that no call detail record will be + * written when directly connecting to an application, so it may be better to + * connect to an extension that starts the application you wish to connect to.<br> + * The response to this action is sent when the channel has been answered and + * asterisk starts connecting it to the given extension. So be careful not to + * choose a too short timeout when waiting for the response.<br> + * If the origination succeeds an OriginateSuccessEvent is generated, if it + * fails an OriginateFailureEvent is generated. The action id of these events + * equals the action id of this OriginateAction. * * @see net.sf.asterisk.manager.event.OriginateSuccessEvent * @see net.sf.asterisk.manager.event.OriginateFailureEvent - * * @author srt * @version $Id$ */ -public class OriginateAction extends AbstractManagerAction implements EventGeneratingAction +public class OriginateAction extends AbstractManagerAction + implements + EventGeneratingAction { /** * Serializable version identifier */ - static final long serialVersionUID = 8194597741743334704L; + static final long serialVersionUID = 8194597741743334704L; private String channel; private String exten; private String context; private Integer priority; - private Integer timeout; + private Long timeout; private String callerId; private Boolean callingPres; private String variable; @@ -79,8 +79,8 @@ public class OriginateAction extends Abs /** * Sets the account code to use for the originated call.<br> - * The account code is included in the call detail record generated for this call and will be - * used for billing. + * The account code is included in the call detail record generated for this + * call and will be used for billing. */ public void setAccount(String account) { @@ -104,7 +104,8 @@ public class OriginateAction extends Abs } /** - * Returns <code>true</code> if Caller ID presentation is set on the outgoing channel. + * Returns <code>true</code> if Caller ID presentation is set on the + * outgoing channel. */ public Boolean getCallingPres() { @@ -112,8 +113,8 @@ public class OriginateAction extends Abs } /** - * Set to <code>true</code> if you want Caller ID presentation to be set on the outgoing - * channel. + * Set to <code>true</code> if you want Caller ID presentation to be set + * on the outgoing channel. */ public void setCallingPres(Boolean callingPres) { @@ -147,7 +148,8 @@ public class OriginateAction extends Abs /** * Sets the name of the context of the extension to connect to.<br> - * If you set the context you also have to set the exten and priority properties. + * If you set the context you also have to set the exten and priority + * properties. */ public void setContext(String context) { @@ -164,7 +166,8 @@ public class OriginateAction extends Abs /** * Sets the extension to connect to.<br> - * If you set the extension you also have to set the context and priority properties. + * If you set the extension you also have to set the context and priority + * properties. */ public void setExten(String exten) { @@ -180,8 +183,8 @@ public class OriginateAction extends Abs } /** - * Sets the priority of the extension to connect to. If you set the priority you also have to - * set the context and exten properties. + * Sets the priority of the extension to connect to. If you set the priority + * you also have to set the context and exten properties. */ public void setPriority(Integer priority) { @@ -223,18 +226,18 @@ public class OriginateAction extends Abs /** * Returns the timeout for the origination. */ - public Integer getTimeout() + public Long getTimeout() { return timeout; } /** * Sets the timeout (in milliseconds) for the origination.<br> - * The channel must be answered within this time, otherwise the origination is considered to - * have failed and an OriginateFailureEvent is generated.<br> - * If not set, asterisk assumes a default value of 30000 meaning 30 seconds. + * The channel must be answered within this time, otherwise the origination + * is considered to have failed and an OriginateFailureEvent is generated.<br> + * If not set, Asterisk assumes a default value of 30000 meaning 30 seconds. */ - public void setTimeout(Integer timeout) + public void setTimeout(Long timeout) { this.timeout = timeout; } @@ -249,9 +252,10 @@ public class OriginateAction extends Abs /** * Sets the variables to set on the originated call.<br> - * Variable assignments are of the form "VARNAME=VALUE". You can specify multiple variable - * assignments separated by the '|' character.<br> - * Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and VAR2 to "def". + * Variable assignments are of the form "VARNAME=VALUE". You can specify + * multiple variable assignments separated by the '|' character.<br> + * Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and + * VAR2 to "def". */ public void setVariable(String variable) { |
From: Stefan R. <sr...@us...> - 2005-07-16 23:27:23
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29072/src/java/net/sf/asterisk/manager Modified Files: DefaultAsteriskManager.java AsteriskManager.java Originate.java Log Message: Adopted DefaultAsteriskManager to use the new EventGeneratingAction features of ManagerConnection Index: DefaultAsteriskManager.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultAsteriskManager.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- DefaultAsteriskManager.java 7 Jul 2005 00:27:29 -0000 1.6 +++ DefaultAsteriskManager.java 16 Jul 2005 23:26:58 -0000 1.7 @@ -17,16 +17,13 @@ package net.sf.asterisk.manager; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; import net.sf.asterisk.manager.action.OriginateAction; -import net.sf.asterisk.manager.action.QueueStatusAction; import net.sf.asterisk.manager.action.StatusAction; import net.sf.asterisk.manager.event.ConnectEvent; import net.sf.asterisk.manager.event.DisconnectEvent; @@ -36,17 +33,14 @@ import net.sf.asterisk.manager.event.Man import net.sf.asterisk.manager.event.NewChannelEvent; import net.sf.asterisk.manager.event.NewExtenEvent; import net.sf.asterisk.manager.event.NewStateEvent; +import net.sf.asterisk.manager.event.OriginateEvent; import net.sf.asterisk.manager.event.OriginateFailureEvent; -import net.sf.asterisk.manager.event.OriginateSuccessEvent; import net.sf.asterisk.manager.event.QueueEntryEvent; import net.sf.asterisk.manager.event.QueueMemberEvent; import net.sf.asterisk.manager.event.QueueParamsEvent; import net.sf.asterisk.manager.event.RenameEvent; -import net.sf.asterisk.manager.event.StatusCompleteEvent; import net.sf.asterisk.manager.event.StatusEvent; import net.sf.asterisk.manager.event.UnlinkEvent; -import net.sf.asterisk.manager.response.ManagerResponse; - import net.sf.asterisk.util.Log; import net.sf.asterisk.util.LogFactory; @@ -62,42 +56,25 @@ public class DefaultAsteriskManager AsteriskManager, ManagerEventHandler { - private final Log log = LogFactory.getLog(this.getClass()); + private final Log logger = LogFactory.getLog(this.getClass()); private ManagerConnection connection; /** * A map of all active channel by their unique id. */ - private Map channels; - - /** - * A map of all of the originating calls by their actionid. - */ - private Map calls; + private final Map channels; /** * Sequence to track calls. */ private int callSequence; - private Map queues; - private List queuedEvents; - private boolean channelsInitialized; - private boolean queuesInitialized; - private boolean initialized; - private boolean loggedIn; + private final Map queues; public DefaultAsteriskManager() { - this.calls = Collections.synchronizedMap(new HashMap()); this.channels = Collections.synchronizedMap(new HashMap()); this.queues = Collections.synchronizedMap(new HashMap()); - this.queuedEvents = Collections.synchronizedList(new ArrayList()); - this.channelsInitialized = false; - // TODO fix detection of queuesInitialized - this.queuesInitialized = true; - this.initialized = false; - this.loggedIn = false; } public void setManagerConnection(ManagerConnection connection) @@ -108,28 +85,89 @@ public class DefaultAsteriskManager public void initialize() throws TimeoutException, IOException, AuthenticationFailedException { - connection.addEventHandler(this); connection.login(); - loggedIn = true; - connection.sendAction(new StatusAction()); - connection.sendAction(new QueueStatusAction()); + initializeChannels(); + initializeQueues(); + + connection.addEventHandler(this); + } + + private void initializeChannels() throws EventTimeoutException, IOException + { + ResponseEvents re; + Iterator i; + + re = connection.sendEventGeneratingAction(new StatusAction()); + i = re.getEvents().iterator(); + while (i.hasNext()) + { + ManagerEvent event; + + event = (ManagerEvent) i.next(); + if (event instanceof StatusEvent) + { + handleStatusEvent((StatusEvent) event); + } + } + } + + private void initializeQueues() throws IOException + { + ResponseEvents re; + Iterator i; + + try + { + re = connection.sendEventGeneratingAction(new StatusAction()); + } + catch (EventTimeoutException e) + { + // this happens with Asterisk 1.0.x as it doesn't send a + // QueueStatusCompleteEvent + re = e.getPartialResult(); + } + + i = re.getEvents().iterator(); + while (i.hasNext()) + { + ManagerEvent event; + + event = (ManagerEvent) i.next(); + if (event instanceof QueueParamsEvent) + { + handleQueueParamsEvent((QueueParamsEvent) event); + } + else if (event instanceof QueueMemberEvent) + { + handleQueueMemberEvent((QueueMemberEvent) event); + } + else if (event instanceof QueueEntryEvent) + { + handleQueueEntryEvent((QueueEntryEvent) event); + } + } } /* Implementation of the AsteriskManager interface */ public Call originateCall(Originate originate) throws TimeoutException, - IOException, Exception + IOException { - Call call; OriginateAction originateAction; - String actionid; + ResponseEvents responseEvents; + Long timeout; - call = new Call(); - originateAction = new OriginateAction(); - actionid = System.identityHashCode(this) + "#" + (++callSequence); + if (originate.getTimeout() == null) + { + timeout = new Long(30000); + } + else + { + timeout = originate.getTimeout(); + } - // set the action properties + originateAction = new OriginateAction(); originateAction.setAccount(originate.getAccount()); originateAction.setApplication(originate.getApplication()); originateAction.setCallerId(originate.getCallerId()); @@ -138,34 +176,18 @@ public class DefaultAsteriskManager originateAction.setData(originate.getData()); originateAction.setExten(originate.getExten()); originateAction.setPriority(originate.getPriority()); - originateAction.setTimeout(originate.getTimeout()); + originateAction.setTimeout(timeout); originateAction.setVariable(originate.getVariableString()); // must set async to true to receive OriginateEvents. originateAction.setAsync(Boolean.TRUE); - originateAction.setActionId(actionid); - - ManagerResponse response = connection.sendAction(originateAction); - // TODO check the response, don't bother waiting for an originatesuccess - // or originatefailure if the response is bad - if ("Success".equalsIgnoreCase(response.getResponse())) - { - // register and listen for the OriginateSuccess or OriginateFailure - // event - synchronized (call) - { - calls.put(actionid, call); - call.wait(); - } - } - else - { - call.setStartTime(new Date()); - call.setEndTime(call.getStartTime()); - } + // 2000 ms extra for the OriginateFailureEvent should be fine + responseEvents = connection.sendEventGeneratingAction(originateAction, + timeout.longValue() + 2000); - return call; + return originateEvent2Call((OriginateEvent) responseEvents.getEvents() + .toArray()[0]); } /** @@ -182,7 +204,7 @@ public class DefaultAsteriskManager } /* Implementation of the ManagerEventHandler interface */ - + /** * Handles all events received from the asterisk server.<br> * Events are queued until channels and queues are initialized and then @@ -200,58 +222,7 @@ public class DefaultAsteriskManager { handleDisconnectEvent((DisconnectEvent) event); } - - // build initial state if not yet initialized, dispatch otherwise. - if (!initialized) - { - if (event instanceof StatusEvent) - { - handleStatusEvent((StatusEvent) event); - } - else if (event instanceof StatusCompleteEvent) - { - handleStatusCompleteEvent((StatusCompleteEvent) event); - } - else if (event instanceof QueueParamsEvent) - { - handleQueueParamsEvent((QueueParamsEvent) event); - } - else if (event instanceof QueueMemberEvent) - { - handleQueueMemberEvent((QueueMemberEvent) event); - } - else if (event instanceof QueueEntryEvent) - { - handleQueueEntryEvent((QueueEntryEvent) event); - } - else - { - queuedEvents.add(event); - } - - if (channelsInitialized && queuesInitialized) - { - Iterator i = queuedEvents.iterator(); - - while (i.hasNext()) - { - ManagerEvent queuedEvent = (ManagerEvent) i.next(); - dispatchEvent(queuedEvent); - i.remove(); - } - - this.initialized = true; - } - } - else - { - dispatchEvent(event); - } - } - - protected void dispatchEvent(ManagerEvent event) - { - if (event instanceof NewChannelEvent) + else if (event instanceof NewChannelEvent) { handleNewChannelEvent((NewChannelEvent) event); } @@ -279,14 +250,6 @@ public class DefaultAsteriskManager { handleHangupEvent((HangupEvent) event); } - else if (event instanceof OriginateSuccessEvent) - { - handleOriginateSuccessEvent((OriginateSuccessEvent) event); - } - else if (event instanceof OriginateFailureEvent) - { - handleOriginateFailureEvent((OriginateFailureEvent) event); - } } protected void addChannel(Channel channel) @@ -350,17 +313,11 @@ public class DefaultAsteriskManager if (isNew) { - log.info("Adding new channel " + channel.getName()); + logger.info("Adding new channel " + channel.getName()); addChannel(channel); } } - protected void handleStatusCompleteEvent(StatusCompleteEvent event) - { - log.info("Channels are now initialized"); - this.channelsInitialized = true; - } - /** * Resets the internal state when the connection to the asterisk server is * lost. @@ -369,11 +326,6 @@ public class DefaultAsteriskManager { this.channels.clear(); this.queues.clear(); - this.queuedEvents.clear(); - this.channelsInitialized = false; - // TODO fix detection of queuesInitialized - this.queuesInitialized = true; - this.initialized = false; } /** @@ -382,28 +334,22 @@ public class DefaultAsteriskManager */ protected void handleConnectEvent(ConnectEvent connectEvent) { - // first connect is no reconnect ;) - if (!loggedIn) - { - return; - } - try { - connection.sendAction(new StatusAction()); + initializeChannels(); } catch (Exception e) { - log.error("Unable to request channel status after reconnect.", e); + logger.error("Unable to initialize channels after reconnect.", e); } try { - connection.sendAction(new QueueStatusAction()); + initializeQueues(); } - catch (Exception e) + catch (IOException e) { - log.error("Unable to request queue status after reconnect.", e); + logger.error("Unable to initialize queues after reconnect.", e); } } @@ -427,7 +373,7 @@ public class DefaultAsteriskManager if (isNew) { - log.info("Adding new queue " + queue.getName()); + logger.info("Adding new queue " + queue.getName()); addQueue(queue); } } @@ -444,13 +390,13 @@ public class DefaultAsteriskManager if (queue == null) { - log.error("ignored QueueEntryEvent for unknown queue " + logger.error("ignored QueueEntryEvent for unknown queue " + event.getQueue()); return; } if (channel == null) { - log.error("ignored QueueEntryEvent for unknown channel " + logger.error("ignored QueueEntryEvent for unknown channel " + event.getChannel()); return; } @@ -490,7 +436,7 @@ public class DefaultAsteriskManager channel.setCallerId(event.getCallerId()); channel.setState(ChannelStateEnum.getEnum(event.getState())); - log.info("Adding channel " + channel.getName()); + logger.info("Adding channel " + channel.getName()); addChannel(channel); } @@ -499,7 +445,7 @@ public class DefaultAsteriskManager Channel channel = (Channel) channels.get(event.getUniqueId()); if (channel == null) { - log.error("Ignored NewExtenEvent for unknown channel " + logger.error("Ignored NewExtenEvent for unknown channel " + event.getChannel()); return; } @@ -519,7 +465,7 @@ public class DefaultAsteriskManager Channel channel = (Channel) channels.get(event.getUniqueId()); if (channel == null) { - log.error("Ignored NewStateEvent for unknown channel " + logger.error("Ignored NewStateEvent for unknown channel " + event.getChannel()); return; } @@ -532,7 +478,7 @@ public class DefaultAsteriskManager Channel channel = (Channel) channels.get(event.getUniqueId()); if (channel == null) { - log.error("Ignored HangupEvent for unknown channel " + logger.error("Ignored HangupEvent for unknown channel " + event.getChannel()); return; } @@ -542,7 +488,7 @@ public class DefaultAsteriskManager channel.setState(ChannelStateEnum.HUNGUP); } - log.info("Removing channel " + channel.getName() + " due to hangup"); + logger.info("Removing channel " + channel.getName() + " due to hangup"); removeChannel(channel); } @@ -553,18 +499,18 @@ public class DefaultAsteriskManager if (channel1 == null) { - log.error("Ignored LinkEvent for unknown channel " + logger.error("Ignored LinkEvent for unknown channel " + event.getChannel1()); return; } if (channel2 == null) { - log.error("Ignored LinkEvent for unknown channel " + logger.error("Ignored LinkEvent for unknown channel " + event.getChannel2()); return; } - log.info("Linking channels " + channel1.getName() + " and " + logger.info("Linking channels " + channel1.getName() + " and " + channel2.getName()); synchronized (this) { @@ -580,18 +526,18 @@ public class DefaultAsteriskManager if (channel1 == null) { - log.error("Ignored UnlinkEvent for unknown channel " + logger.error("Ignored UnlinkEvent for unknown channel " + event.getChannel1()); return; } if (channel2 == null) { - log.error("Ignored UnlinkEvent for unknown channel " + logger.error("Ignored UnlinkEvent for unknown channel " + event.getChannel2()); return; } - log.info("Unlinking channels " + channel1.getName() + " and " + logger.info("Unlinking channels " + channel1.getName() + " and " + channel2.getName()); synchronized (channel1) { @@ -608,64 +554,27 @@ public class DefaultAsteriskManager { Channel channel = (Channel) channels.get(event.getUniqueId()); - log.info("Renaming channel '" + channel.getName() + "' to '" + logger.info("Renaming channel '" + channel.getName() + "' to '" + event.getNewname() + "'"); channel.setName(event.getNewname()); } - protected void handleOriginateSuccessEvent(OriginateSuccessEvent event) + protected Call originateEvent2Call(OriginateEvent event) { - log.debug("Got OriginateSuccess Event" + event); - // see if there is a call registered for this actionid - synchronized (calls) - { - Call call = (Call) calls.get(event.getActionId()); - log.debug("Found a call waiting for this OriginateSuccess event"); - // update the call and notify that it is ready - if (call != null) - { - synchronized (call) - { - Channel channel; - - calls.remove(call); - - channel = (Channel) channels.get(event.getUniqueId()); - call.setUniqueId(event.getUniqueId()); - call.setChannel(channel); - call.setStartTime(event.getDateReceived()); - call.setReason(event.getReason()); - call.notify(); - } - } - } - } + Call call; + Channel channel; - protected void handleOriginateFailureEvent(OriginateFailureEvent event) - { - // see if there is a call registered for this actionid - synchronized (calls) + channel = (Channel) channels.get(event.getUniqueId()); + call = new Call(); + call.setUniqueId(event.getUniqueId()); + call.setChannel(channel); + call.setStartTime(event.getDateReceived()); + if (event instanceof OriginateFailureEvent) { - Call call = (Call) calls.get(event.getActionId()); - - // update the call and notify that it is ready - if (call != null) - { - synchronized (call) - { - Channel channel; - - calls.remove(call); - - channel = (Channel) channels.get(event.getUniqueId()); - call.setUniqueId(event.getUniqueId()); - call.setChannel(channel); - call.setStartTime(event.getDateReceived()); - call.setEndTime(event.getDateReceived()); - call.setReason(event.getReason()); - call.notify(); - } - } + call.setEndTime(event.getDateReceived()); } + call.setReason(event.getReason()); + + return call; } } Index: AsteriskManager.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/AsteriskManager.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- AsteriskManager.java 7 Jul 2005 00:27:35 -0000 1.6 +++ AsteriskManager.java 16 Jul 2005 23:26:59 -0000 1.7 @@ -41,8 +41,7 @@ public interface AsteriskManager * @throws TimeoutException if the originated call is not answered in time * @throws IOException if the action cannot be sent to the asterisk server */ - public Call originateCall(Originate originate) throws TimeoutException, - IOException, Exception; + public Call originateCall(Originate originate) throws TimeoutException, IOException; /** * Returns a Map of active channels.<br> Index: Originate.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/Originate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- Originate.java 22 Jun 2005 18:27:12 -0000 1.1 +++ Originate.java 16 Jul 2005 23:27:11 -0000 1.2 @@ -28,7 +28,7 @@ public class Originate private String exten; private String context; private Integer priority; - private Integer timeout; + private Long timeout; private String callerId; private Map variables = new HashMap(); private String account; @@ -174,7 +174,7 @@ public class Originate /** * Returns the timeout for the origination. */ - public Integer getTimeout() + public Long getTimeout() { return timeout; } @@ -183,9 +183,9 @@ public class Originate * Sets the timeout (in milliseconds) for the origination.<br> * The channel must be answered within this time, otherwise the origination * is considered to have failed and an OriginateFailureEvent is generated.<br> - * If not set, asterisk assumes a default value of 30000 meaning 30 seconds. + * If not set, a default value of 30000 is asumed meaning 30 seconds. */ - public void setTimeout(Integer timeout) + public void setTimeout(Long timeout) { this.timeout = timeout; } |
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13887/src/java/net/sf/asterisk/manager Modified Files: DefaultManagerConnection.java ManagerConnection.java TimeoutException.java Added Files: EventTimeoutException.java Log Message: Added EventTimeoutException to allow access to the partial result when using buggy actions in Asterisk that dont send the correct ActionResponseEvent. --- NEW FILE: EventTimeoutException.java --- /* * Copyright 2004-2005 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 net.sf.asterisk.manager; /** * An EventTimeoutException is thrown if a ManagerResponse or ResponseEvents are * not completely received within the expected time period. * * @author srt * @version $Id: EventTimeoutException.java,v 1.1 2005/07/16 22:04:55 srt Exp $ * @since 0.2 */ public class EventTimeoutException extends TimeoutException { /** * Serial version identifier. */ private static final long serialVersionUID = 5461825583966922L; private final ResponseEvents partialResult; /** * Creates a new EventTimeoutException with the given message and partial * result. * * @param message message with details about the timeout. * @param partialResult the ResponseEvents object filled with the parts that * have been received before the timeout occured. */ public EventTimeoutException(String message, ResponseEvents partialResult) { super(message); this.partialResult = partialResult; } /** * Returns the partial result that has been received before the timeout * occured.<br> * Note: Using the partial result in your application should be avoided * wherever possible. This is only a hack to handle those versions of * Asterisk that don't follow the Manager API conventions, for example by * not sending the correct ActionCompleteEvent. * * @return the ResponseEvents object filled with the parts that have been * received before the timeout occured. Note: The response attribute * may be <code>null</code> when no response has been received. */ public ResponseEvents getPartialResult() { return partialResult; } } Index: DefaultManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultManagerConnection.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -p -r1.21 -r1.22 --- DefaultManagerConnection.java 16 Jul 2005 21:48:16 -0000 1.21 +++ DefaultManagerConnection.java 16 Jul 2005 22:04:54 -0000 1.22 @@ -621,7 +621,7 @@ public class DefaultManagerConnection im } public ResponseEvents sendEventGeneratingAction(EventGeneratingAction action) - throws IOException, TimeoutException, IllegalArgumentException, + throws IOException, EventTimeoutException, IllegalArgumentException, IllegalStateException { return sendEventGeneratingAction(action, defaultEventTimeout); @@ -629,7 +629,7 @@ public class DefaultManagerConnection im public ResponseEvents sendEventGeneratingAction( EventGeneratingAction action, long timeout) throws IOException, - TimeoutException, IllegalArgumentException, IllegalStateException + EventTimeoutException, IllegalArgumentException, IllegalStateException { ResponseEventsImpl responseEvents; ResponseEventHandler responseEventHandler; @@ -709,9 +709,9 @@ public class DefaultManagerConnection im this.responseEventHandlers.remove(internalActionId); } - throw new TimeoutException( + throw new EventTimeoutException( "Timeout waiting for response or response events to " - + action.getAction()); + + action.getAction(), responseEvents); } } Index: ManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerConnection.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -p -r1.10 -r1.11 --- ManagerConnection.java 16 Jul 2005 21:48:16 -0000 1.10 +++ ManagerConnection.java 16 Jul 2005 22:04:55 -0000 1.11 @@ -166,7 +166,7 @@ public interface ManagerConnection * @return a ResponseEvents that contains the corresponding response and * response events received from the Asterisk server * @throws IOException if the network connection is disrupted. - * @throws TimeoutException if no response or not all response events are + * @throws EventTimeoutException if no response or not all response events are * received within the given timeout period. * @throws IllegalArgumentException if the action is <code>null</code>, * the actionCompleteEventClass property of the action is @@ -179,7 +179,7 @@ public interface ManagerConnection * @since 0.2 */ ResponseEvents sendEventGeneratingAction(EventGeneratingAction action) - throws IOException, TimeoutException, IllegalArgumentException, + throws IOException, EventTimeoutException, IllegalArgumentException, IllegalStateException; /** @@ -199,7 +199,7 @@ public interface ManagerConnection * @return a ResponseEvents that contains the corresponding response and * response events received from the Asterisk server * @throws IOException if the network connection is disrupted. - * @throws TimeoutException if no response or not all response events are + * @throws EventTimeoutException if no response or not all response events are * received within the given timeout period. * @throws IllegalArgumentException if the action is <code>null</code>, * the actionCompleteEventClass property of the action is @@ -212,7 +212,7 @@ public interface ManagerConnection * @since 0.2 */ ResponseEvents sendEventGeneratingAction(EventGeneratingAction action, - long timeout) throws IOException, TimeoutException, + long timeout) throws IOException, EventTimeoutException, IllegalArgumentException, IllegalStateException; /** Index: TimeoutException.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/TimeoutException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- TimeoutException.java 23 Feb 2005 22:50:57 -0000 1.2 +++ TimeoutException.java 16 Jul 2005 22:04:55 -0000 1.3 @@ -17,8 +17,8 @@ package net.sf.asterisk.manager; /** - * A TimeoutException is thrown if a ManagerResponse is not received within the expected time - * period. + * A TimeoutException is thrown if a ManagerResponse is not received within the + * expected time period. * * @author srt * @version $Id$ @@ -32,6 +32,7 @@ public class TimeoutException extends Ex /** * Creates a new TimeoutException with the given message. + * * @param message message with details about the timeout. */ public TimeoutException(final String message) |
From: Stefan R. <sr...@us...> - 2005-07-16 21:48:25
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11254/src/java/net/sf/asterisk/manager Modified Files: DefaultManagerConnection.java ManagerConnection.java Added Files: ResponseEvents.java Log Message: Introduced EventGeneratingActions --- NEW FILE: ResponseEvents.java --- /* * Copyright 2004-2005 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 net.sf.asterisk.manager; import java.util.Collection; import net.sf.asterisk.manager.response.ManagerResponse; /** * Contains the result of executing an EventGeneratingAction, that is the * ManagerResponse and any received ManagerEvents. * * @see net.sf.asterisk.manager.action.EventGeneratingAction * @author srt * @version $Id: ResponseEvents.java,v 1.1 2005/07/16 21:48:15 srt Exp $ * @since 0.2 */ public interface ResponseEvents { /** * Returns the ManagerResponse received. * * @return the ManagerResponse received. */ ManagerResponse getResponse(); /** * Returns a Collection of ManagerEvents that have been received including * the last one that indicates completion. * * @return a Collection of ManagerEvents received. */ Collection getEvents(); } Index: DefaultManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultManagerConnection.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -p -r1.20 -r1.21 --- DefaultManagerConnection.java 16 Jul 2005 00:17:26 -0000 1.20 +++ DefaultManagerConnection.java 16 Jul 2005 21:48:16 -0000 1.21 @@ -29,14 +29,17 @@ import java.util.Map; import net.sf.asterisk.io.SocketConnectionFacade; import net.sf.asterisk.io.SocketConnectionFacadeImpl; import net.sf.asterisk.manager.action.ChallengeAction; +import net.sf.asterisk.manager.action.EventGeneratingAction; import net.sf.asterisk.manager.action.LoginAction; import net.sf.asterisk.manager.action.LogoffAction; import net.sf.asterisk.manager.action.ManagerAction; import net.sf.asterisk.manager.event.ConnectEvent; import net.sf.asterisk.manager.event.DisconnectEvent; import net.sf.asterisk.manager.event.ManagerEvent; +import net.sf.asterisk.manager.event.ResponseEvent; import net.sf.asterisk.manager.impl.ManagerReaderImpl; import net.sf.asterisk.manager.impl.ManagerWriterImpl; +import net.sf.asterisk.manager.impl.ResponseEventsImpl; import net.sf.asterisk.manager.response.ChallengeResponse; import net.sf.asterisk.manager.response.ManagerError; import net.sf.asterisk.manager.response.ManagerResponse; @@ -48,7 +51,8 @@ import net.sf.asterisk.util.LogFactory; * * @see net.sf.asterisk.manager.ManagerConnection * @author srt - * @version $Id$ + * @version $Id: DefaultManagerConnection.java,v 1.20 2005/07/16 00:17:26 srt + * Exp $ */ public class DefaultManagerConnection implements ManagerConnection, Dispatcher { @@ -57,17 +61,60 @@ public class DefaultManagerConnection im */ private final Log logger = LogFactory.getLog(getClass()); + /** + * Used to construct the internalActionId. + */ private long actionIdCount = 0; /* Config attributes */ + /** + * The Asterisk server to connect to. + */ private AsteriskServer asteriskServer; + + /** + * The username to use for login as defined in Asterisk's + * <code>manager.conf</code>. + */ protected String username; + + /** + * The password to use for login as defined in Asterisk's + * <code>manager.conf</code>. + */ protected String password; - private long defaultTimeout = 2000; + + /** + * The default timeout to wait for a ManagerResponse after sending a + * ManagerAction. + */ + private long defaultResponseTimeout = 2000; + + /** + * The default timeout to wait for the last ResponseEvent after sending an + * EventGeneratingAction. + */ + private long defaultEventTimeout = 5000; + + /** + * The time the calling thread is sleeping between checking if a reponse or + * the protocol identifer has been received. + */ private long sleepTime = 50; + + /** + * Should we continue to reconnect after an authentication failure? + */ private boolean keepAliveAfterAuthenticationFailure = false; + /** + * The socket to use for TCP/IP communication with Asterisk. + */ private SocketConnectionFacade socket; + + /** + * The thread that runs the reader. + */ private Thread readerThread; /** @@ -80,19 +127,60 @@ public class DefaultManagerConnection im */ private ManagerWriter writer; + /** + * The protocol identifer Asterisk sends on connect. + */ private String protocolIdentifier; + + /** + * Contains the registered handlers that process the ManagerResponses.<br> + * Key is the internalActionId of the Action sent and value the + * corresponding ResponseHandler. + */ private final Map responseHandlers; + + /** + * Contains the event handlers that handle ResponseEvents for the + * sendEventGeneratingAction methods.<br> + * Key is the internalActionId of the Action sent and value the + * corresponding EventHandler. + */ + private final Map responseEventHandlers; + + /** + * Contains the event handlers that users registered. + */ private final List eventHandlers; + + /** + * Should we attempt to reconnect when the connection is lost?<br> + * This is set to <code>true</code> after successful login and to + * <code>false</code> after logoff or after an authentication failure when + * keepAliveAfterAuthenticationFailure is <code>false</code>. + */ protected boolean keepAlive = false; + /** + * Creates a new instance. + */ public DefaultManagerConnection() { this.asteriskServer = new AsteriskServer(); this.responseHandlers = new HashMap(); + this.responseEventHandlers = new HashMap(); this.eventHandlers = new ArrayList(); } + /** + * Creates a new instance with the given connection parameters. + * + * @param hostname the hosname of the Asterisk server to connect to. + * @param port the port where Asterisk listens for incoming Manager API + * connections, usually 5038. + * @param username the username to use for login + * @param password the password to use for login + */ public DefaultManagerConnection(String hostname, int port, String username, String password) { @@ -104,6 +192,8 @@ public class DefaultManagerConnection im setPassword(password); } + // the following two methods can be overriden when running test cases to + // return a mock object protected ManagerReader createReader(Dispatcher dispatcher, AsteriskServer server) { @@ -161,27 +251,60 @@ public class DefaultManagerConnection im } /** - * Sets the time in milli seconds the synchronous method + * Sets the time in milliseconds the synchronous sendAction methods * {@link #sendAction(ManagerAction)} will wait for a response before * throwing a TimeoutException.<br> * Default is 2000. * - * @param defaultTimeout default timeout in milli seconds + * @param defaultTimeout default timeout in milliseconds + * @deprecated use {@link #setDefaultResponseTimeout(long)} instead */ public void setDefaultTimeout(long defaultTimeout) { - this.defaultTimeout = defaultTimeout; + setDefaultResponseTimeout(defaultTimeout); } /** - * Sets the time in milli seconds the synchronous methods + * Sets the time in milliseconds the synchronous method + * {@link #sendAction(ManagerAction)} will wait for a response before + * throwing a TimeoutException.<br> + * Default is 2000. + * + * @param defaultResponseTimeout default response timeout in milliseconds + * @since 0.2 + */ + public void setDefaultResponseTimeout(long defaultResponseTimeout) + { + this.defaultResponseTimeout = defaultResponseTimeout; + } + + /** + * Sets the time in milliseconds the synchronous method + * {@link #sendEventGeneratingAction(EventGeneratingAction)} will wait for a + * response and the last response event before throwing a TimeoutException.<br> + * Default is 5000. + * + * @param defaultEventTimeout default event timeout in milliseconds + * @since 0.2 + */ + public void setDefaultEventTimeout(long defaultEventTimeout) + { + this.defaultEventTimeout = defaultEventTimeout; + } + + /** + * Sets the time in milliseconds the synchronous methods * {@link #sendAction(ManagerAction)} and * {@link #sendAction(ManagerAction, long)} will sleep between two checks * for the arrival of a response. This value should be rather small.<br> + * The sleepTime attribute is also used when checking for the protocol + * identifer.<br> * Default is 50. * - * @param sleepTime time in milli seconds to sleep between two checks for - * the arrival of a responser + * @param sleepTime time in milliseconds to sleep between two checks for the + * arrival of a response or the protocol identifier + * @deprecated this has been replaced by an interrupt based response + * checking approach. */ public void setSleepTime(long sleepTime) { @@ -226,7 +349,7 @@ public class DefaultManagerConnection im public void login() throws IOException, AuthenticationFailedException, TimeoutException { - login(defaultTimeout); + login(defaultResponseTimeout); } /** @@ -256,6 +379,7 @@ public class DefaultManagerConnection im private void login(long timeout) throws IOException, AuthenticationFailedException, TimeoutException { + long start; long timeSpent; ChallengeAction challengeAction; ChallengeResponse challengeResponse; @@ -268,24 +392,24 @@ public class DefaultManagerConnection im connect(); } - timeSpent = 0; + start = System.currentTimeMillis(); while (getProtocolIdentifier() == null) { try { Thread.sleep(sleepTime); - timeSpent += sleepTime; - - if (timeSpent > timeout) - { - disconnect(); - throw new TimeoutException( - "Timeout waiting for protocol identifier"); - } } catch (InterruptedException e) { } + + timeSpent = System.currentTimeMillis() - start; + if (getProtocolIdentifier() == null && timeSpent > timeout) + { + disconnect(); + throw new TimeoutException( + "Timeout waiting for protocol identifier"); + } } challengeAction = new ChallengeAction(); @@ -300,7 +424,9 @@ public class DefaultManagerConnection im loginAction.setUsername(username); try { - MessageDigest md = MessageDigest.getInstance("MD5"); + MessageDigest md; + + md = MessageDigest.getInstance("MD5"); if (challenge != null) { md.update(challenge.getBytes()); @@ -326,8 +452,7 @@ public class DefaultManagerConnection im } // successfully logged in so assure that we keep trying to reconnect - // when - // disconnected + // when disconnected this.keepAlive = true; logger.info("Successfully logged in"); @@ -351,7 +476,7 @@ public class DefaultManagerConnection im this.socket = createSocket(); this.reader.setSocket(socket); - this.readerThread = new Thread(reader, "ManagerReaderThread"); + this.readerThread = new Thread(reader, "ManagerReader"); this.readerThread.start(); this.writer.setSocket(socket); @@ -373,7 +498,7 @@ public class DefaultManagerConnection im public synchronized boolean isConnected() { return socket != null && socket.isConnected(); // JDK 1.4 - //return socket != null; + // return socket != null; } /** @@ -395,6 +520,9 @@ public class DefaultManagerConnection im } } + /** + * Closes the socket connection. + */ private synchronized void disconnect() { if (this.socket != null) @@ -413,48 +541,53 @@ public class DefaultManagerConnection im } public ManagerResponse sendAction(ManagerAction action) throws IOException, - TimeoutException + TimeoutException, IllegalArgumentException, IllegalStateException { - return sendAction(action, defaultTimeout); + return sendAction(action, defaultResponseTimeout); } public ManagerResponse sendAction(ManagerAction action, long timeout) - throws IOException, TimeoutException + throws IOException, TimeoutException, IllegalArgumentException, + IllegalStateException { + long start; long timeSpent; ResponseHandlerResult result; ManagerResponseHandler callbackHandler; result = new ResponseHandlerResult(); - callbackHandler = new DefaultResponseHandler(result); + callbackHandler = new DefaultResponseHandler(result, Thread + .currentThread()); sendAction(action, callbackHandler); + start = System.currentTimeMillis(); timeSpent = 0; while (result.getResponse() == null) { try { - Thread.sleep(sleepTime); - timeSpent += sleepTime; - - if (timeSpent > timeout) - { - throw new TimeoutException( - "Timeout waiting for response to " - + action.getAction()); - } + Thread.sleep(timeout - timeSpent); } catch (InterruptedException ex) { } + + // still no response and timed out? + timeSpent = System.currentTimeMillis() - start; + if (result.getResponse() == null && timeSpent > timeout) + { + throw new TimeoutException("Timeout waiting for response to " + + action.getAction()); + } } return result.getResponse(); } public void sendAction(ManagerAction action, - ManagerResponseHandler callbackHandler) throws IOException + ManagerResponseHandler callbackHandler) throws IOException, + IllegalArgumentException, IllegalStateException { String internalActionId; @@ -474,6 +607,8 @@ public class DefaultManagerConnection im action.setActionId(Util.addInternalActionId(action.getActionId(), internalActionId)); + // if the callbackHandler is null the user is obviously not interested + // in the response, thats fine. if (callbackHandler != null) { synchronized (this.responseHandlers) @@ -485,9 +620,118 @@ public class DefaultManagerConnection im writer.sendAction(action); } + public ResponseEvents sendEventGeneratingAction(EventGeneratingAction action) + throws IOException, TimeoutException, IllegalArgumentException, + IllegalStateException + { + return sendEventGeneratingAction(action, defaultEventTimeout); + } + + public ResponseEvents sendEventGeneratingAction( + EventGeneratingAction action, long timeout) throws IOException, + TimeoutException, IllegalArgumentException, IllegalStateException + { + ResponseEventsImpl responseEvents; + ResponseEventHandler responseEventHandler; + String internalActionId; + long start; + long timeSpent; + + if (action == null) + { + throw new IllegalArgumentException( + "Unable to send action: action is null."); + } + else if (action.getActionCompleteEventClass() == null) + { + throw new IllegalArgumentException( + "Unable to send action: actionCompleteEventClass is null."); + } + else if (!ResponseEvent.class.isAssignableFrom(action + .getActionCompleteEventClass())) + { + throw new IllegalArgumentException( + "Unable to send action: actionCompleteEventClass is not a ResponseEvent."); + } + + if (socket == null) + { + throw new IllegalStateException("Unable to send " + + action.getAction() + " action: not connected."); + } + + responseEvents = new ResponseEventsImpl(); + responseEventHandler = new ResponseEventHandler(responseEvents, action + .getActionCompleteEventClass(), Thread.currentThread()); + + internalActionId = createInternalActionId(); + action.setActionId(Util.addInternalActionId(action.getActionId(), + internalActionId)); + + // register response handler... + synchronized (this.responseHandlers) + { + this.responseHandlers.put(internalActionId, responseEventHandler); + } + + // ...and event handler. + synchronized (this.responseEventHandlers) + { + this.responseEventHandlers.put(internalActionId, + responseEventHandler); + } + + writer.sendAction(action); + + // let's wait to see what we get + start = System.currentTimeMillis(); + timeSpent = 0; + while (responseEvents.getResponse() == null + || !responseEvents.isComplete()) + { + try + { + Thread.sleep(timeout - timeSpent); + } + catch (InterruptedException ex) + { + } + + // still no response or not all events received and timed out? + timeSpent = System.currentTimeMillis() - start; + if ((responseEvents.getResponse() == null || !responseEvents + .isComplete()) + && timeSpent > timeout) + { + // clean up + synchronized (this.responseEventHandlers) + { + this.responseEventHandlers.remove(internalActionId); + } + + throw new TimeoutException( + "Timeout waiting for response or response events to " + + action.getAction()); + } + } + + // remove the event handler (note: the response handler is removed + // automatically when the response is received) + synchronized (this.responseEventHandlers) + { + this.responseEventHandlers.remove(internalActionId); + } + + return responseEvents; + } + /** * Creates a new unique internal action id based on the hash code of this * connection and a sequence. + * + * @see Util#addInternalActionId(String, String) + * @see Util#getInternalActionId(String) + * @see Util#stripInternalActionId(String) */ private String createInternalActionId() { @@ -505,7 +749,8 @@ public class DefaultManagerConnection im { synchronized (this.eventHandlers) { - if (! this.eventHandlers.contains(eventHandler)) + // only add it if its not already there + if (!this.eventHandlers.contains(eventHandler)) { this.eventHandlers.add(eventHandler); } @@ -533,14 +778,14 @@ public class DefaultManagerConnection im return asteriskServer; } - /* Callbacks for ManagerReaderImpl */ + /* Implementation of Dispatcher: callbacks for ManagerReader */ /** * This method is called by the reader whenever a {@link ManagerResponse} is * received. The response is dispatched to the associated * {@link ManagerResponseHandler}. * - * @param response the resonse received by the reader + * @param response the response received by the reader * @see ManagerReader */ public void dispatchResponse(ManagerResponse response) @@ -549,6 +794,7 @@ public class DefaultManagerConnection im String internalActionId; ManagerResponseHandler responseHandler; + // shouldn't happen if (response == null) { logger.error("Unable to dispatch null response"); @@ -580,17 +826,17 @@ public class DefaultManagerConnection im } else { - logger - .warn("No response handler registered for internalActionId '" - + internalActionId + "'"); + // when using the async sendAction it's ok not to register a + // callback so if we don't find a response handler thats ok + logger.debug("No response handler registered for " + + "internalActionId '" + internalActionId + "'"); } } } else { - logger - .error("Unable to retrieve internalActionId from response: asterisk sent actionId '" - + actionId + "':\n" + response); + logger.error("Unable to retrieve internalActionId from response: " + + "actionId '" + actionId + "':\n" + response); } if (responseHandler != null) @@ -601,13 +847,10 @@ public class DefaultManagerConnection im } catch (Exception e) { - logger.warn("Exception calling responseHandler", e); + logger.warn("Exception calling responseHandler " + + responseHandler.getClass().getName(), e); } } - else - { - logger.info("responseHandler not found"); - } } /** @@ -621,14 +864,53 @@ public class DefaultManagerConnection im */ public void dispatchEvent(ManagerEvent event) { + // shouldn't happen if (event == null) { logger.error("Unable to dispatch null event"); return; } - logger.debug("Dispatching event:\n" + event); + logger.debug("Dispatching event:\n" + event.toString()); + + // dispatch ResponseEvents to the appropriate responseEventHandler + if (event instanceof ResponseEvent) + { + ResponseEvent responseEvent; + String internalActionId; + + responseEvent = (ResponseEvent) event; + internalActionId = responseEvent.getInternalActionId(); + if (internalActionId != null) + { + synchronized (responseEventHandlers) + { + ManagerEventHandler eventHandler; + + eventHandler = (ManagerEventHandler) responseEventHandlers + .get(internalActionId); + if (eventHandler != null) + { + try + { + eventHandler.handleEvent(event); + } + catch (Exception e) + { + logger.warn("Exception calling eventHandler " + + eventHandler.getClass().getName(), e); + } + } + } + } + else + { + logger.error("Unable to handle ResponseEvent without " + + "internalActionId:\n" + responseEvent); + } + } + // dispatch to eventHandlers registered by users synchronized (eventHandlers) { Iterator i = eventHandlers.iterator(); @@ -643,17 +925,23 @@ public class DefaultManagerConnection im } catch (Exception e) { - logger.warn("Exception calling eventHandler", e); + logger.warn("Exception calling eventHandler " + + eventHandler.getClass().getName(), e); } } } + // process special events if (event instanceof ConnectEvent) { - setProtocolIdentifier(((ConnectEvent) event) - .getProtocolIdentifier()); + ConnectEvent connectEvent; + String protocolIdentifier; + + connectEvent = (ConnectEvent) event; + protocolIdentifier = connectEvent.getProtocolIdentifier(); + setProtocolIdentifier(protocolIdentifier); } - if (event instanceof DisconnectEvent) + else if (event instanceof DisconnectEvent) { reconnect(); } @@ -664,7 +952,7 @@ public class DefaultManagerConnection im * reader. Having received a correct protocol identifier is the precodition * for logging in. * - * @param protocolIdentifier the protocol version used by the asterisk + * @param protocolIdentifier the protocol version used by the Asterisk * server. */ private void setProtocolIdentifier(final String protocolIdentifier) @@ -673,14 +961,12 @@ public class DefaultManagerConnection im if (!"Asterisk Call Manager/1.0".equals(protocolIdentifier)) { - logger - .warn("Unsupported protocol version '" - + protocolIdentifier - + "'. This library has only been tested with version 1.0 of the asterisk " - + "call manager protocol. Use at your own risk!"); + logger.warn("Unsupported protocol version '" + protocolIdentifier + + "'. Use at your own risk."); } this.protocolIdentifier = protocolIdentifier; + } /** @@ -722,7 +1008,7 @@ public class DefaultManagerConnection im } catch (InterruptedException e1) { - // it's ok to awake us + // it's ok to wake us } try @@ -744,14 +1030,16 @@ public class DefaultManagerConnection im } else { - logger.error("Unable to log in after reconnect. Giving up."); + logger.error("Unable to log in after reconnect. " + + "Giving up."); this.keepAlive = false; } } catch (TimeoutException e1) { // shouldn't happen - logger.error("TimeoutException while trying to log in after reconnect."); + logger.error("TimeoutException while trying to log in " + + "after reconnect."); synchronized (this) { socket.close(); @@ -811,15 +1099,101 @@ public class DefaultManagerConnection im */ private static final long serialVersionUID = 2926598671855316803L; private ResponseHandlerResult result; + private final Thread thread; - public DefaultResponseHandler(ResponseHandlerResult result) + /** + * Creates a new instance. + * + * @param result the result to store the response in + * @param thread the thread to interrupt when the response has been + * received + */ + public DefaultResponseHandler(ResponseHandlerResult result, + Thread thread) { this.result = result; + this.thread = thread; } public void handleResponse(ManagerResponse response) { - this.result.setResponse(response); + result.setResponse(response); + thread.interrupt(); + } + } + + /** + * A combinded event and response handler that adds received events and the + * response to a ResponseEvents object. + */ + private class ResponseEventHandler + implements + ManagerEventHandler, + ManagerResponseHandler, + Serializable + { + /** + * Serializable version identifier + */ + private static final long serialVersionUID = 2926598671855316803L; + private final ResponseEventsImpl events; + private final Class actionCompleteEventClass; + private final Thread thread; + + /** + * Creates a new instance. + * + * @param events the ResponseEventsImpl to store the events in + * @param actionCompleteEventClass the type of event that indicates that + * all events have been received + * @param thread the thread to interrupt when the + * actionCompleteEventClass has been received + */ + public ResponseEventHandler(ResponseEventsImpl events, + Class actionCompleteEventClass, Thread thread) + { + this.events = events; + this.actionCompleteEventClass = actionCompleteEventClass; + this.thread = thread; + } + + public void handleEvent(ManagerEvent event) + { + // should always be a ResponseEvent, anyway... + if (event instanceof ResponseEvent) + { + ResponseEvent responseEvent; + + responseEvent = (ResponseEvent) event; + events.addEvent(responseEvent); + } + + // finished? + if (actionCompleteEventClass.isAssignableFrom(event.getClass())) + { + synchronized (events) + { + events.setComplete(true); + if (events.getResponse() != null) + { + thread.interrupt(); + } + } + } + } + + public void handleResponse(ManagerResponse response) + { + synchronized (events) + { + events.setRepsonse(response); + + // finished? + if (events.isComplete()) + { + thread.interrupt(); + } + } } } } Index: ManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerConnection.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -p -r1.9 -r1.10 --- ManagerConnection.java 16 Jul 2005 13:19:34 -0000 1.9 +++ ManagerConnection.java 16 Jul 2005 21:48:16 -0000 1.10 @@ -18,6 +18,7 @@ package net.sf.asterisk.manager; import java.io.IOException; +import net.sf.asterisk.manager.action.EventGeneratingAction; import net.sf.asterisk.manager.action.ManagerAction; import net.sf.asterisk.manager.event.ManagerEvent; import net.sf.asterisk.manager.response.ManagerResponse; @@ -45,10 +46,10 @@ public interface ManagerConnection * Asterisk allows you to send custom events via the UserEvent application. * If you choose to send such events you can extend the abstract class * UserEvent provide a name for your new event and optionally add your own - * attributes. After registering a user event type asterisk-java will handle + * attributes. After registering a user event type Asterisk-Java will handle * such events the same way it handles the internal events and inform your * registered event handlers.<br> - * Note: If you write your own asterisk applications that use asterisk's + * Note: If you write your own Asterisk applications that use Asterisk's * <code>manager_event()</code> function directly and don't use the * channel and uniqueid attributes provided by UserEvent you can also * register events that directly subclass ManagerEvent. @@ -60,7 +61,7 @@ public interface ManagerConnection void registerUserEventClass(Class userEventClass); /** - * Logs in to the asterisk server with the username and password specified + * Logs in to the Asterisk server with the username and password specified * when this connection was created. * * @throws IOException if the network connection is disrupted. @@ -78,7 +79,7 @@ public interface ManagerConnection TimeoutException; /** - * Sends a LogoffAction to the asterisk server and disconnects. + * Sends a LogoffAction to the Asterisk server and disconnects. * * @throws IOException if the network connection is disrupted. * @throws TimeoutException if no response to the logoff action is received @@ -91,59 +92,133 @@ public interface ManagerConnection * Returns the protocol identifier, i.e. a string like "Asterisk Call * Manager/1.0". * - * @return the protocol identifier of the asterisk manager interface in use + * @return the protocol identifier of the Asterisk Manager Interface in use * if it has already been received; <code>null</code> otherwise */ String getProtocolIdentifier(); /** - * Sends a ManagerAction to the asterisk manager interface and waits for the + * Sends a ManagerAction to the Asterisk server and waits for the * corresponding ManagerResponse. * - * @param action the action to send to the asterisk server - * @return the corresponding response received from the asterisk server + * @param action the action to send to the Asterisk server + * @return the corresponding response received from the Asterisk server * @throws IOException if the network connection is disrupted. - * @throws TimeoutException if no reponse is received within the default + * @throws TimeoutException if no response is received within the default * timeout period. + * @throws IllegalArgumentException if the action is <code>null</code>. + * @throws IllegalStateException if you are not connected to an Asterisk + * server. * @see #sendAction(ManagerAction, long) * @see #sendAction(ManagerAction, ManagerResponseHandler) */ ManagerResponse sendAction(ManagerAction action) throws IOException, - TimeoutException; + TimeoutException, IllegalArgumentException, IllegalStateException; /** - * Sends a ManagerAction to the asterisk manager interface and waits for the - * corresponding {@link ManagerResponse}. + * Sends a ManagerAction to the Asterisk server and waits for the + * corresponding ManagerResponse. * - * @param action the action to send to the asterisk server - * @param timeout milliseconds to wait for the reponse before throwing a + * @param action the action to send to the Asterisk server + * @param timeout milliseconds to wait for the response before throwing a * TimeoutException - * @return the corresponding response received from the asterisk server + * @return the corresponding response received from the Asterisk server * @throws IOException if the network connection is disrupted. - * @throws TimeoutException if no reponse is received within the given + * @throws TimeoutException if no response is received within the given * timeout period. + * @throws IllegalArgumentException if the action is <code>null</code>. + * @throws IllegalStateException if you are not connected to an Asterisk + * server. * @see #sendAction(ManagerAction, ManagerResponseHandler) */ ManagerResponse sendAction(ManagerAction action, long timeout) - throws IOException, TimeoutException; + throws IOException, TimeoutException, IllegalArgumentException, + IllegalStateException; /** - * Sends a ManagerAction to the asterisk manager interface and registers a - * callback handler to be called when the corresponding ManagerResponse is - * received. + * Sends a ManagerAction to the Asterisk server and registers a callback + * handler to be called when the corresponding ManagerResponse is received. * - * @param action the action to send to the asterisk server + * @param action the action to send to the Asterisk server * @param callbackHandler the callback handler to call when the response is - * received + * received or <code>null</code> if you are not interested in + * the response * @throws IOException if the network connection is disrupted. + * @throws IllegalArgumentException if the action is <code>null</code>. + * @throws IllegalStateException if you are not connected to an Asterisk + * server. */ void sendAction(ManagerAction action, ManagerResponseHandler callbackHandler) - throws IOException; + throws IOException, IllegalArgumentException, IllegalStateException; + + /** + * Sends a EventGeneratingAction to the Asterisk server and waits for the + * corresponding ManagerResponse and the ResponseEvents.<br> + * EventGeneratingActions are ManagerActions that don't return their + * response in the corresponding ManagerResponse but send a series of events + * that contain the payload.<br> + * Examples for EventGeneratingActions are the + * {@link net.sf.asterisk.manager.action.StatusAction}, the + * {@link net.sf.asterisk.manager.action.QueueAction} or the + * {@link net.sf.asterisk.manager.action.AgentsAction}. + * + * @param action the action to send to the Asterisk server + * @return a ResponseEvents that contains the corresponding response and + * response events received from the Asterisk server + * @throws IOException if the network connection is disrupted. + * @throws TimeoutException if no response or not all response events are + * received within the given timeout period. + * @throws IllegalArgumentException if the action is <code>null</code>, + * the actionCompleteEventClass property of the action is + * <code>null</code> or if actionCompleteEventClass is not a + * ResponseEvent. + * @throws IllegalStateException if you are not connected to an Asterisk + * server. + * @see EventGeneratingAction + * @see net.sf.asterisk.manager.event.ResponseEvent + * @since 0.2 + */ + ResponseEvents sendEventGeneratingAction(EventGeneratingAction action) + throws IOException, TimeoutException, IllegalArgumentException, + IllegalStateException; + + /** + * Sends a EventGeneratingAction to the Asterisk server and waits for the + * corresponding ManagerResponse and the ResponseEvents. + * EventGeneratingActions are ManagerActions that don't return their + * response in the corresponding ManagerResponse but send a series of events + * that contain the payload.<br> + * Examples for EventGeneratingActions are the + * {@link net.sf.asterisk.manager.action.StatusAction}, the + * {@link net.sf.asterisk.manager.action.QueueAction} or the + * {@link net.sf.asterisk.manager.action.AgentsAction}. + * + * @param action the action to send to the Asterisk server + * @param timeout milliseconds to wait for the response and the response + * events before throwing a TimeoutException + * @return a ResponseEvents that contains the corresponding response and + * response events received from the Asterisk server + * @throws IOException if the network connection is disrupted. + * @throws TimeoutException if no response or not all response events are + * received within the given timeout period. + * @throws IllegalArgumentException if the action is <code>null</code>, + * the actionCompleteEventClass property of the action is + * <code>null</code> or if actionCompleteEventClass is not a + * ResponseEvent. + * @throws IllegalStateException if you are not connected to an Asterisk + * server. + * @see EventGeneratingAction + * @see net.sf.asterisk.manager.event.ResponseEvent + * @since 0.2 + */ + ResponseEvents sendEventGeneratingAction(EventGeneratingAction action, + long timeout) throws IOException, TimeoutException, + IllegalArgumentException, IllegalStateException; /** * Registers an event handler to be called whenever an * {@link net.sf.asterisk.manager.event.ManagerEvent} is receiced from the - * asterisk server.<br> + * Asterisk server.<br> * Event handlers are notified about new events in the same order as they * were registered via addEventHandler. * |
From: Stefan R. <sr...@us...> - 2005-07-16 21:48:24
|
Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11254/src/test/net/sf/asterisk/manager Modified Files: DefaultManagerConnectionTest.java Log Message: Introduced EventGeneratingActions Index: DefaultManagerConnectionTest.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager/DefaultManagerConnectionTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -p -r1.10 -r1.11 --- DefaultManagerConnectionTest.java 12 Jul 2005 08:24:22 -0000 1.10 +++ DefaultManagerConnectionTest.java 16 Jul 2005 21:48:16 -0000 1.11 @@ -57,9 +57,7 @@ public class DefaultManagerConnectionTes dmc = new MockedDefaultManagerConnection(mockReader, mockWriter, mockSocket); - // make tests faster that expect a TimeoutException - dmc.setSleepTime(5); - dmc.setDefaultTimeout(20); + dmc.setDefaultResponseTimeout(20); mockWriter.setDispatcher(dmc); mockWriter.setAsteriskServer(asteriskServer); @@ -141,7 +139,17 @@ public class DefaultManagerConnectionTes // Some time for the reader thread to be started. Otherwise run() might // not yet have been // called. - Thread.sleep(10); + try + { + Thread.sleep(10); + } + catch (InterruptedException e) + { + // ugly hack to make this work when the thread is interrupted coz a + // response has been received but the ManagerConnection was not yet + // sleeping + Thread.sleep(10); + } assertEquals("run() not called 1 time", 1, mockReader.runCalls); assertEquals("unexpected call to die()", 0, mockReader.dieCalls); @@ -150,9 +158,10 @@ public class DefaultManagerConnectionTes assertEquals("must have handled exactly one event", 1, managerEventHandler.eventsHandled.size()); - assertTrue("eventHandled must be a ConnectEvent", + assertTrue( + "eventHandled must be a ConnectEvent", managerEventHandler.eventsHandled.get(0) instanceof ConnectEvent); - + socketMC.verify(); } @@ -193,7 +202,17 @@ public class DefaultManagerConnectionTes // Some time for the reader thread to be started. Otherwise run() might // not yet have been // called. - Thread.sleep(10); + try + { + Thread.sleep(10); + } + catch (InterruptedException e) + { + // ugly hack to make this work when the thread is interrupted coz a + // response has been received but the ManagerConnection was not yet + // sleeping + Thread.sleep(10); + } assertEquals("run() not called 1 time", 1, mockReader.runCalls); assertEquals("unexpected call to die()", 0, mockReader.dieCalls); @@ -591,15 +610,14 @@ public class DefaultManagerConnectionTes socketMC.verify(); } - - + public void testDispatchEventWithMultipleEventHandlers() { final int count = 20; ManagerEvent event; MockControl listMC; final List list; - + // verify that event handlers are called in the correct order event = new NewChannelEvent(new AsteriskServer()); listMC = MockControl.createStrictControl(List.class); @@ -609,14 +627,15 @@ public class DefaultManagerConnectionTes final int index = i; list.add(new Integer(index)); listMC.setReturnValue(true); - dmc.addEventHandler(new ManagerEventHandler(){ + dmc.addEventHandler(new ManagerEventHandler() + { public void handleEvent(ManagerEvent event) { list.add(new Integer(index)); } }); } - + listMC.replay(); dmc.dispatchEvent(event); listMC.verify(); |