Package ch.loway.oss.ari4java
Class ARI
- java.lang.Object
-
- ch.loway.oss.ari4java.ARI
-
public class ARI extends java.lang.Object
ARI factory and helper class
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ARI.ClassFactory
This interface is used to go from an interface to its concrete implementation.
-
Constructor Summary
Constructors Constructor Description ARI()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ActionApplications
applications()
Gets a ready to use Applications Action.ActionAsterisk
asterisk()
Gets a ready to use Asterisk Action.ActionBridges
bridges()
Gets a ready to use Bridges Action.static ARI
build(java.lang.String url, java.lang.String app, java.lang.String user, java.lang.String pass, AriVersion version)
Minimal helper to build an instance of ARIstatic ARI
build(java.lang.String url, java.lang.String app, java.lang.String user, java.lang.String pass, AriVersion version, boolean testConnection)
Helper to build an instance of ARI.ActionChannels
channels()
Gets a ready to use Channels Action.void
cleanup()
This operation is the opposite of a build() - to be called in the final clause where the ARI object is built.void
closeAction(java.lang.Object action)
Close an action object that is open for WebSocket interactionActionDeviceStates
deviceStates()
Gets a ready to use Device States Action.ActionEndpoints
endpoints()
Gets a ready to use Endpoints Action.ActionEvents
events()
Gets a ready to use Events Action.void
eventsCallback(AriCallback<Message> callback)
Create the events Websocket with the provided callbackvoid
eventsCallback(AriCallback<Message> callback, boolean subscribeAll)
Create the events Websocket with the provided callback<T> T
getActionImpl(java.lang.Class<T> klazz)
Get the implementation for a given action interfacejava.lang.String
getAppName()
Return the current application name.java.lang.String
getBuildVersion()
Gets the package information an<T> T
getModelImpl(java.lang.Class<T> klazz)
Get the implementation for a given model interfacestatic java.lang.String
getUID()
Generates a pseudo-random ID like "a4j.ZH6IA.IXEX0.TUIE8".AriVersion
getVersion()
Returns the current ARI versionMessageQueue
getWebsocketQueue()
Gets an instance of a message queueMessageQueue
getWebsocketQueue(boolean subscribeAll)
In order to avoid multi-threading for users, you can get a MessageQueue object and poll on it for new messages.boolean
isWsConnected()
Is the Websocket is connectedActionMailboxes
mailboxes()
Gets a ready to use Mailboxes Action.ActionPlaybacks
playbacks()
Gets a ready to use Playbacks Action.ActionRecordings
recordings()
Gets a ready to use Recordings Action.void
setAppName(java.lang.String s)
Sets the application name.void
setHttpClient(HttpClient httpClient)
Sets the clientvoid
setVersion(AriVersion version)
Sets the Versionvoid
setWsClient(WsClient wsClient)
Sets the clientstatic void
sleep(long ms)
Wrapper of the Thread.sleep() to avoid exception.ActionSounds
sounds()
Gets a ready to use Sounds Action.Application
subscribe(EventSource m)
Subscribes to an event source.void
unsubscribe(EventSource m)
Unsubscribes from an event source.void
unsubscribeAll()
Unsubscribes from all known subscriptions.
-
-
-
Method Detail
-
setHttpClient
public void setHttpClient(HttpClient httpClient)
Sets the client- Parameters:
httpClient
- the http client
-
setWsClient
public void setWsClient(WsClient wsClient)
Sets the client- Parameters:
wsClient
- the ws client
-
setVersion
public void setVersion(AriVersion version)
Sets the Version- Parameters:
version
- the version
-
getVersion
public AriVersion getVersion()
Returns the current ARI version- Returns:
- the version
- Throws:
ARIRuntimeException
- when version null
-
getActionImpl
public <T> T getActionImpl(java.lang.Class<T> klazz) throws ARIException
Get the implementation for a given action interface- Type Parameters:
T
- interface class- Parameters:
klazz
- the required action interface class- Returns:
- An implementation instance
- Throws:
ARIException
- when error
-
getModelImpl
public <T> T getModelImpl(java.lang.Class<T> klazz) throws ARIException
Get the implementation for a given model interface- Type Parameters:
T
- interface class- Parameters:
klazz
- the required model interface class- Returns:
- An implementation instance
- Throws:
ARIException
- when error
-
closeAction
public void closeAction(java.lang.Object action) throws ARIException
Close an action object that is open for WebSocket interaction- Parameters:
action
- the action object- Throws:
ARIException
- when error
-
build
public static ARI build(java.lang.String url, java.lang.String app, java.lang.String user, java.lang.String pass, AriVersion version) throws ARIException
Minimal helper to build an instance of ARI- Parameters:
url
- urlapp
- appuser
- userpass
- The passwordversion
- The required version- Returns:
- instance
- Throws:
ARIException
- exception- See Also:
build(String, String, String, String, AriVersion, boolean)
-
build
public static ARI build(java.lang.String url, java.lang.String app, java.lang.String user, java.lang.String pass, AriVersion version, boolean testConnection) throws ARIException
Helper to build an instance of ARI. If the version is set as IM_FEELING_LUCKY the AriFactory will determine the version by 1st connecting to the server and requesting the resources.json to extract the version number.- Parameters:
url
- The URL of the Asterisk web server, e.g. http://10.10.5.8:8088/ (defined in http.conf)app
- The appuser
- The user name (defined in ari.conf)pass
- The password (defined in ari.conf)version
- The required versiontestConnection
- Test the connection details by executing the ping operation- Returns:
- an instance
- Throws:
ARIException
- If the url is invalid, or the version of ARI is not supported.
-
setAppName
public void setAppName(java.lang.String s)
Sets the application name.- Parameters:
s
- app name
-
getAppName
public java.lang.String getAppName()
Return the current application name.- Returns:
- the appName
-
cleanup
public void cleanup()
This operation is the opposite of a build() - to be called in the final clause where the ARI object is built.In any case, it is good practice to have a way to deallocate stuff like the websocket or any circular reference.
-
eventsCallback
public void eventsCallback(AriCallback<Message> callback) throws ARIException
Create the events Websocket with the provided callback- Parameters:
callback
- AriCallback- Throws:
ARIException
- when error
-
eventsCallback
public void eventsCallback(AriCallback<Message> callback, boolean subscribeAll) throws ARIException
Create the events Websocket with the provided callback- Parameters:
callback
- AriCallbacksubscribeAll
- subscribe to all- Throws:
ARIException
- when error
-
getWebsocketQueue
public MessageQueue getWebsocketQueue() throws ARIException
Gets an instance of a message queue- Returns:
- MessageQueue
- Throws:
ARIException
- when error
-
getWebsocketQueue
public MessageQueue getWebsocketQueue(boolean subscribeAll) throws ARIException
In order to avoid multi-threading for users, you can get a MessageQueue object and poll on it for new messages. This makes sure you don't really need to synchonize or be worried by threading issues- Parameters:
subscribeAll
- subscribe to all events- Returns:
- The MQ connected to your websocket.
- Throws:
ARIException
- when error
-
applications
public ActionApplications applications()
Gets a ready to use Applications Action.- Returns:
- ActionApplications
-
asterisk
public ActionAsterisk asterisk()
Gets a ready to use Asterisk Action.- Returns:
- ActionAsterisk
-
bridges
public ActionBridges bridges()
Gets a ready to use Bridges Action.- Returns:
- ActionBridges
-
channels
public ActionChannels channels()
Gets a ready to use Channels Action.- Returns:
- ActionChannels
-
deviceStates
public ActionDeviceStates deviceStates()
Gets a ready to use Device States Action.- Returns:
- ActionDeviceStates
-
endpoints
public ActionEndpoints endpoints()
Gets a ready to use Endpoints Action.- Returns:
- ActionEndpoints
-
events
public ActionEvents events()
Gets a ready to use Events Action.- Returns:
- ActionEvents
-
mailboxes
public ActionMailboxes mailboxes()
Gets a ready to use Mailboxes Action.- Returns:
- ActionMailboxes
-
playbacks
public ActionPlaybacks playbacks()
Gets a ready to use Playbacks Action.- Returns:
- ActionPlaybacks
-
recordings
public ActionRecordings recordings()
Gets a ready to use Recordings Action.- Returns:
- ActionRecordings
-
sounds
public ActionSounds sounds()
Gets a ready to use Sounds Action.- Returns:
- ActionSounds
-
sleep
public static void sleep(long ms)
Wrapper of the Thread.sleep() to avoid exception.- Parameters:
ms
- how long is it going to sleep.
-
getUID
public static java.lang.String getUID()
Generates a pseudo-random ID like "a4j.ZH6IA.IXEX0.TUIE8".- Returns:
- the UID
-
subscribe
public Application subscribe(EventSource m) throws RestException
Subscribes to an event source.- Parameters:
m
- event- Returns:
- the Application object
- Throws:
RestException
- when error
-
unsubscribe
public void unsubscribe(EventSource m) throws RestException
Unsubscribes from an event source.- Parameters:
m
- event- Throws:
RestException
- when error
-
unsubscribeAll
public void unsubscribeAll() throws RestException
Unsubscribes from all known subscriptions.- Throws:
RestException
- when error
-
getBuildVersion
public java.lang.String getBuildVersion()
Gets the package information an- Returns:
- String
-
isWsConnected
public boolean isWsConnected()
Is the Websocket is connected- Returns:
- true if connected
-
-