Ametista Engine

The AmetistaEngine class is the core component of the Ametista system. It collects performance data and tracks issues to send to your backend instance for analysis

Author

N7ghtm4r3 - Tecknobit

Constructors

Link copied to clipboard
private constructor(platform: EngineConfiguration.Platform)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
private lateinit var applicationId: String

applicationId -> the identifier of the current application managed by the Engine

Link copied to clipboard
private var appVersion: String?

appVersion -> the current application version managed by the Engine

Link copied to clipboard

configurationLoaded -> whether the configuration has been loaded correctly

Link copied to clipboard
private val configurationMutex: Mutex

configurationMutex -> the mutex used to wait the configuration loaded before execute any operation

Link copied to clipboard
private var debugMode: Boolean

debugMode -> whether the Engine must send the requests but the server must not collect as real, this is the use-case of a not-production environment

Link copied to clipboard
private val deviceInfo: DeviceInfo

deviceInfo -> the current device information

Link copied to clipboard
private lateinit var host: String

host -> the host address where send the stats and performance data collected

Link copied to clipboard
private val ktorClient: HttpClient

ktorClient -> the HTTP client used to send the stats and the performance data

Link copied to clipboard
private var loggingEnabled: Boolean

loggingEnabled -> whether the logging is enabled

Link copied to clipboard
Link copied to clipboard
private val requestsMutex: Mutex

requestsMutex -> the mutex used to synchronize the requests to avoid the interleaving between each request

Link copied to clipboard
private lateinit var serverSecret: String

serverSecret -> the server secret value used as authentication method to validate the requests of the Engine

Functions

Link copied to clipboard

Method to check the validity of the configuration loaded

Link copied to clipboard

Method to connect the platform where the application is currently running.

Link copied to clipboard

Method to execute an action after the configuration has been loaded. The configurationMutex synchronize the access locking it waiting the configuration loading

Link copied to clipboard
private suspend fun execRequest(response: HttpResponse)

Method to execute the request

Link copied to clipboard
fun fireUp(configData: ByteArray, loggingEnabled: Boolean = false, debugMode: Boolean)
fun fireUp(configPath: String, loggingEnabled: Boolean = false, debugMode: Boolean)

Method to initialize the Engine with the configuration data and the flags available

Link copied to clipboard
private fun formatHostForAndroid()

Method to format the host value in the correct localhost value address for the Android emulators with the ANDROID_LOCALHOST_VALUE

Link copied to clipboard
private fun getAppVersion(configuration: EngineConfiguration): String?

Method to get from the engine configuration the application version, this method check first if the version is specific for the current platform where the application is running, if not found will be used the generic one

Link copied to clipboard

Method to check whether the configuration is correctly loaded

Link copied to clipboard
private fun isValidHost(): Boolean

Method to check whether the host value is correctly formatted

Link copied to clipboard
private fun loadConfiguration(configData: ByteArray)

Method to load the configuration serializing the data in the EngineConfiguration data class and initializing the host, serverSecret, applicationId and appVersion instances

Link copied to clipboard
private fun notifyAppLaunch()

Method to notify the application launch and send the related value to the server.

Link copied to clipboard
fun notifyIssue(issue: String)

Method to send the crash report of an issue occurred during the runtime of the application

Link copied to clipboard

Method to request the count of a network request sent by the application

Link copied to clipboard
private fun sendRequest(method: HttpMethod, endpoint: String = "", parameters: Map<String, Any> = emptyMap(), payload: JsonObject? = null)

Method to send a request

Link copied to clipboard
private fun setLogging(enabled: Boolean)

Method to set the logging

Link copied to clipboard

Method to throw an error if the configuration is not valid, if the error is related to the appVersion will be instead used a specific message