Class ARI


  • public class ARI
    extends java.lang.Object
    ARI factory and helper class
    • Constructor Detail

      • ARI

        public ARI()
    • 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,
                                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 app
        user - The user name (defined in ari.conf)
        pass - The password (defined in ari.conf)
        version - The required version
        testConnection - 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 - AriCallback
        subscribeAll - subscribe to all
        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
      • 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