public class AsyncClient extends Object
ApiClient apiClient = new ApiClient(restEndpoint); ApiClient.GetInfoResponse response = apiClient.getInfo(); String apiKey = response.result.appConfig.pusher.appKey; String eventChannel = response.result.appConfig.pusher.eventChannel; AsyncClient asyncClient = new AsyncClient(apiKey, eventChannel); asyncClient.setEventListener(vehicle, new AsyncClient.EventListener() { @Override public void eventReceived(ApiClient.Event event) { if ("gpsFix".equals(event.eventType)) { System.out.println("gpsFix event received"); System.out.println(" latitude = " + event.fix.latitude); System.out.println(" longitude = " + event.fix.longitude); } } }); asyncClient.connect(); System.out.println("Connected. Waiting for event notifications..."); Thread.sleep(Long.MAX_VALUE); asyncClient.disconnect();
Modifier and Type | Class and Description |
---|---|
static interface |
AsyncClient.EventListener
Interface used to notify your code about received events.
|
Constructor and Description |
---|
AsyncClient(String pusherApiKey,
String pusherEventChannel)
Creates an instance with information that can be provided by an administrator of the TethysDash service.
|
Modifier and Type | Method and Description |
---|---|
void |
connect()
Connects to the server and starts notifying registered listeners.
|
void |
disconnect()
Call this when you are no longer interested in getting notifications.
|
void |
setEventListener(String vehicleName,
AsyncClient.EventListener eventListener)
Sets the event listener for a particular vehicle or for all vehicles.
|
public AsyncClient(String pusherApiKey, String pusherEventChannel)
pusherApiKey
- API key of the associated Pusher application.pusherEventChannel
- Name of the channel to listen to.public void setEventListener(String vehicleName, AsyncClient.EventListener eventListener)
vehicleName
- Name of specific vehicle, or null for all vehicles.
A call to this method overwrites any previous call
with the same value for this parameter.
In other words, there's at most an EventListener per vehicle
(or for all vehicles if you pass null here).eventListener
- The listenerpublic void connect()
public void disconnect()
Copyright © 2017 MBARI. All Rights Reserved.