use of org.jivesoftware.smackx.geoloc.GeoLocationManager in project Smack by igniterealtime.
the class GeolocationIntegrationTest method publishAndWait.
/**
* Publish data using PEP, and block until the server has echoed the publication back to the publishing user.
*
* @param geoManager The GeoLocationManager instance for the connection that is expected to publish data.
* @param discoManager The ServiceDiscoveryManager instance for the connection that is expected to publish data.
* @param data The data to be published.
*
* @throws Exception if the test fails
*/
public void publishAndWait(GeoLocationManager geoManager, ServiceDiscoveryManager discoManager, GeoLocation data) throws Exception {
final SimpleResultSyncPoint publicationEchoReceived = new SimpleResultSyncPoint();
final PepEventListener<GeoLocation> publicationEchoListener = (jid, geoLocation, id, message) -> {
if (geoLocation.equals(data)) {
publicationEchoReceived.signal();
}
};
try {
registerListenerAndWait(geoManager, discoManager, publicationEchoListener);
geoManager.addGeoLocationListener(publicationEchoListener);
geoManager.publishGeoLocation(data);
} finally {
geoManager.removeGeoLocationListener(publicationEchoListener);
}
}
use of org.jivesoftware.smackx.geoloc.GeoLocationManager in project Smack by igniterealtime.
the class GeolocationIntegrationTest method registerListenerAndWait.
/**
* Registers a listener for GeoLocation data. This implicitly publishes a CAPS update to include a notification
* filter for the geolocation node. This method blocks until the server has indicated that this update has been
* received.
*
* @param geoManager The GeoLocationManager instance for the connection that is expected to receive data.
* @param discoManager The ServiceDiscoveryManager instance for the connection that is expected to publish data.
* @param listener A listener instance for GeoLocation data that is to be registered.
*
* @throws Exception if the test fails
*/
public void registerListenerAndWait(GeoLocationManager geoManager, ServiceDiscoveryManager discoManager, PepEventListener<GeoLocation> listener) throws Exception {
final SimpleResultSyncPoint notificationFilterReceived = new SimpleResultSyncPoint();
final EntityCapabilitiesChangedListener notificationFilterReceivedListener = info -> {
if (info.containsFeature(GeoLocationManager.GEOLOCATION_NODE + "+notify")) {
notificationFilterReceived.signal();
}
};
discoManager.addEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
try {
geoManager.addGeoLocationListener(listener);
notificationFilterReceived.waitForResult(timeout);
} finally {
discoManager.removeEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
}
}
Aggregations