LockingProcess (API Reference)
Class LockingProcess
LockingProcess helps to detect situations when cache is locked with another process and
attempt to create instance of SDKNativeEngine fails with error
InstantiationErrorCode.FAILED_TO_LOCK_CACHE_FOLDER.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voiddestroyLockingProcess(android.content.Context context, SDKOptions sdkOptions, long maxTimeoutInMilliseconds) Checks if cache folder is locked.static voiddestroyLockingProcess(SDKOptions sdkOptions, long maxTimeoutInMilliseconds) Deprecated.static IntegergetLockingProcessId(android.content.Context context, SDKOptions options) Gets the process ID (PID) that currently locks the map cache or the persistent map storage.static IntegergetLockingProcessId(SDKOptions options) Deprecated.Will be removed in v4.27.0, usegetLockingProcessId(android.content.Context, SDKOptions)instead.
-
Method Details
-
getLockingProcessId
Deprecated.Will be removed in v4.27.0, use
getLockingProcessId(android.content.Context, SDKOptions)instead.Gets the process ID (PID) that currently locks the map cache or the persistent map storage. Returns
null, when no lock is active. Usually, a lock is not happening on the current process. The PID of the current process can be checked withandroid.os.Process#myPid(). The PID can be used to kill or to send a signal to the process with the related functions:android.os.Process#killProcess(int)andandroid.os.Process#sendSignal(int,int). Note that the PID might belong to the current app process, so it is recommended to check this before a process is killed as otherwise you will kill your own app process. Alternatively, call the convenient functiondestroyLockingProcess(android.content.Context, SDKOptions, long).If a PID is available it means that there is a lock on either the cache or the persistant map storage and that the HERE SDK will be non-functional until the locking process is killed. In such a case, consider to kill the locking process.
Note: The Operation is not atomic and may return a PID for a process which is already destroyed or the file might be locked by another thread or process after this function returned
null.- Parameters:
options-The options which are supposed to be used for new instance of the engine.
- Returns:
Process ID if the cache or the persistent map directory is locked and a process ID was successfully read.
-
getLockingProcessId
@Nullable public static Integer getLockingProcessId(@NonNull android.content.Context context, @NonNull SDKOptions options) Gets the process ID (PID) that currently locks the map cache or the persistent map storage. Returns
null, when no lock is active. Usually, a lock is not happening on the current process. The PID of the current process can be checked withandroid.os.Process#myPid(). The PID can be used to kill or to send a signal to the process with the related functions:android.os.Process#killProcess(int)andandroid.os.Process#sendSignal(int,int). Note that the PID might belong to the current app process, so it is recommended to check this before a process is killed as otherwise you will kill your own app process. Alternatively, call the convenient functiondestroyLockingProcess(android.content.Context, SDKOptions, long).If a PID is available it means that there is a lock on either the cache or the persistant map storage and that the HERE SDK will be non-functional until the locking process is killed. In such a case, consider to kill the locking process.
Note: The Operation is not atomic and may return a PID for a process which is already destroyed or the file might be locked by another thread or process after this function returned
null.- Parameters:
context-The Android context
options-The options which are supposed to be used for new instance of the engine.
- Returns:
Process ID if the cache or the persistent map directory is locked and a process ID was successfully read.
-
destroyLockingProcess
@Deprecated public static void destroyLockingProcess(@NonNull SDKOptions sdkOptions, long maxTimeoutInMilliseconds) Deprecated.Will be removed in v4.27.0, use
destroyLockingProcess(android.content.Context, SDKOptions, long)instead.Checks if cache folder is locked. Does nothing if cache is not locked or locked by current process. If cache is locked by a different process then the HERE SDK makes a few attempts to kill the locking application during the specified timeout. If it fails to kill the application, it attempts to remove the cache at
SDKOptions.cachePath. This function can be used before creating a SDKNativeEngine, i.e.SDKOptions options = new SDKOptions(...); LockingProcess.destroyLockingProcess(options, 300); SDKNativeEngine engine = new SDKNativeEngine(options);- Parameters:
sdkOptions-The options which are supposed to be used for a new instance of the engine.
maxTimeoutInMilliseconds-The maximum timeout in milliseconds. Recommended value is 300 - 500 milliseconds. If 0 or a negative value is passed then it makes only one attempt to kill the locking process (if any) and waits 30 milliseconds before exit because the system may spend a small amount of time to perform the operation.
-
destroyLockingProcess
public static void destroyLockingProcess(@NonNull android.content.Context context, @NonNull SDKOptions sdkOptions, long maxTimeoutInMilliseconds) Checks if cache folder is locked. Does nothing if cache is not locked or locked by current process. If cache is locked by a different process then the HERE SDK makes a few attempts to kill the locking application during the specified timeout. If it fails to kill the application, it attempts to remove the cache at
SDKOptions.cachePath. This function can be used before creating a SDKNativeEngine, i.e.SDKOptions options = new SDKOptions(...); LockingProcess.destroyLockingProcess(context, options, 300); SDKNativeEngine engine = new SDKNativeEngine(options);- Parameters:
context-The Android context
sdkOptions-The options which are supposed to be used for a new instance of the engine.
maxTimeoutInMilliseconds-The maximum timeout in milliseconds. Recommended value is 300 - 500 milliseconds. If 0 or a negative value is passed then it makes only one attempt to kill the locking process (if any) and waits 30 milliseconds before exit because the system may spend a small amount of time to perform the operation.
-
destroyLockingProcess(android.content.Context, SDKOptions, long)instead.