static void checkPrerequisites(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, TestNotPossibleException { IoTDiscoveryManager discoveryManager = IoTDiscoveryManager.getInstanceFor(connection); Jid registry = discoveryManager.findRegistry(); if (registry == null) { throw new TestNotPossibleException("Could not find IoT Registry"); } }
public IoTClaimed claimThing(Collection<Tag> metaTags, boolean publicThing) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Jid registry = findRegistry(); return claimThing(registry, metaTags, publicThing); }
public void disownThing(Jid thing, NodeInfo nodeInfo) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Jid registry = findRegistry(); disownThing(registry, thing, nodeInfo); }
public ThingState registerThing(Thing thing) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, IoTClaimedException { Jid registry = findRegistry(); return registerThing(registry, thing); }
public void unregister(NodeInfo nodeInfo) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Jid registry = findRegistry(); unregister(registry, nodeInfo); }
public void unregister(Jid registry, NodeInfo nodeInfo) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { interactWithRegistry(registry); IoTUnregister iotUnregister = new IoTUnregister(nodeInfo); iotUnregister.setTo(registry); connection().createStanzaCollectorAndSend(iotUnregister).nextResultOrThrow(); ThingState state = getStateFor(nodeInfo); state.setUnregistered(); final XMPPConnection connection = connection(); IoTDataManager.getInstanceFor(connection).uninstallThing(nodeInfo); IoTControlManager.getInstanceFor(connection).uninstallThing(nodeInfo); }
@SmackIntegrationTest public void registerClaimAndUnregisterThing() throws XMPPErrorException, InterruptedException, SmackException { final String key = StringUtils.randomString(12); final String sn = StringUtils.randomString(12); final Thing thing = Thing.builder().setKey(key).setSerialNumber(sn).setManufacturer("Ignite Realtime").setModel( "Smack").setVersion("0.1").build(); registerThing(discoveryManagerOne, thing); IoTClaimed iotClaimed = discoveryManagerTwo.claimThing(thing.getMetaTags()); assertEquals(conOne.getUser().asBareJid(), iotClaimed.getJid()); discoveryManagerTwo.disownThing(iotClaimed.getJid()); discoveryManagerOne.unregister(); }
public void removeThing(Jid registry, BareJid thing, NodeInfo nodeInfo) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { interactWithRegistry(registry); IoTRemove iotRemove = new IoTRemove(thing, nodeInfo); iotRemove.setTo(registry); connection().createStanzaCollectorAndSend(iotRemove).nextResultOrThrow(); // We no not update the ThingState here, as this is done in the <removed/> IQ handler above.; }
if (IoTDiscoveryManager.getInstanceFor(connection()).isRegistry(from.asBareJid())) { return SubscribeAnswer.Approve;
public static ThingState registerThing(IoTDiscoveryManager iotDiscoveryManager, Thing thing) throws XMPPErrorException, InterruptedException, SmackException { int attempts = 0; while (true) { try { return iotDiscoveryManager.registerThing(thing); } catch (IoTClaimedException e) { iotDiscoveryManager.unregister(); } if (attempts++ > 3) { throw new SmackException("Could no register thing"); } } }
public IoTDiscoveryIntegrationTest(SmackIntegrationTestEnvironment environment) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, TestNotPossibleException { super(environment); discoveryManagerOne = IoTDiscoveryManager.getInstanceFor(conOne); discoveryManagerTwo = IoTDiscoveryManager.getInstanceFor(conTwo); checkPrerequisites(conOne); }
public void removeThing(BareJid thing, NodeInfo nodeInfo) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Jid registry = findRegistry(); removeThing(registry, thing, nodeInfo); }
public void unregister() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { unregister(NodeInfo.EMPTY); }
public IoTClaimed claimThing(Collection<Tag> metaTags) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return claimThing(metaTags, true); }
public void disownThing(Jid thing) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { disownThing(thing, NodeInfo.EMPTY); }
public boolean isRegistry(BareJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Objects.requireNonNull(jid, "JID argument must not be null"); // At some point 'usedRegistries' will also contain the registry returned by findRegistry(), but since this is // not the case from the beginning, we perform findRegistry().equals(jid) too. Jid registry = findRegistry(); if (jid.equals(registry)) { return true; } if (usedRegistries.contains(jid)) { return true; } return false; }
private void interactWithRegistry(Jid registry) throws NotConnectedException, InterruptedException { boolean isNew = usedRegistries.add(registry); if (!isNew) { return; } IoTProvisioningManager iotProvisioningManager = IoTProvisioningManager.getInstanceFor(connection()); iotProvisioningManager.sendFriendshipRequestIfRequired(registry.asBareJid()); }
/** * Get the manger instance responsible for the given connection. * * @param connection the XMPP connection. * @return a manager instance. */ public static synchronized IoTDiscoveryManager getInstanceFor(XMPPConnection connection) { IoTDiscoveryManager manager = INSTANCES.get(connection); if (manager == null) { manager = new IoTDiscoveryManager(connection); INSTANCES.put(connection, manager); } return manager; }
public ThingState registerThing(Jid registry, Thing thing) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, IoTClaimedException { final XMPPConnection connection = connection(); IoTRegister iotRegister = new IoTRegister(thing.getMetaTags(), thing.getNodeInfo(), thing.isSelfOwened()); iotRegister.setTo(registry); IQ result = connection.createStanzaCollectorAndSend(iotRegister).nextResultOrThrow(); if (result instanceof IoTClaimed) { IoTClaimed iotClaimedResult = (IoTClaimed) result; throw new IoTClaimedException(iotClaimedResult); } ThingState state = getStateFor(thing.getNodeInfo()); state.setRegistry(registry.asBareJid()); interactWithRegistry(registry); IoTDataManager.getInstanceFor(connection).installThing(thing); IoTControlManager.getInstanceFor(connection).installThing(thing); return state; }
public void disownThing(Jid registry, Jid thing, NodeInfo nodeInfo) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { interactWithRegistry(registry); IoTDisown iotDisown = new IoTDisown(thing, nodeInfo); iotDisown.setTo(registry); connection().createStanzaCollectorAndSend(iotDisown).nextResultOrThrow(); }