|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.orderlysoftware.orderlycalls.base.Service com.orderlysoftware.orderlycalls.asterisk.manager.ManagerClient
public class ManagerClient
This class represents the TCP/IP connection to the Asterisk Manager system.
The class contains an internal queue to ensure that only one action is
processed at a time.
Calls to the Send method will therefore block until a response is received.
The class also distributes Events to registered ManagerEventListener
objects.
NOTE: If you require more than one Manager connection to a particular Asterisk server,
you should use a proxy to prevent collisions.
Field Summary | |
---|---|
static java.util.logging.Logger |
log
|
Constructor Summary | |
---|---|
ManagerClient(ManagerSettings settings)
Creates a ManagerClient but does not start it. |
Method Summary | |
---|---|
ManagerResponse |
absoluteTimeout(java.lang.String channel,
int timeout)
Hangup a channel after a certain time. |
void |
addManagerEventListener(ManagerEventListener mel)
If you're interested in Asterisk Manager Events, create a class that implements ManagerEventListener, and add it here. |
ManagerResponse |
changeMonitor(java.lang.String channel,
java.lang.String file)
Change monitoring filename of a channel. |
void |
clean()
|
ManagerResponse |
command(java.lang.String command,
java.lang.String actionId)
Execute Command Run a CLI command. |
void |
connect(java.lang.String host,
int port)
Connects to the Aterisk system by TCP/IP, but does not log in. |
void |
connectAndLogin(ManagerSettings settings)
Connects to Asterisk over TCP/IP and logs in. |
ManagerResponse |
events(java.lang.String eventMask)
Contol Event Flow |
ManagerResponse |
extensionState(java.lang.String exten,
java.lang.String context,
java.lang.String actionId)
Check Extension Status |
long |
getActionTimeout()
How long this manager will wait for a response before proceding to the next action. |
static ManagerClient |
getByInetAddress(java.net.InetAddress address)
Gets a ManagerClient connected to a particular remote IP address. |
java.util.ArrayList |
getEventListeners()
Gets all attached ManagerEventListeners. |
static ManagerClient |
getInstance(ManagerSettings settings)
Gets a ManagerClient instance, or creates one if none can be found. |
static ManagerClient |
getInstance(ManagerSettings settings,
boolean reuse)
Gets a connected ManagerClient instance. |
static ManagerClient |
getInstance(java.lang.String name)
Gets a connected ManagerClient instance, or null if none can be found. |
static java.lang.String |
getShortChannelName(java.lang.String fullName)
Utility method for converting a full channel name (e.g. |
java.lang.String |
getVar(java.lang.String channel,
java.lang.String variable,
java.lang.String actionId)
Gets a Channel Variable |
ManagerResponse |
hangUp(java.lang.String channel)
Hangup Channel |
ManagerResponse |
iaxPeers()
Lists all IAX Peers. |
void |
init()
Initialises this ManagerClient based on the settings object stored. |
boolean |
isRunning()
Determines whether this service is active. |
ManagerResponse |
listCommands()
List available manager commands |
ManagerResponse |
login(java.lang.String username,
java.lang.String password)
Logs in to Asterisk Manager. |
ManagerResponse |
logOff()
Logoff Manager |
ManagerResponse |
logout()
Synonym for logOff() |
ManagerResponse |
mailboxCount(java.lang.String mailbox,
java.lang.String actionId)
Check Mailbox Message Count. |
ManagerResponse |
mailboxStatus(java.lang.String mailbox,
java.lang.String actionId)
Check Mailbox |
static void |
main(java.lang.String[] args)
For running ManagerClient as a stand-alone appliction. |
ManagerResponse |
monitor(java.lang.String channel,
java.lang.String file,
java.lang.String format,
boolean mix)
Monitor a channel |
ManagerResponse |
originate(java.lang.String channel,
java.lang.String exten,
java.lang.String context,
java.lang.String priority,
java.lang.String application,
java.lang.String data,
long timeout,
java.lang.String callerID,
java.lang.String variable,
java.lang.String account,
boolean async)
Originate Call |
ManagerResponse |
parkedCalls()
Lists parked calls. |
ManagerResponse |
ping()
Pings Asterisk. |
ManagerResponse |
queueAdd(java.lang.String queue,
java.lang.String interfaceId,
java.lang.String penalty,
boolean isPaused,
java.lang.String actionId)
Add interface to queue. |
ManagerResponse |
queueRemove(java.lang.String queue,
java.lang.String interfaceId)
Remove interface from queue. |
ManagerResponse |
queues()
Shows queue status information for all queues. |
ManagerResponse |
queueStatus(java.lang.String actionId)
Causes a series of queue status events to be fired. |
ManagerResponse |
redirect(java.lang.String channel,
java.lang.String extraChannel,
java.lang.String exten,
java.lang.String context,
java.lang.String priority)
Redirects channel(s) to a different extension. |
void |
removeManagerEventListener(ManagerEventListener mel)
Call this method to remove event listeners. |
void |
run()
The message queue thread. |
void |
safeClean()
Closes any connections without throwing an exception. |
ManagerResponse |
send(ManagerAction action)
Once you've got a connected ManagerClient object, call this method to send Actions to the Asterisk system. |
void |
setActionTimeout(long actionTimeout)
Sets how long this manager will wait for a response before |
ManagerResponse |
setCDRUserField(java.lang.String userField,
java.lang.String channel,
java.lang.String append)
Sets the CDR user field. |
ManagerResponse |
setVar(java.lang.String channel,
java.lang.String variable,
java.lang.String value)
Set a local channel variable. |
void |
shutdown()
Gracefully stops the Client. |
ManagerResponse |
status(java.lang.String channel)
|
ManagerResponse |
status(java.lang.String channel,
java.lang.String actionId)
Fires channel status events. |
ManagerResponse |
stopMonitor(java.lang.String channel)
Stop monitoring (recording) a channel. |
ManagerResponse |
zapDialOffHook(java.lang.String zapChannel,
java.lang.String number)
Dial over Zap channel while offhook |
ManagerResponse |
zapDNDOff(java.lang.String zapChannel)
Toggle Zap channel Do Not Disturb status OFF |
ManagerResponse |
zapDNDOn(java.lang.String zapChannel)
Toggle Zap channel Do Not Disturb status ON |
ManagerResponse |
zapHangUp(java.lang.String zapChannel)
Hangup Zap Channel |
ManagerResponse |
zapShowChannels(java.lang.String actionId)
Show Zap Channels |
ManagerResponse |
zapTransfer(java.lang.String zapChannel)
Transfer Zap Channel |
Methods inherited from class com.orderlysoftware.orderlycalls.base.Service |
---|
getExecutorService, getInstance, getInstance, getInstance, getInstanceByName, getLogName, getName, getSettings, setExecutorService, shutdownAll |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.util.logging.Logger log
Constructor Detail |
---|
public ManagerClient(ManagerSettings settings)
settings
- Method Detail |
---|
public static ManagerClient getInstance(ManagerSettings settings)
settings
- The settings to use.
public static ManagerClient getInstance(ManagerSettings settings, boolean reuse)
settings
- The settings to use.reuse
- Whether or not to reuse an existing instance, if found.
public boolean isRunning()
Service
isRunning
in class Service
public static ManagerClient getInstance(java.lang.String name)
name
- the Name of the Settings object for the service.
public void init()
All ManagerEventListeners listed in the settings are created and added.
init
in class Service
public static ManagerClient getByInetAddress(java.net.InetAddress address)
address
- The address of the Asterisk server.
public java.util.ArrayList getEventListeners()
public long getActionTimeout()
public void setActionTimeout(long actionTimeout)
actionTimeout
- The actionTimeout to set.public void addManagerEventListener(ManagerEventListener mel)
mel
- the event listener to add.public void removeManagerEventListener(ManagerEventListener mel)
mel
- The event listener to remove.public void run()
Started automatically by the connect() method, which is called by init().
Also pings the server once every minute to keep the connection alive.
run
in interface java.lang.Runnable
public void safeClean()
Called by shutdown().
public static java.lang.String getShortChannelName(java.lang.String fullName)
SIP/12345-ab37
)
to its shortened version (e.g. SIP/12345
).
Useful for originating calls.
fullName
- The extended name of the channel.
public ManagerResponse send(ManagerAction action)
action
- The action to execute
public void connect(java.lang.String host, int port)
public void connectAndLogin(ManagerSettings settings)
settings
- public void clean() throws java.io.IOException
java.io.IOException
safeClean()
public void shutdown()
shutdown
in class Service
public ManagerResponse absoluteTimeout(java.lang.String channel, int timeout)
Privilege: call
Acknowledges with 'Timeout Set' message
channel
- Channel name to hanguptimeout
- Maximum duration of the call (sec)
public ManagerResponse changeMonitor(java.lang.String channel, java.lang.String file)
The 'ChangeMonitor' action may be used to change the file started by a previous 'Monitor' action.
Privilege: call
channel
- Required. Used to specify the channel to record.file
- Required. Is the new name of the file created in the monitor
spool directory.
public ManagerResponse command(java.lang.String command, java.lang.String actionId)
Privilege: command
command
- Required: Asterisk CLI command to runactionId
- Optional: Action id for message matching.
public ManagerResponse events(java.lang.String eventMask)
Enable/Disable sending of events to this manager client.
Warning: This manager action does not always return a response. Specifically, if the "on" command is sent when events are already being sent, no response is returned.
This will cause the message queue to hang for until actionTimeout milliseconds have passed (default 10 seconds).
There is no known workaround.
Privilege: none
eventMask
- "on" if all events should be sent, "off" if no events should
be sent, "system,call,log" to select which flags events should
have to be sent.
-
public ManagerResponse extensionState(java.lang.String exten, java.lang.String context, java.lang.String actionId)
Report the extension state for given extension. If the extension has a hint, will use devicestate to check the status of the device connected to the extension.
Will return an "Extension Status" message.
exten
- Required: Extension to check state oncontext
- Required: Context for extensionactionId
- Optional: ID for this transaction
public java.lang.String getVar(java.lang.String channel, java.lang.String variable, java.lang.String actionId)
Get the value of a local channel variable.
Privilege: call
channel
- Required: Channel to read variable fromvariable
- Required: Variable nameactionId
- Optional: Action id for message matching.
public ManagerResponse hangUp(java.lang.String channel)
Privilege: call
channel
- The channel name to be hungup
public ManagerResponse iaxPeers()
Warning: If no peers are registered to the asterisk server, no response is returned. This will cause the message queue to hang for timeout (default 10 seconds)
Privilege: None
public ManagerResponse listCommands()
Privilege: none
public ManagerResponse login(java.lang.String username, java.lang.String password) throws java.io.IOException
This method is called for you by connectAndLogin(ManagerSettings settings).
settings
-
java.io.IOException
public ManagerResponse logOff()
Logoff this manager session
Privilege: none
public ManagerResponse logout()
public ManagerResponse mailboxCount(java.lang.String mailbox, java.lang.String actionId)
Checks a voicemail account for new messages.
Privilege: call
mailbox
- Required: Full mailbox ID (e.g. mailbox@vm-context)actionId
- Optional: ActionID for message matching.
public ManagerResponse mailboxStatus(java.lang.String mailbox, java.lang.String actionId)
Checks a voicemail account for status.
Privilege: call
mailbox
- Required: Full mailbox ID (e.g. mailbox@vm-context)actionId
- Optional: ActionID for message matching.
public ManagerResponse monitor(java.lang.String channel, java.lang.String file, java.lang.String format, boolean mix)
The 'Monitor' action may be used to record the audio on a specified channel.
Privilege: call
channel
- Required: Used to specify the channel to record.file
- Optional: Is the name of the file created in the monitor spool
directory. Defaults to the same name as the channel (with
slashes replaced with dashes).format
- Optional. Is the audio recording format. Defaults to "wav".
"gsm" and "mp3" are also valid values.mix
- mixes the input and output channels together after the
recording is finished to produce a single file if true.
public ManagerResponse originate(java.lang.String channel, java.lang.String exten, java.lang.String context, java.lang.String priority, java.lang.String application, java.lang.String data, long timeout, java.lang.String callerID, java.lang.String variable, java.lang.String account, boolean async)
Generates an outgoing call to a Extension/Context/Priority or Application/Data
Privilege: call
channel
- Required: Channel name to callexten
- Optional: Extension to use (requires 'Context' and 'Priority')context
- Optional: Context to use (requires 'Exten' and 'Priority')priority
- Optional: Priority to use (requires 'Exten' and 'Context')application
- Optional: Application to usedata
- Optional: Data to use (requires 'Application')timeout
- Optional: How long to wait for call to be answered (in ms)callerID
- Optional: Caller ID to be set on the outgoing channelvariable
- Optional: Channel variable to set (use
"VAR1=value1|VAR2=value2" to set multiple variables)account
- Optional: Account codeasync
- Optional: Uses fast origination when true.
public ManagerResponse parkedCalls()
Privilege: none
Note: The actual Parked Call data is sent in an event immediately following this call, and is not returned in the response. To capture the data, you must add a ManagerEventListener.
public ManagerResponse ping()
A 'Ping' action will ellicit a 'Pong' response. Used to keep the manager connection open.
ManagerClient objects automatically Ping the server once per minute in order to maintain connections.
java.io.IOException
public ManagerResponse queueAdd(java.lang.String queue, java.lang.String interfaceId, java.lang.String penalty, boolean isPaused, java.lang.String actionId)
Privilege: agent
queue
- Required: Existing queue to add member.interfaceId
- Required: Member interface (sip/1000, zap/1-1, etc) .penalty
- Optional: Entries with higher penalties are considered last.isPaused
- If true member is initially paused.actionId
- Optional: Action ID for message tracking.
public ManagerResponse queueRemove(java.lang.String queue, java.lang.String interfaceId)
Privilege: agent
queue
- interfaceId
-
public ManagerResponse queues()
Privilege: none
public ManagerResponse queueStatus(java.lang.String actionId)
You must add a ManagerEventListener
in order to receive these events.
actionId
- Optional: parameter for message tracking
public ManagerResponse redirect(java.lang.String channel, java.lang.String extraChannel, java.lang.String exten, java.lang.String context, java.lang.String priority)
channel
- Required: the channel to redirectextraChannel
- Optional: An additional channel to redirect (e.g. 2-party call
to meeting room)exten
- The target extensioncontext
- The target contextpriority
- The target priority
public ManagerResponse setCDRUserField(java.lang.String userField, java.lang.String channel, java.lang.String append)
userField
- channel
- append
-
public ManagerResponse setVar(java.lang.String channel, java.lang.String variable, java.lang.String value)
All parameters are required.
Privilege: call
channel
- channel to set variable forvariable
- variable namevalue
- variable value
public ManagerResponse status(java.lang.String channel, java.lang.String actionId)
You will need to add a ManagerEventListener to capture them.
Privilege: call
channel
- Required: the channel to show the status.actionId
- Optional: message identifier for tracking.
public ManagerResponse status(java.lang.String channel)
public ManagerResponse stopMonitor(java.lang.String channel)
Privilege: call
channel
- Required: The channel to cease recording.
public ManagerResponse zapDialOffHook(java.lang.String zapChannel, java.lang.String number)
zapChannel
- number
-
public ManagerResponse zapDNDOff(java.lang.String zapChannel)
zapChannel
-
public ManagerResponse zapDNDOn(java.lang.String zapChannel)
zapChannel
-
public ManagerResponse zapHangUp(java.lang.String zapChannel)
zapChannel
-
public ManagerResponse zapShowChannels(java.lang.String actionId)
actionId
- Optional: message id for tracking.
public ManagerResponse zapTransfer(java.lang.String zapChannel)
zapChannel
-
public static void main(java.lang.String[] args)
If you also require AGI functionality, you should run an AGIServer instead, and have your AGIProcessor objects call ManagerClient.getManagerClient()
Usage: java com.orderlysoftware.orderlycalls.manager.ManagerClientUsername and Password are mandatory, all other arguments optional.[username] [password]
args
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |