use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.
the class IoTDiscoveryManager method findRegistry.
/**
* Try to find an XMPP IoT registry.
*
* @return the JID of a Thing Registry if one could be found, <code>null</code> otherwise.
* @throws InterruptedException if the calling thread was interrupted.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NoResponseException if there was no response from the remote entity.
* @see <a href="http://xmpp.org/extensions/xep-0347.html#findingregistry">XEP-0347 § 3.5 Finding Thing Registry</a>
*/
public Jid findRegistry() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (preconfiguredRegistry != null) {
return preconfiguredRegistry;
}
final XMPPConnection connection = connection();
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
List<DiscoverInfo> discoverInfos = sdm.findServicesDiscoverInfo(Constants.IOT_DISCOVERY_NAMESPACE, true, true);
if (!discoverInfos.isEmpty()) {
return discoverInfos.get(0).getFrom();
}
return null;
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.
the class IoTProvisioningManager method findProvisioningServerComponent.
/**
* Try to find a provisioning server component.
*
* @return the XMPP address of the provisioning server component if one was found.
* @throws NoResponseException if there was no response from the remote entity.
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
* @see <a href="http://xmpp.org/extensions/xep-0324.html#servercomponent">XEP-0324 § 3.1.2 Provisioning Server as a server component</a>
*/
public DomainBareJid findProvisioningServerComponent() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
final XMPPConnection connection = connection();
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
List<DiscoverInfo> discoverInfos = sdm.findServicesDiscoverInfo(Constants.IOT_PROVISIONING_NAMESPACE, true, true);
if (discoverInfos.isEmpty()) {
return null;
}
Jid jid = discoverInfos.get(0).getFrom();
assert jid.isDomainBareJid();
return jid.asDomainBareJid();
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.
the class MoodIntegrationTest method registerListenerAndWait.
/**
* Registers a listener for User Tune data. This implicitly publishes a CAPS update to include a notification
* filter for the mood node. This method blocks until the server has indicated that this update has been
* received.
*
* @param moodManager The MoodManager 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 Mood data that is to be registered.
*
* @throws Exception if the test fails
*/
public void registerListenerAndWait(MoodManager moodManager, ServiceDiscoveryManager discoManager, PepEventListener<MoodElement> listener) throws Exception {
final SimpleResultSyncPoint notificationFilterReceived = new SimpleResultSyncPoint();
final EntityCapabilitiesChangedListener notificationFilterReceivedListener = info -> {
if (info.containsFeature(MoodManager.MOOD_NODE + "+notify")) {
notificationFilterReceived.signal();
}
};
discoManager.addEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
try {
moodManager.addMoodListener(listener);
notificationFilterReceived.waitForResult(timeout);
} finally {
discoManager.removeEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
}
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.
the class EntityCapsTest method addFeatureAndWaitForPresence.
/**
* Adds 'feature' to conB and waits until conA observes a presence form conB.
*
* @param conA the connection to observe the presence on.
* @param conB the connection to add the feature to.
* @param feature the feature to add.
* @throws Exception in case of an exception.
*/
private void addFeatureAndWaitForPresence(XMPPConnection conA, XMPPConnection conB, String feature) throws Exception {
final ServiceDiscoveryManager sdmB = ServiceDiscoveryManager.getInstanceFor(conB);
ThrowingRunnable action = new ThrowingRunnable() {
@Override
public void runOrThrow() throws Exception {
sdmB.addFeature(feature);
}
};
performActionAndWaitForPresence(conA, conB, action);
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager 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);
}
}
Aggregations