public List < IoTFieldsExtension > requestMomentaryValuesReadOut ( EntityFullJid jid ) throws NoResponseException , XMPPErrorException , NotConnectedException , InterruptedException { final XMPPConnection connection = connection ( ) ; final int seqNr = nextSeqNr . incrementAndGet ( ) ; IoTDataRequest iotDataRequest = new IoTDataRequest ( seqNr , true ) ; iotDataRequest . setTo ( jid ) ; StanzaFilter doneFilter = new IoTFieldsExtensionFilter ( seqNr , true ) ; StanzaFilter dataFilter = new IoTFieldsExtensionFilter ( seqNr , false ) ; // Setup the IoTFieldsExtension message collectors before sending the IQ to avoid a data race. StanzaCollector doneCollector = connection . createStanzaCollector ( doneFilter ) ; StanzaCollector . Configuration dataCollectorConfiguration = StanzaCollector . newConfiguration ( ) . setStanzaFilter ( dataFilter ) . setCollectorToReset ( doneCollector ) ; StanzaCollector dataCollector = connection . createStanzaCollector ( dataCollectorConfiguration ) ; try { connection . createStanzaCollectorAndSend ( iotDataRequest ) . nextResultOrThrow ( ) ; // Wait until a message with an IoTFieldsExtension and the done flag comes in. doneCollector . nextResult ( ) ; } finally { // Canceling dataCollector will also cancel the doneCollector since it is configured as dataCollector's // collector to reset. dataCollector . cancel ( ) ; } int collectedCount = dataCollector . getCollectedCount ( ) ; List < IoTFieldsExtension > res = new ArrayList <> ( collectedCount ) ; for ( int i = 0 ; i < collectedCount ; i ++ ) { Message message = dataCollector . pollResult ( ) ; IoTFieldsExtension iotFieldsExtension = IoTFieldsExtension . from ( message ) ; res . add ( iotFieldsExtension ) ; } return res ; }
Try to read out a things momentary values .