Package 

Class TimeoutableRequest


  • 
    public abstract class TimeoutableRequest
    extends Request
                        

    A base class for requests that can be canceled or can time out.

    Not all messages can be cancelled. For example, Bluetooth LE operations, which rely on android.bluetooth.BluetoothGattCallback callbacks, cannot be cancelled. This is because the callback is called when the operation is completed, even if the request was cancelled. Receiving the callback is required before starting a new operation.

    • Method Summary

      Modifier and Type Method Description
      TimeoutableRequest setHandler(@Nullable() Handler handler) Sets the handler that will be used to invoke callbacks.
      TimeoutableRequest timeout(@IntRange(from = 0) long timeout) Sets the operation timeout.
      void cancel() Cancels the request.
      final void enqueue() Enqueues the request for asynchronous execution.
      final void enqueue(@IntRange(from = 0) long timeout) Enqueues the request for asynchronous execution.
      final void await() Synchronously waits until the request is done.
      final void await(@IntRange(from = 0) long timeout) Synchronously waits, for as most as the given number of milliseconds, until the requestis ready.
      final boolean isCancelled() Returns true if the request has been cancelled.
      • Methods inherited from class no.nordicsemi.android.ble.Request

        before, createBond, done, fail, invalid, newConnectionPriorityRequest, newDisableBatteryLevelNotificationsRequest, newDisableIndicationsRequest, newDisableNotificationsRequest, newEnableBatteryLevelNotificationsRequest, newEnableIndicationsRequest, newEnableNotificationsRequest, newMtuRequest, newReadBatteryLevelRequest, newReadPhyRequest, newReadRequest, newReadRequest, newReadRssiRequest, newRefreshCacheRequest, newSetPreferredPhyRequest, newSleepRequest, newWaitForIndicationRequest, newWaitForNotificationRequest, newWriteRequest, newWriteRequest, newWriteRequest, newWriteRequest, newWriteRequest, newWriteRequest, removeBond, setHandler, then
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • setHandler

        @NonNull() TimeoutableRequest setHandler(@Nullable() Handler handler)

        Sets the handler that will be used to invoke callbacks. By default, the handler set in BleManager will be used.

        If set to null, the callbacks will be invoked immediately on the BLE looper.

        Parameters:
        handler - The handler to invoke callbacks for this request.
      • timeout

        @NonNull() TimeoutableRequest timeout(@IntRange(from = 0) long timeout)

        Sets the operation timeout.When the timeout occurs, the request will fail with REASON_TIMEOUT.

        Parameters:
        timeout - the request timeout in milliseconds, 0 to disable timeout.
      • cancel

         void cancel()

        Cancels the request. The request will fail with REASON_CANCELLED,or will throw CancellationException if the thread is blocked using await.

        If the request has not been started yet, it will be skipped silently.

      • enqueue

         final void enqueue()

        Enqueues the request for asynchronous execution.

        Use timeout to set the maximum time the manager should wait until the deviceis ready. When the timeout occurs, the request will fail with REASON_TIMEOUT and the device will get disconnected.

      • enqueue

        @Deprecated() final void enqueue(@IntRange(from = 0) long timeout)

        Enqueues the request for asynchronous execution.

        When the timeout occurs, the request will fail with REASON_TIMEOUT and the device will get disconnected.

        Parameters:
        timeout - the request timeout in milliseconds, 0 to disable timeout.
      • await

         final void await()

        Synchronously waits until the request is done.

        Use timeout to set the maximum time the manager should wait until the requestis ready. When the timeout occurs, the InterruptedException will be thrown.

        Callbacks set using done and fail will be ignored.

        This method may not be called from the main (UI) thread.

      • await

        @Deprecated() final void await(@IntRange(from = 0) long timeout)

        Synchronously waits, for as most as the given number of milliseconds, until the requestis ready.

        When the timeout occurs, the InterruptedException will be thrown.

        Callbacks set using done and fail will be ignored.

        This method may not be called from the main (UI) thread.

        Parameters:
        timeout - optional timeout in milliseconds, 0 to disable timeout.
      • isCancelled

         final boolean isCancelled()

        Returns true if the request has been cancelled.