public class Data extends Object
You should not need to create an instance of this class manually.
Use the WVA class to manage all interactions with the WVA.
| Modifier and Type | Field and Description |
|---|---|
static String |
SUB_SUFFIX
Suffix used to create the default short names for subscriptions.
|
| Constructor and Description |
|---|
Data(HttpClient client) |
| Modifier and Type | Method and Description |
|---|---|
void |
createAlarm(String endpoint,
AlarmType type,
double threshold,
int seconds,
WvaCallback<Void> cb)
Alarm are similar to subscriptions, but they do not occur at regular
intervals.
|
void |
deleteAlarm(String endpoint,
AlarmType type,
boolean deleteCallbacks,
WvaCallback<Void> cb)
Removes the alarm attached to the given endpoint.
|
void |
fetchVehicleData(String endpoint)
Asynchronously queries the WVA for the newest data at the given endpoint
and caches the result.
|
void |
fetchVehicleData(String endpoint,
WvaCallback<VehicleDataResponse> cb)
Asynchronously queries the WVA for the newest data at the given endpoint
and caches the result.
|
void |
fetchVehicleDataEndpoints(WvaCallback<Set<String>> onInitialized)
Initializes the cache of vehicle data endpoints for the vehicle.
|
VehicleDataResponse |
getCachedVehicleData(String endpoint)
Synchronously returns the last response received by this library for a
given endpoint.
|
Set<String> |
getVehicleDataEndpoints() |
void |
notifyListeners(VehicleDataEvent e)
Triggers the
listener associated
with e's AbstractEvent.getEndpoint() endpoint name} (if there are any), and then
the "catch-all" listener (if any). |
void |
removeAllListeners()
Removes all listeners
setVehicleDataListener(String, VehicleDataListener)
with all endpoint names, as well as the
"catch-all" listener, if any. |
void |
removeVehicleDataListener(String endpoint)
Removes any
VehicleDataListener that has been set to be
invoked on new vehicle data pertaining to the given endpoint. |
void |
setVehicleDataListener(String endpoint,
VehicleDataListener listener)
Sets the
VehicleDataListener to be invoked when a new vehicle data event with the
given endpoint name arrives via the event channel. |
void |
setVehicleDataListener(VehicleDataListener listener)
Sets the
VehicleDataListener to be invoked when any vehicle data arrives
via the event channel. |
void |
subscribe(String endpoint,
int seconds,
WvaCallback<Void> cb)
Subscribe to the given vehicle data endpoint on the WVA.
|
void |
unsubscribe(String endpoint,
boolean deleteCallbacks,
WvaCallback<Void> cb)
Ends the periodic updating of the given endpoint.
|
void |
updateCachedVehicleData(String uri,
VehicleDataResponse response)
Updates the cached value of an endpoint, and also calls
notifyListeners(VehicleDataEvent) with a new Event constructed
from uri and response. |
void |
updateCachedVehicleData(VehicleDataEvent e)
Updates the cached value of an endpoint, and also calls
notifyListeners(VehicleDataEvent) with e. |
public static final String SUB_SUFFIX
"EngineSpeed" becomes "EngineSpeed~sub".public Data(HttpClient client)
public void fetchVehicleDataEndpoints(WvaCallback<Set<String>> onInitialized)
public Set<String> getVehicleDataEndpoints()
public void notifyListeners(VehicleDataEvent e)
listener associated
with e's AbstractEvent.getEndpoint() endpoint name} (if there are any), and then
the "catch-all" listener (if any).e - the event to be used to trigger the aforementioned listenerspublic void removeAllListeners()
setVehicleDataListener(String, VehicleDataListener)
with all endpoint names, as well as the
"catch-all" listener, if any.
This only removes the VehicleDataListener objects from this Data's internal map. It does not remove any subscriptions or alarms from
the WVA device itself.
public void updateCachedVehicleData(VehicleDataEvent e)
notifyListeners(VehicleDataEvent) with e.
It is convenient for testing when no WVA and/or TCP connection is
available.e - a VehicleDataEvent objectpublic void updateCachedVehicleData(String uri, VehicleDataResponse response)
notifyListeners(VehicleDataEvent) with a new Event constructed
from uri and response.
It is convenient for testing when no WVA and/or TCP connection is
available.uri - the web service URI whose data is being updatedresponse - the data from the WVApublic void setVehicleDataListener(VehicleDataListener listener)
VehicleDataListener to be invoked when any vehicle data arrives
via the event channel.
To unset this listener, simply call again with null.
listener - the listener to be invoked with all event channel vehicle datasetVehicleDataListener(String, VehicleDataListener)public void setVehicleDataListener(String endpoint, VehicleDataListener listener)
VehicleDataListener to be invoked when a new vehicle data event with the
given endpoint name arrives via the event channel.
If you have configured both a listener for a given endpoint ("EngineSpeed", for instance),
and the catch-all listener (using
setVehicleDataListener(VehicleDataListener), then the listener set using this method
will be invoked first.
endpoint - the endpoint to associate with the listenerlistener - the listener to be invoked with matching event channel vehicle dataremoveVehicleDataListener(String)public void removeVehicleDataListener(String endpoint)
VehicleDataListener that has been set to be
invoked on new vehicle data pertaining to the given endpoint.endpoint - the endpoint whose listener is to be removedsetVehicleDataListener(String, com.digi.wva.async.VehicleDataListener)public VehicleDataResponse getCachedVehicleData(String endpoint)
endpoint - the name of the vehicle data endpoint to look atpublic void fetchVehicleData(String endpoint, WvaCallback<VehicleDataResponse> cb)
Note that this is a relatively resource-intensive request and intended to be an ad-hoc operation. Instead of using fetchVehicleData() in a loop to query endpoints, create subscriptions to receive new information as it arrives.
endpoint - the name of the vehicle data endpoint to querycb - the callback to handle the responsepublic void fetchVehicleData(String endpoint)
Note that this is a relatively resource-intensive request and intended to be an ad-hoc operation. Instead of using fetchVehicleData() in a loop to query endpoints, create subscriptions to receive new information as it arrives.
This method calls fetchVehicleData(String, WvaCallback) with a null
callback.
endpoint - the name of the vehicle data endpoint to querypublic void subscribe(String endpoint, int seconds, WvaCallback<Void> cb) throws JSONException
See setVehicleDataListener(String, VehicleDataListener) for information on
configuring a callback to be invoked each time subscription data arrives for the given
endpoint.
When a subscription is created for an endpoint, that endpoint will automatically update at regular intervals. This is the preferred method of receiving vehicle data from the WVA device because it does not have to create an HTTP connection for every piece of data received.
endpoint - The vehicle data endpoint name to subscribe toseconds - The interval of time between updatescb - callback to give feedback on whether the subscription creation succeeds or notJSONException - If an error occurs while creating the requestpublic void unsubscribe(String endpoint, boolean deleteCallbacks, WvaCallback<Void> cb)
This method will only delete a subscription created by the WVA Android library
(or one with a name matching <endpoint>~sub).
endpoint - the name of the vehicle data endpoint to unsubscribe fromdeleteCallbacks - whether to dissociate any VehicleDataListeners
(held internally) from this endpointcb - callback to give feedback on whether the unsubscribe call succeeds or notpublic void createAlarm(String endpoint, AlarmType type, double threshold, int seconds, WvaCallback<Void> cb) throws JSONException
setVehicleDataListener(String, VehicleDataListener) sets the listener invoked
when new alarm events come in through the event channel. In your
VehicleDataListener, use the getType() method
on the event to determine whether the data is from a subscription or an alarm.
endpoint - the name of the vehicle data endpoint to alarm ontype - the type of alarm to create. One endpoint can't have two
alarms of the same typethreshold - changes meaning depending on AlarmTypeseconds - the minimum number of seconds before two alarms of the same
type will be generated (for instance, only send an alarm for speeding
once in a five-minute period)cb - Executed when the HTTP response is received with the
short_name of the alarmJSONExceptionpublic void deleteAlarm(String endpoint, AlarmType type, boolean deleteCallbacks, WvaCallback<Void> cb)
This method will only delete an Alarm created by the WVA Android library
(or one with a name matching <endpoint>~<type>).
endpoint - the name of the vehicle data endpoint to remove an alarm fromtype - the type of alarm to deletedeleteCallbacks - whether to dissociate any VehicleDataListeners
(held internally) from this alarmcb - callback to give feedback on whether the alarm deletion call succeeds or not