+ @Override
+ public Optional<Timeout> getPollTimeout() {
+ return Optional.ofNullable(pollTimeout);
+ }
+
+ private void statChainFuture(final Iterator<MultipartType> iterator, final SettableFuture<Boolean> resultFuture) {
+ if (ConnectionContext.CONNECTION_STATE.RIP.equals(deviceContext.getPrimaryConnectionContext().getConnectionState())) {
+ final String errMsg = String.format("Device connection is closed for Node : %s.",
+ deviceContext.getDeviceInfo().getNodeId());
+ LOG.debug(errMsg);
+ resultFuture.setException(new IllegalStateException(errMsg));
+ return;
+ }
+ if ( ! iterator.hasNext()) {
+ resultFuture.set(Boolean.TRUE);
+ LOG.debug("Stats collection successfully finished for node {}", deviceContext.getDeviceInfo().getNodeId());
+ return;
+ }
+
+ final MultipartType nextType = iterator.next();
+ LOG.debug("Stats iterating to next type for node {} of type {}", deviceContext.getDeviceInfo().getNodeId(), nextType);
+
+ final ListenableFuture<Boolean> deviceStatisticsCollectionFuture = chooseStat(nextType);
+ Futures.addCallback(deviceStatisticsCollectionFuture, new FutureCallback<Boolean>() {
+ @Override
+ public void onSuccess(final Boolean result) {
+ statChainFuture(iterator, resultFuture);
+ }
+ @Override
+ public void onFailure(@Nonnull final Throwable t) {
+ resultFuture.setException(t);
+ }
+ });
+ }
+
+ /**
+ * Method checks a device state. It returns null for be able continue. Otherwise it returns immediateFuture
+ * which has to be returned from caller too
+ *
+ * @return
+ */
+ @VisibleForTesting
+ ListenableFuture<Boolean> deviceConnectionCheck() {
+ if (!ConnectionContext.CONNECTION_STATE.WORKING.equals(deviceContext.getPrimaryConnectionContext().getConnectionState())) {
+ ListenableFuture<Boolean> resultingFuture = SettableFuture.create();