Class DynamicEntityDataSource

java.lang.Object
com.esri.arcgisruntime.realtime.DynamicEntityDataSource
All Implemented Interfaces:
RemoteResource, Loadable
Direct Known Subclasses:
ArcGISStreamService

public abstract class DynamicEntityDataSource extends Object implements Loadable, RemoteResource
A dynamic entity data source that streams observations to a client.

The DynamicEntityDataSource class is the base class for classes that stream dynamic entity data. The class provides methods and properties that allow:

  • maintenance of a persistent connection for streaming
  • control over the storage of observations in its local data cache
  • notification of received or purged observations
This class is used as the data source for a DynamicEntityLayer.
Since:
200.1.0
See Also:
  • Property Details

  • Constructor Details

    • DynamicEntityDataSource

      protected DynamicEntityDataSource()
      No argument constructor to avoid custom dynamic entity data sources having to define a no argument constructor.
      Since:
      200.2.0
  • Method Details

    • connectionErrorProperty

      public final ReadOnlyObjectProperty<ArcGISRuntimeException> connectionErrorProperty()
      The current network connection ArcGISRuntimeException.

      This property is null until an attempt to connect the data source is made. If a connection attempt succeeds, this property is set to null. If a connection fails, this property contains the platform-specific error.

      If maximumReconnectionAttemptsProperty() is greater than 0, this property will contain the exception that caused the data source to lose the connection.

      Returns:
      the connectionError property
      Since:
      200.1.0
      See Also:
    • getConnectionError

      public final ArcGISRuntimeException getConnectionError()
      Gets the value of the connectionError property.
      Property description:
      The current network connection ArcGISRuntimeException.

      This property is null until an attempt to connect the data source is made. If a connection attempt succeeds, this property is set to null. If a connection fails, this property contains the platform-specific error.

      If maximumReconnectionAttemptsProperty() is greater than 0, this property will contain the exception that caused the data source to lose the connection.

      Returns:
      the value of the connectionError property
      Since:
      200.1.0
      See Also:
    • connectionStatusProperty

      public final ReadOnlyObjectProperty<ConnectionStatus> connectionStatusProperty()
      The current network connection status of the DynamicEntityDataSource.

      This property contains the state of the connection throughout the lifetime of the data source. The initial value of this property is ConnectionStatus.DISCONNECTED.

      Returns:
      the connectionStatus property
      Since:
      200.1.0
      See Also:
    • getConnectionStatus

      public final ConnectionStatus getConnectionStatus()
      Gets the value of the connectionStatus property.
      Property description:
      The current network connection status of the DynamicEntityDataSource.

      This property contains the state of the connection throughout the lifetime of the data source. The initial value of this property is ConnectionStatus.DISCONNECTED.

      Returns:
      the value of the connectionStatus property
      Since:
      200.1.0
      See Also:
    • maximumReconnectionAttemptsProperty

      public final IntegerProperty maximumReconnectionAttemptsProperty()
      The maximum number of attempts to reconnect after a connection fails.

      This property informs the data source to attempt reconnection if a connection is lost. When a connection fails, the data source attempts to reconnect the specified number of times waiting reconnectionIntervalProperty() between attempts.

      If reconnection fails on the final attempt, connectionStatusProperty() is set to ConnectionStatus.FAILED and the connectionErrorProperty() is set to the platform specific connection error.

      The default value is 12. The first 2 connection attempts are made without waiting the specified DynamicEntityDataSource.reconnectionIntervalProperty() between attempts.

      Returns:
      the maximumReconnectionAttempts property
      Since:
      200.1.0
      See Also:
    • getMaximumReconnectionAttempts

      public final int getMaximumReconnectionAttempts()
      Gets the value of the maximumReconnectionAttempts property.
      Property description:
      The maximum number of attempts to reconnect after a connection fails.

      This property informs the data source to attempt reconnection if a connection is lost. When a connection fails, the data source attempts to reconnect the specified number of times waiting reconnectionIntervalProperty() between attempts.

      If reconnection fails on the final attempt, connectionStatusProperty() is set to ConnectionStatus.FAILED and the connectionErrorProperty() is set to the platform specific connection error.

      The default value is 12. The first 2 connection attempts are made without waiting the specified DynamicEntityDataSource.reconnectionIntervalProperty() between attempts.

      Returns:
      the value of the maximumReconnectionAttempts property
      Since:
      200.1.0
      See Also:
    • setMaximumReconnectionAttempts

      public final void setMaximumReconnectionAttempts(int maximumReconnectionAttempts)
      Sets the value of the maximumReconnectionAttempts property.
      Property description:
      The maximum number of attempts to reconnect after a connection fails.

      This property informs the data source to attempt reconnection if a connection is lost. When a connection fails, the data source attempts to reconnect the specified number of times waiting reconnectionIntervalProperty() between attempts.

      If reconnection fails on the final attempt, connectionStatusProperty() is set to ConnectionStatus.FAILED and the connectionErrorProperty() is set to the platform specific connection error.

      The default value is 12. The first 2 connection attempts are made without waiting the specified DynamicEntityDataSource.reconnectionIntervalProperty() between attempts.

      Parameters:
      maximumReconnectionAttempts - the value for the maximumReconnectionAttempts property
      Since:
      200.1.0
      See Also:
    • purgeOptionsProperty

      public final ReadOnlyObjectProperty<DynamicEntityDataSourcePurgeOptions> purgeOptionsProperty()
      A DynamicEntityDataSourcePurgeOptions that defines when observations are purged from the local data cache.

      Data received from the DynamicEntityDataSource is stored in memory on the client and can grow quickly depending on the number of dynamic entities and frequency of updates. If purge options are not set appropriately, a data source may store too many observations in its local data cache and cause performance and memory issues for the application. Use the property to control app data storage for the local cache.

      This property must be set before loading the data source and cannot be changed once the data source is loaded.

      By default, purge options are set to remove observations from the data cache when a maximum limit of 100,000 observations is reached.

      Note that you can clear all observations from the cache using purgeAllAsync(). This clears all data from the local data cache, but does not disconnect from the stream. Dynamic entities and observations will continue to be added to the local data cache as they come from the stream.

      Returns:
      the purgeOptions property
      Since:
      200.1.0
      See Also:
    • getPurgeOptions

      public final DynamicEntityDataSourcePurgeOptions getPurgeOptions()
      Gets the value of the purgeOptions property.
      Property description:
      A DynamicEntityDataSourcePurgeOptions that defines when observations are purged from the local data cache.

      Data received from the DynamicEntityDataSource is stored in memory on the client and can grow quickly depending on the number of dynamic entities and frequency of updates. If purge options are not set appropriately, a data source may store too many observations in its local data cache and cause performance and memory issues for the application. Use the property to control app data storage for the local cache.

      This property must be set before loading the data source and cannot be changed once the data source is loaded.

      By default, purge options are set to remove observations from the data cache when a maximum limit of 100,000 observations is reached.

      Note that you can clear all observations from the cache using purgeAllAsync(). This clears all data from the local data cache, but does not disconnect from the stream. Dynamic entities and observations will continue to be added to the local data cache as they come from the stream.

      Returns:
      the value of the purgeOptions property
      Since:
      200.1.0
      See Also:
    • reconnectionIntervalProperty

      public final DoubleProperty reconnectionIntervalProperty()
      The time (in seconds) to wait between attempts to reconnect.

      This property sets the amount of time delay between reconnection attempts after a connection fails. The default value is 10 seconds.

      Returns:
      the reconnectionInterval property
      Since:
      200.1.0
      See Also:
    • getReconnectionInterval

      public final double getReconnectionInterval()
      Gets the value of the reconnectionInterval property.
      Property description:
      The time (in seconds) to wait between attempts to reconnect.

      This property sets the amount of time delay between reconnection attempts after a connection fails. The default value is 10 seconds.

      Returns:
      the value of the reconnectionInterval property
      Since:
      200.1.0
      See Also:
    • setReconnectionInterval

      public final void setReconnectionInterval(double reconnectionInterval)
      Sets the value of the reconnectionInterval property.
      Property description:
      The time (in seconds) to wait between attempts to reconnect.

      This property sets the amount of time delay between reconnection attempts after a connection fails. The default value is 10 seconds.

      Parameters:
      reconnectionInterval - the value for the reconnectionInterval property
      Since:
      200.1.0
      See Also:
    • addObservation

      protected final void addObservation(Geometry geometry, Map<String,Object> attributes)
      Adds or updates the newly-received observation data in the data source store.
      Parameters:
      geometry - geometry of the associated observation. Only data sources that send point geometries are supported. Can be null.
      attributes - the attributes of the associated observation. Can be null.
      Since:
      200.2.0
    • connectAsync

      public final ListenableFuture<Void> connectAsync()
      Connects to a service that provides dynamic entity observations.

      Data does not start streaming from the dynamic entity data source until it's loaded and connected. Once the connection is successfully established, data begins to flow from the stream.

      Use this method to explicitly connect to the data source. This call loads the data source if it is not already loaded and then initiates a persistent connection to the service that provides the observation stream. When this method completes, the connectionStatusProperty() is set to connected or failed.

      Note that a data source connection is initiated implicitly if the data source is contained by a DynamicEntityLayer and added to a map or scene.

      Returns:
      a ListenableFuture that has no return value
      Since:
      200.1.0
    • deleteEntityAsync

      public final ListenableFuture<Void> deleteEntityAsync(String entityId)
      Deletes the dynamic entity identified by the id value from the data source store.
      Parameters:
      entityId - the value of the unique id field identifying an entity. For example, a track id field value for track-aware data or an object id value for discrete data.
      Returns:
      a ListenableFuture that has no return value
      Throws:
      NullPointerException - if entityId is null
      Since:
      200.2.0
    • disconnectAsync

      public final ListenableFuture<Void> disconnectAsync()
      Closes the connection to a service.

      Use this method to explicitly disconnect from a data source. When this method completes, the connectionStatusProperty() is set to disconnected or failed.

      If this method is called when a data source has a DynamicEntityDataSource.ConnectionStatusProperty() of connecting, the current connection attempt is cancelled.

      Returns:
      a ListenableFuture that has no return value
      Since:
      200.1.0
    • onConnectAsync

      protected abstract CompletableFuture<Void> onConnectAsync()
      Handles the connection process of a data source.

      Override this method to perform operations that initiate a connection and start the flow of data from an underlying data source. For instance, operations like connecting a websocket, opening a source file, or starting a polling timer are all operations that may be performed in this method.

      This method is called by the ArcGIS Maps SDK when the connection is required. This can be due to an explicit call to connectAsync() or called implicitly when a layer that contains the data source needs to be rendered.

      The completable future should complete exceptionally if the connect operation fails. The exception is passed back to the data source and is available in the connectionErrorProperty() property.

      If disconnectAsync() is called when a connectAsync() is in progress the future returned here will be cancelled by completing exceptionally with a CancellationException. The implementation of onConnectAsync() should check for cancellation when the future completes and take any necessary action, for example, releasing resources.

      Returns:
      a CompletableFuture that handles the connection process of a data source
      Since:
      200.2.0
    • onDisconnectAsync

      protected abstract CompletableFuture<Void> onDisconnectAsync()
      Handles the disconnection process of a data source.

      Override this method to perform operations that stop the flow of data from an underlying data source.

      If a connectAsync() is in progress when this method is called the future returned by onConnectAsync() will be cancelled by completing exceptionally.

      Returns:
      a CompletableFuture that handles the disconnection process of a data source
      Since:
      200.2.0
    • onLoadAsync

      protected abstract CompletableFuture<DynamicEntityDataSourceInfo> onLoadAsync()
      Handles the loading process of a data source and returns DynamicEntityDataSourceInfo.

      Override this method to populate and return a DynamicEntityDataSourceInfo object. This object defines the schema and metadata used by the internal data cache of the DynamicEntityDataSource. If the returned DynamicEntityDataSourceInfo object does not contain all required values, the data source will fail to load and will not be usable.

      This method is called by the ArcGIS Maps SDK when loading is required. This can be due to an explicit call to load the data source using Loadable.loadAsync() or called implicitly when a layer that contains the data source needs to be rendered.

      The completable future should complete exceptionally if the load operation fails. The exception is passed back to the data source and is available in the loadErrorProperty() property.

      Returns:
      a CompletableFuture that returns a DynamicEntityDataSourceInfo
      Since:
      200.2.0
    • purgeAllAsync

      public final ListenableFuture<Void> purgeAllAsync()
      Removes all dynamic entity observations from the in-memory data cache as well as from the map or scene.

      Sometimes, a large number of dynamic entity observations can crowd the display and make information hard to interpret. Use this method to clear (purge) all dynamic entity observations to remove stale information and limit the amount of memory consumed. This does not disconnect you from the service, so new dynamic entity observations continue to display as they become available.

      The following DynamicEntityDataSource events will not be raised due to a call to this method:

      Returns:
      a ListenableFuture that has no return value
      Since:
      200.1.0
    • setConnectionFailed

      protected final void setConnectionFailed(Throwable error, boolean reconnect)
      Handles the error when the connection fails and may attempt to reconnect.

      Use this method when an established connection has failed. Pass the exception that caused the connection to fail and a flag that indicates whether to attempt reconnection.

      This method should only be used on an established connection, or when connectionStatusProperty() is ConnectionStatus.CONNECTED. It should not be used when attempting to create an initial connection during onConnectAsync().

      Parameters:
      error - the error that was encountered during connection failure
      reconnect - indicates whether reconnection should be attempted after failure
      Throws:
      NullPointerException - if error is null
      Since:
      200.2.0
    • addDynamicEntityObservationPurgedListener

      public final void addDynamicEntityObservationPurgedListener(DynamicEntityDataSource.DynamicEntityObservationPurgedListener listener)
      Registers the given DynamicEntityObservationPurgedListener to be called when an update is received from the DynamicEntityDataSource.

      Adding this listener on the UI thread will cause it to be invoked on the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.

      Parameters:
      listener - the listener to register
      Throws:
      NullPointerException - if the DynamicEntityObservationPurgedListener is null
      Since:
      200.1.0
      See Also:
    • removeDynamicEntityObservationPurgedListener

      public final boolean removeDynamicEntityObservationPurgedListener(DynamicEntityDataSource.DynamicEntityObservationPurgedListener listener)
      Unregisters the given DynamicEntityObservationPurgedListener that was previously added using addDynamicEntityObservationPurgedListener(DynamicEntityObservationPurgedListener).
      Parameters:
      listener - the listener to unregister
      Returns:
      true if the listener was successfully removed; false otherwise
      Since:
      200.1.0
    • addDynamicEntityObservationReceivedListener

      public final void addDynamicEntityObservationReceivedListener(DynamicEntityDataSource.DynamicEntityObservationReceivedListener listener)
      Registers the given listener to be called when an update is received from the DynamicEntityDataSource.

      Adding this listener on the UI thread will cause it to be invoked on the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.

      Parameters:
      listener - the listener to register
      Throws:
      IllegalArgumentException - if the listener is null
      Since:
      200.1.0
      See Also:
    • removeDynamicEntityObservationReceivedListener

      public final boolean removeDynamicEntityObservationReceivedListener(DynamicEntityDataSource.DynamicEntityObservationReceivedListener listener)
      Unregisters the given listener that was previously added using addDynamicEntityObservationReceivedListener(DynamicEntityObservationReceivedListener).
      Parameters:
      listener - the listener to unregister
      Returns:
      true if the listener was successfully removed; false otherwise
      Since:
      200.1.0
    • addDynamicEntityPurgedListener

      public final void addDynamicEntityPurgedListener(DynamicEntityDataSource.DynamicEntityPurgedListener listener)
      Registers the given DynamicEntityPurgedListener to be called when an update is received from the DynamicEntityDataSource.

      Adding this listener on the UI thread will cause it to be invoked on the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.

      Parameters:
      listener - the listener to register
      Throws:
      NullPointerException - if the DynamicEntityPurgedListener is null
      Since:
      200.1.0
      See Also:
    • removeDynamicEntityPurgedListener

      public final boolean removeDynamicEntityPurgedListener(DynamicEntityDataSource.DynamicEntityPurgedListener listener)
      Unregisters the given DynamicEntityPurgedListener that was previously added using addDynamicEntityPurgedListener(DynamicEntityPurgedListener).
      Parameters:
      listener - the listener to unregister
      Returns:
      true if the listener was successfully removed; false otherwise
      Since:
      200.1.0
    • addDynamicEntityReceivedListener

      public final void addDynamicEntityReceivedListener(DynamicEntityDataSource.DynamicEntityReceivedListener listener)
      Registers the given DynamicEntityReceivedListener to be called when an update is received from the DynamicEntityDataSource.

      Adding this listener on the UI thread will cause it to be invoked on the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.

      Parameters:
      listener - the listener to register
      Throws:
      NullPointerException - if the DynamicEntityReceivedListener is null
      Since:
      200.1.0
      See Also:
    • removeDynamicEntityReceivedListener

      public final boolean removeDynamicEntityReceivedListener(DynamicEntityDataSource.DynamicEntityReceivedListener listener)
      Unregisters the given DynamicEntityReceivedListener that was previously added using addDynamicEntityReceivedListener(DynamicEntityReceivedListener).
      Parameters:
      listener - the listener to unregister
      Returns:
      true if the listener was successfully removed; false otherwise
      Since:
      200.1.0
    • getLoadError

      public final ArcGISRuntimeException getLoadError()
      Gets the value of the loadError property.
      Specified by:
      getLoadError in interface Loadable
      Property description:
      Returns:
      the value of the loadError property
      See Also:
    • getLoadStatus

      public final LoadStatus getLoadStatus()
      Gets the value of the loadStatus property.
      Specified by:
      getLoadStatus in interface Loadable
      Property description:
      Returns:
      the value of the loadStatus property
      See Also:
    • cancelLoad

      public final void cancelLoad()
      Description copied from interface: Loadable
      Cancels loading metadata for the object.

      Cancels loading the metadata if the object is loading, and always invokes the done loading listener.

      A load operation that is in progress (LoadStatus.LOADING state) can be cancelled by calling this method and the resource will transition from LoadStatus.LOADING to LoadStatus.FAILED_TO_LOAD state. If the load operation was successfully cancelled, a CancellationException will be returned from Loadable.getLoadError().

      Cancellation should be used carefully because all enqueued done loading listeners for that resource instance will get invoked with an error stating that the operation was cancelled. Thus, one component in the application can cancel the load operation initiated by other components.

      This method does nothing if the resource is not in LoadStatus.LOADING state.

      Specified by:
      cancelLoad in interface Loadable
    • loadAsync

      public final void loadAsync()
      Description copied from interface: Loadable
      Loads the metadata of the loadable resource asynchronously.

      The load status changes from LoadStatus.NOT_LOADED to LoadStatus.LOADING. A listener can be added via Loadable.addDoneLoadingListener(java.lang.Runnable) that is invoked upon completion of the asynchronous load operation.

      If the load operation completes successfully, the load status will be LoadStatus.LOADED, which means the resource has loaded its metadata.

      If the load operation failed, the load status will be LoadStatus.FAILED_TO_LOAD and the error can be retrieved by calling Loadable.getLoadError().

      This method can be called concurrently and repeatedly, but only one attempt is ever made to perform the load operation. If a load operation is already in progress (LoadStatus.LOADING state) when loadAsync is called, it simply piggy-backs on the outstanding operation and the done loading listener added to the loadable resource is enqueued to be invoked when that operation completes. If the operation has already completed (LoadStatus.LOADED or LoadStatus.FAILED_TO_LOAD state) when loadAsync is called, the done loading listener is immediately invoked when added to the loadable resource.

      If a loadable resource has failed to load, calling loadAsync on it subsequently will not change its state. The done loading listener will be invoked immediately when added to the loadable resource. In order to retry loading the resource, Loadable.retryLoadAsync() needs to be used.

      A load operation that is in progress (LoadStatus.LOADING state) can be cancelled by calling Loadable.cancelLoad().

      Specified by:
      loadAsync in interface Loadable
    • retryLoadAsync

      public final void retryLoadAsync()
      Description copied from interface: Loadable
      Loads or retries loading metadata for the object asynchronously.

      Will retry loading the metadata if the object's load status is LoadStatus.FAILED_TO_LOAD. Will load the object if it is not loaded. Will not retry to load the object if the object is loaded.

      For more details on the load process see Loadable.loadAsync().

      Specified by:
      retryLoadAsync in interface Loadable
    • addDoneLoadingListener

      public final void addDoneLoadingListener(Runnable runner)
      Description copied from interface: Loadable
      Adds a listener to the loadable resource that is invoked when loading has completed.

      The listener may be added at any point, whether the loadable resource has already completed loading or not.

      • For resources that are not loaded when the listener is added (LoadStatus is NOT_LOADED or LOADING): When the resource completes loading, the listener will be invoked on the UI thread if it is added from the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.
      • For resources that are already loaded when the listener is added (LoadStatus is LOADED or FAILED_TO_LOAD): The listener will be called immediately, on the current thread.

      Alternatively, to be notified when there is any change in the load status, add a listener to the Loadable.loadStatusProperty() instead.

      Specified by:
      addDoneLoadingListener in interface Loadable
      Parameters:
      runner - a Runnable that is invoked upon completion of the load operation
    • removeDoneLoadingListener

      public final boolean removeDoneLoadingListener(Runnable runner)
      Description copied from interface: Loadable
      Removes a done loading listener from the loadable resource.
      Specified by:
      removeDoneLoadingListener in interface Loadable
      Parameters:
      runner - the listener to be removed
      Returns:
      true if the listener was removed, otherwise false
    • addLoadStatusChangedListener

      public final void addLoadStatusChangedListener(LoadStatusChangedListener listener)
      Description copied from interface: Loadable
      Adds a LoadStatusChangedListener to the loadable resource that is invoked whenever the load status changes.

      Adding this listener on the UI thread will cause it to be invoked on the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.

      The listener will not be called if added to a loadable resource that has already completed loading. To be notified when a loadable resource has completed loading, including if the resource is already loaded when the listener is added, use the Loadable.addDoneLoadingListener(Runnable) method.

      Specified by:
      addLoadStatusChangedListener in interface Loadable
      Parameters:
      listener - the LoadStatusChangedListener to be added
    • removeLoadStatusChangedListener

      public final boolean removeLoadStatusChangedListener(LoadStatusChangedListener listener)
      Description copied from interface: Loadable
      Removes a LoadStatusChangedListener from the loadable resource.
      Specified by:
      removeLoadStatusChangedListener in interface Loadable
      Parameters:
      listener - the LoadStatusChangedListener to be removed
      Returns:
      true if the listener was removed, otherwise false
    • loadStatusProperty

      public final ReadOnlyObjectProperty<LoadStatus> loadStatusProperty()
      Description copied from interface: Loadable
      The load status.
      Specified by:
      loadStatusProperty in interface Loadable
      Returns:
      the loadStatus property
      See Also:
    • loadErrorProperty

      public final ReadOnlyObjectProperty<ArcGISRuntimeException> loadErrorProperty()
      Description copied from interface: Loadable
      The load error.
      Specified by:
      loadErrorProperty in interface Loadable
      Returns:
      the loadError property
      See Also:
    • getCredential

      public final Credential getCredential()
      Description copied from interface: RemoteResource
      Gets the Credential that is set on the network-enabled resource.

      Only applicable if the resource is secured.

      Specified by:
      getCredential in interface RemoteResource
      Returns:
      the Credential, or null if there is none
    • setCredential

      public final void setCredential(Credential credential)
      Description copied from interface: RemoteResource
      Sets a Credential to be used by the network-enabled resource in the event of an authentication challenge. The default credential is null.

      Only applicable if the resource is secured.

      Specified by:
      setCredential in interface RemoteResource
      Parameters:
      credential - the Credential to be used for authentication
    • setRequestConfiguration

      public final void setRequestConfiguration(RequestConfiguration requestConfiguration)
      Description copied from interface: RemoteResource
      Sets the RequestConfiguration used to modify the parameters of network requests made by this RemoteResource. If not set, the global RequestConfiguration will be used (see RequestConfiguration.getGlobalRequestConfiguration()).
      Specified by:
      setRequestConfiguration in interface RemoteResource
      Parameters:
      requestConfiguration - the RequestConfiguration used to modify network requests
    • getRequestConfiguration

      public final RequestConfiguration getRequestConfiguration()
      Description copied from interface: RemoteResource
      Gets the RequestConfiguration used to modify the parameters of network requests made by this RemoteResource.
      Specified by:
      getRequestConfiguration in interface RemoteResource
      Returns:
      the RequestConfiguration used to modify network requests