public class DefaultAsteriskServer extends Object implements AsteriskServer
AsteriskServer| Constructor and Description |
|---|
DefaultAsteriskServer()
Creates a new instance without a
ManagerConnection. |
DefaultAsteriskServer(ManagerConnection eventConnection)
Creates a new instance that uses the given
ManagerConnection. |
DefaultAsteriskServer(String hostname,
int port,
String username,
String password)
Creates a new instance and a new
ManagerConnection with the given
connection data. |
DefaultAsteriskServer(String hostname,
String username,
String password)
Creates a new instance and a new
ManagerConnection with the given
connection data. |
| Modifier and Type | Method and Description |
|---|---|
void |
addAsteriskServerListener(AsteriskServerListener listener)
Adds a listener to this AsteriskServer.
|
void |
addChainListener(ManagerEventListener chainListener)
The chainListener allows a listener to receive manager events after they
have been processed by the AsteriskServer.
|
protected DefaultManagerConnection |
createManagerConnection(String hostname,
int port,
String username,
String password) |
List<String> |
executeCliCommand(String command)
Executes a command line interface (CLI) command.
|
void |
forceQueuesMonitor(boolean force)
every time we get an event of a queue we reload the information about it
from the Asterisk Server
|
Collection<AsteriskAgent> |
getAgents()
Return the agents, registered at Asterisk server.
|
AsteriskChannel |
getChannelById(String id)
Returns a channel by its unique id.
|
AsteriskChannel |
getChannelByName(String name)
Returns a channel by its name.
|
Collection<AsteriskChannel> |
getChannels()
Returns the active channels of the Asterisk server.
|
ConfigFile |
getConfig(String filename)
Reads the given Asterisk configuration file.
|
String |
getGlobalVariable(String variable)
Returns the value of the given global variable.
|
ManagerConnection |
getManagerConnection()
Returns the underlying ManagerConnection.
|
MeetMeRoom |
getMeetMeRoom(String name)
Returns the MeetMe room with the given number, if the room does not yet
exist a new
MeetMeRoom object is created. |
Collection<MeetMeRoom> |
getMeetMeRooms()
Returns the acitve MeetMe rooms on the Asterisk server.
|
AsteriskQueue |
getQueueByName(String queueName)
get Asterisk Queue by name
|
Collection<AsteriskQueue> |
getQueues()
Returns the queues served by the Asterisk server.
|
List<AsteriskQueue> |
getQueuesUpdatedAfter(Date date)
List of Queues Objects updated after certain date
|
String |
getVersion()
Returns the exact version string of this Asterisk server.
|
int[] |
getVersion(String file)
Returns the CVS revision of a given source file of this
Asterisk server.
|
Collection<Voicemailbox> |
getVoicemailboxes()
Returns a collection of all voicemailboxes configured for this Asterisk
server with the number of new and old messages they contain.
|
void |
initialize()
Opens the connection to this server.
|
boolean |
isAsteriskServerListening(AsteriskServerListener listener)
Checks whether the listener is already registered with this Asterisk
server
|
boolean |
isModuleLoaded(String module)
Checks whether a module is currently loaded.
|
boolean |
isQueuesMonitorForced()
Check if the Queue Information is forced
|
void |
loadModule(String module)
Loads a module or subsystem
Available since Asterisk 1.6
|
AsteriskChannel |
originate(OriginateAction originateAction)
Generates an outgoing channel.
|
void |
originateAsync(OriginateAction originateAction,
OriginateCallback cb)
Asynchronously generates an outgoing channel.
|
AsteriskChannel |
originateToApplication(String channel,
String application,
String data,
long timeout)
Generates an outgoing channel to an application.
|
AsteriskChannel |
originateToApplication(String channel,
String application,
String data,
long timeout,
CallerId callerId,
Map<String,String> variables)
Generates an outgoing channel to an application and sets an optional map
of channel variables.
|
void |
originateToApplicationAsync(String channel,
String application,
String data,
long timeout,
CallerId callerId,
Map<String,String> variables,
OriginateCallback cb)
Asynchronously generates an outgoing channel to an application and sets
an optional map of channel variables.
|
void |
originateToApplicationAsync(String channel,
String application,
String data,
long timeout,
OriginateCallback cb)
Asynchronously generates an outgoing channel to an application.
|
AsteriskChannel |
originateToExtension(String channel,
String context,
String exten,
int priority,
long timeout)
Generates an outgoing channel to a dialplan entry (extension, context,
priority).
|
AsteriskChannel |
originateToExtension(String channel,
String context,
String exten,
int priority,
long timeout,
CallerId callerId,
Map<String,String> variables)
Generates an outgoing channel to a dialplan entry (extension, context,
priority) and sets an optional map of channel variables.
|
void |
originateToExtensionAsync(String channel,
String context,
String exten,
int priority,
long timeout,
CallerId callerId,
Map<String,String> variables,
OriginateCallback cb)
Asynchronously generates an outgoing channel to a dialplan entry
(extension, context, priority) and sets an optional map of channel
variables.
|
void |
originateToExtensionAsync(String channel,
String context,
String exten,
int priority,
long timeout,
OriginateCallback cb)
Asynchronously generates an outgoing channel to a dialplan entry
(extension, context, priority).
|
void |
reloadAllModules()
Reloads all currently loaded modules.
|
void |
reloadModule(String module)
Reloads a module or subsystem.
|
void |
removeAsteriskServerListener(AsteriskServerListener listener)
Removes a listener from this Asterisk server.
|
void |
removeChainListener(ManagerEventListener chainListener)
remove the chain listener.
|
void |
setGlobalVariable(String variable,
String value)
Sets the value of the given global variable.
|
void |
setManagerConnection(ManagerConnection eventConnection) |
void |
setSkipQueues(boolean skipQueues)
Determines if queue status is retrieved at startup.
|
void |
shutdown()
Closes the connection to this server.
|
void |
unloadModule(String module)
Unloads a module or subsystem.
|
public DefaultAsteriskServer()
ManagerConnection. The
ManagerConnection must be set using
setManagerConnection(ManagerConnection) before you can use this
AsteriskServer.public DefaultAsteriskServer(String hostname, String username, String password)
ManagerConnection with the given
connection data.hostname - the hostname of the Asterisk server to connect to.username - the username to use for loginpassword - the password to use for loginpublic DefaultAsteriskServer(String hostname, int port, String username, String password)
ManagerConnection with the given
connection data.hostname - the hostname of the Asterisk server to connect to.port - the port where Asterisk listens for incoming Manager API
connections, usually 5038.username - the username to use for loginpassword - the password to use for loginpublic DefaultAsteriskServer(ManagerConnection eventConnection)
ManagerConnection.eventConnection - the ManagerConnection to use for receiving events
from Asterisk.protected DefaultManagerConnection createManagerConnection(String hostname, int port, String username, String password)
public void setSkipQueues(boolean skipQueues)
true to circumvent the startup delay caused by the missing
QueueStatusComplete event. false.skipQueues - true to skip queue initialization,
false to not skip.public void setManagerConnection(ManagerConnection eventConnection)
public void initialize()
throws ManagerCommunicationException
AsteriskServerinitialize in interface AsteriskServerManagerCommunicationException - if login failspublic ManagerConnection getManagerConnection()
AsteriskServer
Unlike the methods operating on the manager connection this method does
not implicitly initialize the connection. Thus you can use this method to
add custom ManagerEventListeners before the connection to the Asterisk server is
established. If you want to ensure that the connection is established
call AsteriskServer.initialize().
getManagerConnection in interface AsteriskServerpublic AsteriskChannel originate(OriginateAction originateAction) throws ManagerCommunicationException, NoSuchChannelException
AsteriskServeroriginate in interface AsteriskServeroriginateAction - the action that contains parameters for the
originateManagerCommunicationException - if the originate action cannot be
sent to AsteriskNoSuchChannelException - if the channel is not available on the
Asterisk server, for example because you used "SIP/1310" and
1310 is not a valid SIP user, the SIP channel module hasn't
been loaded or the SIP or IAX peer is not registered
currently.public AsteriskChannel originateToExtension(String channel, String context, String exten, int priority, long timeout) throws ManagerCommunicationException, NoSuchChannelException
AsteriskServeroriginateToExtension in interface AsteriskServerchannel - channel name to call, for example "SIP/1310".context - context to connect toexten - extension to connect topriority - priority to connect totimeout - how long to wait for the channel to be answered before its
considered to have failed (in ms)ManagerCommunicationException - if the originate action cannot be
sent to AsteriskNoSuchChannelException - if the channel is not available on the
Asterisk server, for example because you used "SIP/1310" and
1310 is not a valid SIP user, the SIP channel module hasn't
been loaded or the SIP or IAX peer is not registered
currently.public AsteriskChannel originateToExtension(String channel, String context, String exten, int priority, long timeout, CallerId callerId, Map<String,String> variables) throws ManagerCommunicationException, NoSuchChannelException
AsteriskServeroriginateToExtension in interface AsteriskServerchannel - channel name to call, for example "SIP/1310".context - context to connect toexten - extension to connect topriority - priority to connect totimeout - how long to wait for the channel to be answered before its
considered to have failed (in ms)callerId - callerId to use for the outgoing channel, may be
null.variables - channel variables to set, may be null.ManagerCommunicationException - if the originate action cannot be
sent to AsteriskNoSuchChannelException - if the channel is not available on the
Asterisk server, for example because you used "SIP/1310" and
1310 is not a valid SIP user, the SIP channel module hasn't
been loaded or the SIP or IAX peer is not registered
currently.public AsteriskChannel originateToApplication(String channel, String application, String data, long timeout) throws ManagerCommunicationException, NoSuchChannelException
AsteriskServeroriginateToApplication in interface AsteriskServerchannel - channel name to call, for example "SIP/1310".application - application to connect to, for example "MeetMe"data - data to pass to the application, for example "1000|d", may be
null.timeout - how long to wait for the channel to be answered before its
considered to have failed (in ms)ManagerCommunicationException - if the originate action cannot be
sent to AsteriskNoSuchChannelException - if the channel is not available on the
Asterisk server, for example because you used "SIP/1310" and
1310 is not a valid SIP user, the SIP channel module hasn't
been loaded or the SIP or IAX peer is not registered
currently.public AsteriskChannel originateToApplication(String channel, String application, String data, long timeout, CallerId callerId, Map<String,String> variables) throws ManagerCommunicationException, NoSuchChannelException
AsteriskServeroriginateToApplication in interface AsteriskServerchannel - channel name to call, for example "SIP/1310".application - application to connect to, for example "MeetMe"data - data to pass to the application, for example "1000|d", may be
null.timeout - how long to wait for the channel to be answered before its
considered to have failed (in ms)callerId - callerId to use for the outgoing channel, may be
null.variables - channel variables to set, may be null.ManagerCommunicationException - if the originate action cannot be
sent to AsteriskNoSuchChannelException - if the channel is not available on the
Asterisk server, for example because you used "SIP/1310" and
1310 is not a valid SIP user, the SIP channel module hasn't
been loaded or the SIP or IAX peer is not registered
currently.public void originateAsync(OriginateAction originateAction, OriginateCallback cb) throws ManagerCommunicationException
AsteriskServeroriginateAsync in interface AsteriskServeroriginateAction - the action that contains parameters for the
originatecb - callback to inform about the resultManagerCommunicationException - if the originate action cannot be
sent to Asteriskpublic void originateToApplicationAsync(String channel, String application, String data, long timeout, CallerId callerId, Map<String,String> variables, OriginateCallback cb) throws ManagerCommunicationException
AsteriskServeroriginateToApplicationAsync in interface AsteriskServerchannel - channel name to call, for example "SIP/1310".application - application to connect to, for example "MeetMe"data - data to pass to the application, for example "1000|d", may be
null.timeout - how long to wait for the channel to be answered before its
considered to have failed (in ms)callerId - callerId to use for the outgoing channel, may be
null.variables - channel variables to set, may be null.cb - callback to inform about the resultManagerCommunicationException - if the originate action cannot be
sent to Asteriskpublic void originateToApplicationAsync(String channel, String application, String data, long timeout, OriginateCallback cb) throws ManagerCommunicationException
AsteriskServeroriginateToApplicationAsync in interface AsteriskServerchannel - channel name to call, for example "SIP/1310".application - application to connect to, for example "MeetMe"data - data to pass to the application, for example "1000|d", may be
null.timeout - how long to wait for the channel to be answered before its
considered to have failed (in ms)cb - callback to inform about the resultManagerCommunicationException - if the originate action cannot be
sent to Asteriskpublic void originateToExtensionAsync(String channel, String context, String exten, int priority, long timeout, CallerId callerId, Map<String,String> variables, OriginateCallback cb) throws ManagerCommunicationException
AsteriskServeroriginateToExtensionAsync in interface AsteriskServerchannel - channel name to call, for example "SIP/1310".context - context to connect toexten - extension to connect topriority - priority to connect totimeout - how long to wait for the channel to be answered before its
considered to have failed (in ms)callerId - callerId to use for the outgoing channel, may be
null.variables - channel variables to set, may be null.cb - callback to inform about the resultManagerCommunicationException - if the originate action cannot be
sent to Asteriskpublic void originateToExtensionAsync(String channel, String context, String exten, int priority, long timeout, OriginateCallback cb) throws ManagerCommunicationException
AsteriskServeroriginateToExtensionAsync in interface AsteriskServerchannel - channel name to call, for example "SIP/1310".context - context to connect toexten - extension to connect topriority - priority to connect totimeout - how long to wait for the channel to be answered before its
considered to have failed (in ms)cb - callback to inform about the resultManagerCommunicationException - if the originate action cannot be
sent to Asteriskpublic Collection<AsteriskChannel> getChannels() throws ManagerCommunicationException
AsteriskServergetChannels in interface AsteriskServerManagerCommunicationException - if there is a problem communication
with Asteriskpublic AsteriskChannel getChannelByName(String name) throws ManagerCommunicationException
AsteriskServergetChannelByName in interface AsteriskServername - name of the channel to returnnull if there is
no such channel.ManagerCommunicationException - if there is a problem communication
with Asteriskpublic AsteriskChannel getChannelById(String id) throws ManagerCommunicationException
AsteriskServergetChannelById in interface AsteriskServerid - the unique id of the channel to returnnull if
there is no such channel.ManagerCommunicationException - if there is a problem communication
with Asteriskpublic Collection<MeetMeRoom> getMeetMeRooms() throws ManagerCommunicationException
AsteriskServergetMeetMeRooms in interface AsteriskServerManagerCommunicationException - if there is a problem communication
with Asteriskpublic MeetMeRoom getMeetMeRoom(String name) throws ManagerCommunicationException
AsteriskServerMeetMeRoom object is created.getMeetMeRoom in interface AsteriskServername - the number of the room to returnManagerCommunicationException - if there is a problem communication
with Asteriskpublic Collection<AsteriskQueue> getQueues() throws ManagerCommunicationException
AsteriskServergetQueues in interface AsteriskServerManagerCommunicationException - if there is a problem communication
with Asteriskpublic String getVersion() throws ManagerCommunicationException
AsteriskServergetVersion in interface AsteriskServerManagerCommunicationException - if the version cannot be retrieved
from Asteriskpublic int[] getVersion(String file) throws ManagerCommunicationException
AsteriskServergetVersion in interface AsteriskServerfile - the file for which to get the version like "app_meetme.c"null if that file
is not part of the Asterisk instance you are connected to (maybe
due to a module that provides it has not been loaded) or if you
are connected to an Astersion 1.0.xManagerCommunicationException - if the version cannot be retrieved
from Asteriskpublic String getGlobalVariable(String variable) throws ManagerCommunicationException
AsteriskServergetGlobalVariable in interface AsteriskServervariable - the name of the global variable to return.null if it is
not set.ManagerCommunicationException - if the get variable action cannot
be sent to Asterisk.public void setGlobalVariable(String variable, String value) throws ManagerCommunicationException
AsteriskServersetGlobalVariable in interface AsteriskServervariable - the name of the global variable to set.value - the value of the global variable to set.ManagerCommunicationException - if the set variable action cannot
be sent to Asterisk.public Collection<Voicemailbox> getVoicemailboxes() throws ManagerCommunicationException
AsteriskServergetVoicemailboxes in interface AsteriskServerManagerCommunicationException - if the voicemailboxes can't be
retrieved.public List<String> executeCliCommand(String command) throws ManagerCommunicationException
AsteriskServerexecuteCliCommand in interface AsteriskServercommand - the command to execute, for example "sip show peers".ManagerCommunicationException - if the command can't be executed.CommandActionpublic boolean isModuleLoaded(String module) throws ManagerCommunicationException
AsteriskServerAvailable since Asterisk 1.6
isModuleLoaded in interface AsteriskServermodule - name of the module to load (with out without the ".so"
extension).true if the module is currently loaded,
false otherwise.ManagerCommunicationException - if the module can't be checked.public ConfigFile getConfig(String filename) throws ManagerCommunicationException
AsteriskServergetConfig in interface AsteriskServerfilename - the filename, for example "voicemail.conf".ManagerCommunicationException - if the command can't be executed.public void reloadAllModules()
throws ManagerCommunicationException
AsteriskServerAvailable since Asterisk 1.6
reloadAllModules in interface AsteriskServerManagerCommunicationException - if the modules cannot be reloaded.public void reloadModule(String module) throws ManagerCommunicationException
AsteriskServerAvailable since Asterisk 1.6
reloadModule in interface AsteriskServermodule - name of the module to reload (including ".so" extension) or
subsystem name.ManagerCommunicationException - if the module cannot be reloaded.public void unloadModule(String module) throws ManagerCommunicationException
AsteriskServerAvailable since Asterisk 1.6
unloadModule in interface AsteriskServermodule - name of the module to unload (including ".so" extension) or
subsystem name.ManagerCommunicationException - if the module cannot be unloaded.public void loadModule(String module) throws ManagerCommunicationException
AsteriskServerAvailable since Asterisk 1.6
loadModule in interface AsteriskServermodule - name of the module to load (including ".so" extension) or
subsystem name.ManagerCommunicationException - if the module cannot be loaded.public void addAsteriskServerListener(AsteriskServerListener listener) throws ManagerCommunicationException
AsteriskServeraddAsteriskServerListener in interface AsteriskServerlistener - the listener to add.ManagerCommunicationException - if the server is not yet connected
and the connection or initialization fails.public void removeAsteriskServerListener(AsteriskServerListener listener)
AsteriskServerremoveAsteriskServerListener in interface AsteriskServerlistener - the listener to remove.public boolean isAsteriskServerListening(AsteriskServerListener listener)
AsteriskServerisAsteriskServerListening in interface AsteriskServerlistener - the listener to checkpublic void shutdown()
AsteriskServershutdown in interface AsteriskServerpublic Collection<AsteriskAgent> getAgents() throws ManagerCommunicationException
AsteriskServerAsteriskAgent)getAgents in interface AsteriskServerManagerCommunicationException - if there is a problem communication
with Asteriskpublic AsteriskQueue getQueueByName(String queueName)
AsteriskServergetQueueByName in interface AsteriskServerqueueName - Name of the queue to retrievepublic List<AsteriskQueue> getQueuesUpdatedAfter(Date date)
AsteriskServergetQueuesUpdatedAfter in interface AsteriskServerpublic void forceQueuesMonitor(boolean force)
AsteriskServerforceQueuesMonitor in interface AsteriskServerpublic boolean isQueuesMonitorForced()
AsteriskServerisQueuesMonitorForced in interface AsteriskServerpublic void addChainListener(ManagerEventListener chainListener)
AsteriskServeraddChainListener in interface AsteriskServerpublic void removeChainListener(ManagerEventListener chainListener)
AsteriskServerremoveChainListener in interface AsteriskServerCopyright © 2004–2024. All rights reserved.