public IoTUnregister(NodeInfo nodeInfo) { super(ELEMENT, NAMESPACE); this.nodeInfo = nodeInfo; setType(Type.set); }
public Builder setKey(String key) { final String name = "KEY"; Tag tag = new Tag(name, Type.str, key); metaTags.put(name, tag); return this; }
/** * Claim a thing by providing a collection of meta tags. If the claim was successful, then a {@link IoTClaimed} * instance will be returned, which contains the XMPP address of the thing. Use {@link IoTClaimed#getJid()} to * retrieve this address. * * @param registry the registry use to claim the thing. * @param metaTags a collection of meta tags used to identify the thing. * @param publicThing if this is a public thing. * @return a {@link IoTClaimed} if successful. * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException */ public IoTClaimed claimThing(Jid registry, Collection<Tag> metaTags, boolean publicThing) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { interactWithRegistry(registry); IoTMine iotMine = new IoTMine(metaTags, publicThing); iotMine.setTo(registry); IoTClaimed iotClaimed = connection().createStanzaCollectorAndSend(iotMine).nextResultOrThrow(); // The 'jid' attribute of the <claimed/> response now represents the XMPP address of the thing we just successfully claimed. Jid thing = iotClaimed.getJid(); IoTProvisioningManager.getInstanceFor(connection()).sendFriendshipRequest(thing.asBareJid()); return iotClaimed; }
@Override public IoTRegister parse(XmlPullParser parser, int initialDepth) throws Exception { boolean selfOwned = ParserUtils.getBooleanAttribute(parser, "selfOwned", false); NodeInfo nodeInfo = NodeInfoParser.parse(parser); List<Tag> tags = new ArrayList<>(); while (parser.getDepth() != initialDepth) { int event = parser.next(); if (event != XmlPullParser.START_TAG) { continue; } final String element = parser.getName(); Tag.Type type = null; switch (element) { case "str": type = Tag.Type.str; break; case "num": type = Tag.Type.num; break; } if (type == null) { continue; } String name = parser.getAttributeValue(null, "name"); String value = parser.getAttributeValue(null, "value"); tags.add(new Tag(name, type, value)); } return new IoTRegister(tags, nodeInfo, selfOwned); }
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(); }
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.; }
@Override public IQ handleIQRequest(IQ iqRequest) { if (!isRegistry(iqRequest.getFrom())) { LOGGER.log(Level.SEVERE, "Received control stanza from non-registry entity: " + iqRequest); return null; } IoTRemoved iotRemoved = (IoTRemoved) iqRequest; ThingState state = getStateFor(iotRemoved.getNodeInfo()); state.setRemoved(); // Unfriend registry. "It does this, so the Thing can remove the friendship and stop any // meta data updates to the Registry." try { IoTProvisioningManager.getInstanceFor(connection()).unfriend(iotRemoved.getFrom()); } catch (NotConnectedException | InterruptedException e) { LOGGER.log(Level.SEVERE, "Could not unfriend registry after <removed/>", e); } return IQ.createResultIQ(iqRequest); } });
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); }
@Override public IoTUnregister parse(XmlPullParser parser, int initialDepth) throws Exception { NodeInfo nodeInfo = NodeInfoParser.parse(parser); return new IoTUnregister(nodeInfo); }
@Override public IoTRemoved parse(XmlPullParser parser, int initialDepth) throws Exception { NodeInfo nodeInfo = NodeInfoParser.parse(parser); return new IoTRemoved(nodeInfo); }
@Override public IoTDisowned parse(XmlPullParser parser, int initialDepth) throws Exception { NodeInfo nodeInfo = NodeInfoParser.parse(parser); return new IoTDisowned(nodeInfo); }
@Override public IoTDisown parse(XmlPullParser parser, int initialDepth) throws Exception { Jid jid = ParserUtils.getJidAttribute(parser); NodeInfo nodeInfo = NodeInfoParser.parse(parser); return new IoTDisown(jid, nodeInfo); }
@Override public IoTClaimed parse(XmlPullParser parser, int initialDepth) throws Exception { Jid jid = ParserUtils.getJidAttribute(parser); NodeInfo nodeInfo = NodeInfoParser.parse(parser); return new IoTClaimed(jid, nodeInfo); }
@Override public IoTRemove parse(XmlPullParser parser, int initialDepth) throws Exception { Jid jid = ParserUtils.getJidAttribute(parser); if (jid.hasResource()) { throw new SmackException("JID must be without resourcepart"); } BareJid bareJid = jid.asBareJid(); NodeInfo nodeInfo = NodeInfoParser.parse(parser); return new IoTRemove(bareJid, nodeInfo); }
@SuppressWarnings("ObjectToString") @Override public IQ handleIQRequest(IQ iqRequest) { if (!isRegistry(iqRequest.getFrom())) { LOGGER.log(Level.SEVERE, "Received control stanza from non-registry entity: " + iqRequest); return null; } IoTDisowned iotDisowned = (IoTDisowned) iqRequest; Jid from = iqRequest.getFrom(); NodeInfo nodeInfo = iotDisowned.getNodeInfo(); ThingState state = getStateFor(nodeInfo); if (!from.equals(state.getRegistry())) { LOGGER.severe("Received <disowned/> for " + nodeInfo + " from " + from + " but this is not the registry " + state.getRegistry() + " of the thing."); return null; } if (state.isOwned()) { state.setUnowned(); } else { LOGGER.fine("Received <disowned/> for " + nodeInfo + " but thing was not owned."); } return IQ.createResultIQ(iqRequest); } });
public Builder setSerialNumber(String sn) { final String name = "SN"; Tag tag = new Tag(name, Type.str, sn); metaTags.put(name, tag); return this; }
public Builder setModel(String model) { final String name = "MODEL"; Tag tag = new Tag(name, Type.str, model); metaTags.put(name, tag); return this; }
public Builder setVersion(String version) { final String name = "V"; Tag tag = new Tag(name, Type.num, version); metaTags.put(name, tag); return this; }
public Builder setManufacturer(String manufacturer) { final String name = "MAN"; Tag tag = new Tag(name, Type.str, manufacturer); metaTags.put(name, tag); return this; }