Returns a shard iterator for the given {@link SequenceNumber}.

@return shard iterator
@throws Exception
423892
protected String getShardIterator(SequenceNumber sequenceNumber) throws Exception {

		if (isSentinelSequenceNumber(sequenceNumber)) {
			return getShardIteratorForSentinel(sequenceNumber);
		} else {
			// we will be starting from an actual sequence number (due to restore from failure).
			return getShardIteratorForRealSequenceNumber(sequenceNumber);
		}
	}
91247
List<Iterator<BlockInfo>> getBlocksIterarors(int numShards) {
    List<Iterator<BlockInfo>> iterators = new ArrayList<Iterator<BlockInfo>>();
    if (numShards <= 0) {
      throw new IllegalArgumentException("Number of shards must be greater than 0");
    }
    for (int i = 0; i < numShards; i++) {
      Iterator<BlockInfo> iterator = blocks.shardIterator(i, numShards);
      if (iterator != null) {
        iterators.add(iterator);
      }
    }   
    return iterators;
  }
94140
@SafeVarargs
    public static <T> Iterable<T> sequence( final Iterable<? extends T>... iterables ) {
        return new Iterable<T>() {
            public Iterator<T> iterator() {
                return new FlattenIterator<T,Iterable<? extends T>>(ImmutableList.copyOf(iterables)) {
                    protected Iterator<T> expand(Iterable<? extends T> iterable) {
                        return Iterators.<T>cast(iterable).iterator();
                    }
                };
            }
        };
    }
383561
@Override
	public final MutableObjectIterator<T> getIterator() {
		final SingleSegmentInputView startIn = new SingleSegmentInputView(this.recordsPerSegment * this.recordSize);
		startIn.set(this.sortBuffer.get(0), 0);
		
		return new MutableObjectIterator<T>() {
			
			private final SingleSegmentInputView in = startIn;
			private final TypeComparator<T> comp = comparator;
			
			private final int numTotal = size();
			private final int numPerSegment = recordsPerSegment;
			
			private int currentTotal = 0;
			private int currentInSegment = 0;
			private int currentSegmentIndex = 0;

			@Override
			public T next(T reuse) {
				if (this.currentTotal < this.numTotal) {
					
					if (this.currentInSegment >= this.numPerSegment) {
						this.currentInSegment = 0;
						this.currentSegmentIndex++;
						this.in.set(sortBuffer.get(this.currentSegmentIndex), 0);
					}
					
					this.currentTotal++;
					this.currentInSegment++;
					
					try {
						return this.comp.readWithKeyDenormalization(reuse, this.in);
					}
					catch (IOException ioe) {
						throw new RuntimeException(ioe);
					}
				}
				else {
					return null;
				}
			}
		};
	}
412886
public Iterator<A> iterator() {
        return new Iterator<A>() {
            List<A> elems = ListBuffer.this.elems;
            public boolean hasNext() {
                return !elems.isEmpty();
            }
            public A next() {
                if (elems.isEmpty())
                    throw new NoSuchElementException();
                A elem = elems.head;
                elems = elems.tail;
                return elem;
            }
            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
682642
public Iterator<Node> iterator() {

        return new Iterator<Node>() {
            private int currentIndex = 0;
            
            public boolean hasNext() {
                return currentIndex < nodeList.getLength();
            }
            
            public Node next() {
                Node next = nodeList.item(currentIndex);
                currentIndex++;
                if (next == null) {
                    throw new NoSuchElementException("No element found for index: " + currentIndex);
                }
                return next;
            }
            
            public void remove() {
                throw new UnsupportedOperationException("IterableNodeList does not support remove");
            }
        };
    }
927331
private Long getSequence(String sequenceName)
    {
        Long result = null;
        // now lookup the sequence map for calling DB
        Map mapForDB = (Map) sequencesDBMap.get(getBrokerForClass()
                .serviceConnectionManager().getConnectionDescriptor().getJcdAlias());
        if(mapForDB != null)
        {
            result = (Long) mapForDB.get(sequenceName);
        }
        return result;
    }
512678
public Iterator iterator() {
        return new Iterator() {
            public boolean hasNext() {
                return false;
            }

            public Object next() {
                return null;
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
1334430
int nextSequenceShuffleIndex() throws Exception {
		RTObject popEvaluationStack = state.popEvaluationStack();

		IntValue numElementsIntVal = popEvaluationStack instanceof IntValue ? (IntValue) popEvaluationStack : null;

		if (numElementsIntVal == null) {
			error("expected number of elements in sequence for shuffle index");
			return 0;
		}

		Container seqContainer = state.getCurrentPointer().container;

		int numElements = numElementsIntVal.value;

		IntValue seqCountVal = (IntValue) state.popEvaluationStack();
		int seqCount = seqCountVal.value;
		int loopIndex = seqCount / numElements;
		int iterationIndex = seqCount % numElements;

		// Generate the same shuffle based on:
		// - The hash of this container, to make sure it's consistent
		// each time the runtime returns to the sequence
		// - How many times the runtime has looped around this full shuffle
		String seqPathStr = seqContainer.getPath().toString();
		int sequenceHash = 0;
		for (char c : seqPathStr.toCharArray()) {
			sequenceHash += c;
		}

		int randomSeed = sequenceHash + loopIndex + state.getStorySeed();

		Random random = new Random(randomSeed);

		ArrayList<Integer> unpickedIndices = new ArrayList<Integer>();
		for (int i = 0; i < numElements; ++i) {
			unpickedIndices.add(i);
		}

		for (int i = 0; i <= iterationIndex; ++i) {
			int chosen = random.nextInt(Integer.MAX_VALUE) % unpickedIndices.size();
			int chosenIndex = unpickedIndices.get(chosen);
			unpickedIndices.remove(chosen);

			if (i == iterationIndex) {
				return chosenIndex;
			}
		}

		throw new Exception("Should never reach here");
	}
966508
@Override
	public Iterator<C> iterator() {
		final List<Sequence<C>> localSequences = sequences;
		return new Iterator<C>() {

			private Iterator<C> currentSequenceIterator = null;
			private int currentPosition = 0;


			@Override
			public boolean hasNext() {
				//If the current iterator is null then see if the Sequences object has anything
				if (currentSequenceIterator == null) {
					return !localSequences.isEmpty();
				}

				//See if we had any compounds
				boolean hasNext = currentSequenceIterator.hasNext();
				if (!hasNext) {
					hasNext = currentPosition < sequences.size();
				}
				return hasNext;
			}


			@Override
			public C next() {
				if (currentSequenceIterator == null) {
					if (localSequences.isEmpty()) {
						throw new NoSuchElementException("No sequences to iterate over; make sure you call hasNext() before next()");
					}
					currentSequenceIterator = localSequences.get(currentPosition).iterator();
					currentPosition++;
				}
				if (!currentSequenceIterator.hasNext()) {
					currentSequenceIterator = localSequences.get(currentPosition).iterator();
					currentPosition++;
				}
				return currentSequenceIterator.next();
			}


			@Override
			public void remove() throws UnsupportedOperationException {
				throw new UnsupportedOperationException("Cannot remove from this Sequence");
			}
		};
	}
1367561
public static <T> ImmutableMap<T, Integer> itemToIndexMap(final Iterable<T> sequence) {
    return itemToIndexMapStartingFrom(sequence, 0);
  }
1113314
@Override
    public Object mapSequence(Object sequence) {
        List<?> values = (List<?>) sequence;
        List<List<Integer>> ret = new ArrayList<>();
        for (Object obj : values) {
            ret.add((List<Integer>) map(obj));
        }
        return ret;
    }
1339495
protected function getInitialShardIterator($shard_id, $starting_sequence_number = NULL)
    {

        $args = [
            'ShardId' => $shard_id,
            'StreamName' => $this->getStreamName(),
            'ShardIteratorType' => $this->initialShardIteratorType,
        ];

        // If we have the starting sequence number update also the ShardIteratorType
        // to start reading just after it.
        if (!empty($starting_sequence_number)) {
            $args['ShardIteratorType'] = self::ITERATOR_TYPE_AFTER_SEQUENCE_NUMBER;
            $args['StartingSequenceNumber'] = $starting_sequence_number;
        }

        $res = $this->getClient()->getShardIterator($args);

        return $res->get('ShardIterator');
    }
821369
@Override
  protected ShardsIterator shards(ClusterState clusterState, GetIndicesVersionRequest request, String[] concreteIndices) {
    return clusterState.routingTable().allShards(concreteIndices);
  }
1304952
public void runFetcher() throws Exception {

		// check that we are running before proceeding
		if (!running) {
			return;
		}

		this.mainThread = Thread.currentThread();

		// ------------------------------------------------------------------------
		//  Procedures before starting the infinite while loop:
		// ------------------------------------------------------------------------

		//  1. check that there is at least one shard in the subscribed streams to consume from (can be done by
		//     checking if at least one value in subscribedStreamsToLastDiscoveredShardIds is not null)
		boolean hasShards = false;
		StringBuilder streamsWithNoShardsFound = new StringBuilder();
		for (Map.Entry<String, String> streamToLastDiscoveredShardEntry : subscribedStreamsToLastDiscoveredShardIds.entrySet()) {
			if (streamToLastDiscoveredShardEntry.getValue() != null) {
				hasShards = true;
			} else {
				streamsWithNoShardsFound.append(streamToLastDiscoveredShardEntry.getKey()).append(", ");
			}
		}

		if (streamsWithNoShardsFound.length() != 0 && LOG.isWarnEnabled()) {
			LOG.warn("Subtask {} has failed to find any shards for the following subscribed streams: {}",
				indexOfThisConsumerSubtask, streamsWithNoShardsFound.toString());
		}

		if (!hasShards) {
			throw new RuntimeException("No shards can be found for all subscribed streams: " + streams);
		}

		//  2. start consuming any shard state we already have in the subscribedShardState up to this point; the
		//     subscribedShardState may already be seeded with values due to step 1., or explicitly added by the
		//     consumer using a restored state checkpoint
		for (int seededStateIndex = 0; seededStateIndex < subscribedShardsState.size(); seededStateIndex++) {
			KinesisStreamShardState seededShardState = subscribedShardsState.get(seededStateIndex);

			// only start a consuming thread if the seeded subscribed shard has not been completely read already
			if (!seededShardState.getLastProcessedSequenceNum().equals(SentinelSequenceNumber.SENTINEL_SHARD_ENDING_SEQUENCE_NUM.get())) {

				if (LOG.isInfoEnabled()) {
					LOG.info("Subtask {} will start consuming seeded shard {} from sequence number {} with ShardConsumer {}",
						indexOfThisConsumerSubtask, seededShardState.getStreamShardHandle().toString(),
						seededShardState.getLastProcessedSequenceNum(), seededStateIndex);
					}

				shardConsumersExecutor.submit(
					createShardConsumer(
						seededStateIndex,
						subscribedShardsState.get(seededStateIndex).getStreamShardHandle(),
						subscribedShardsState.get(seededStateIndex).getLastProcessedSequenceNum(),
						registerShardMetrics(consumerMetricGroup, subscribedShardsState.get(seededStateIndex))));
			}
		}

        // start periodic watermark emitter, if a watermark assigner was configured
		if (periodicWatermarkAssigner != null) {
			long periodicWatermarkIntervalMillis = runtimeContext.getExecutionConfig().getAutoWatermarkInterval();
			if (periodicWatermarkIntervalMillis > 0) {
				ProcessingTimeService timerService = ((StreamingRuntimeContext) runtimeContext).getProcessingTimeService();
				LOG.info("Starting periodic watermark emitter with interval {}", periodicWatermarkIntervalMillis);
				new PeriodicWatermarkEmitter(timerService, periodicWatermarkIntervalMillis).start();
			}
			this.shardIdleIntervalMillis = Long.parseLong(
				getConsumerConfiguration().getProperty(ConsumerConfigConstants.SHARD_IDLE_INTERVAL_MILLIS,
					Long.toString(ConsumerConfigConstants.DEFAULT_SHARD_IDLE_INTERVAL_MILLIS)));
		}

		// ------------------------------------------------------------------------

		// finally, start the infinite shard discovery and consumer launching loop;
		// we will escape from this loop only when shutdownFetcher() or stopWithError() is called

		final long discoveryIntervalMillis = Long.valueOf(
			configProps.getProperty(
				ConsumerConfigConstants.SHARD_DISCOVERY_INTERVAL_MILLIS,
				Long.toString(ConsumerConfigConstants.DEFAULT_SHARD_DISCOVERY_INTERVAL_MILLIS)));

		if (this.numberOfActiveShards.get() == 0) {
			LOG.info("Subtask {} has no active shards to read on startup; marking the subtask as temporarily idle ...",
				indexOfThisConsumerSubtask);
			sourceContext.markAsTemporarilyIdle();
		}

		while (running) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("Subtask {} is trying to discover new shards that were created due to resharding ...",
					indexOfThisConsumerSubtask);
			}
			List<StreamShardHandle> newShardsDueToResharding = discoverNewShardsToSubscribe();

			for (StreamShardHandle shard : newShardsDueToResharding) {
				// since there may be delay in discovering a new shard, all new shards due to
				// resharding should be read starting from the earliest record possible
				KinesisStreamShardState newShardState =
					new KinesisStreamShardState(convertToStreamShardMetadata(shard), shard, SentinelSequenceNumber.SENTINEL_EARLIEST_SEQUENCE_NUM.get());
				int newStateIndex = registerNewSubscribedShardState(newShardState);

				if (LOG.isInfoEnabled()) {
					LOG.info("Subtask {} has discovered a new shard {} due to resharding, and will start consuming " +
							"the shard from sequence number {} with ShardConsumer {}",
						indexOfThisConsumerSubtask, newShardState.getStreamShardHandle().toString(),
						newShardState.getLastProcessedSequenceNum(), newStateIndex);
				}

				shardConsumersExecutor.submit(
					createShardConsumer(
						newStateIndex,
						newShardState.getStreamShardHandle(),
						newShardState.getLastProcessedSequenceNum(),
						registerShardMetrics(consumerMetricGroup, newShardState)));
			}

			// we also check if we are running here so that we won't start the discovery sleep
			// interval if the running flag was set to false during the middle of the while loop
			if (running && discoveryIntervalMillis != 0) {
				try {
					Thread.sleep(discoveryIntervalMillis);
				} catch (InterruptedException iex) {
					// the sleep may be interrupted by shutdownFetcher()
				}
			}
		}

		// make sure all resources have been terminated before leaving
		try {
			awaitTermination();
		} catch (InterruptedException ie) {
			// If there is an original exception, preserve it, since that's more important/useful.
			this.error.compareAndSet(null, ie);
		}

		// any error thrown in the shard consumer threads will be thrown to the main thread
		Throwable throwable = this.error.get();
		if (throwable != null) {
			if (throwable instanceof Exception) {
				throw (Exception) throwable;
			} else if (throwable instanceof Error) {
				throw (Error) throwable;
			} else {
				throw new Exception(throwable);
			}
		}
	}
36333
public Iterator<T> iterator() {
        Collection<ServiceReference<T>> fetchReferences = fetchReferences();
        return new ServiceReferenceIterator<T>(fetchReferences.iterator(), bundleContext);
    }
608561
public FastqBuilder withSequence(final String sequence)
	{
		if (sequence == null)
		{
			throw new IllegalArgumentException("sequence must not be null");
		}
		if (this.sequence == null)
		{
			this.sequence = new StringBuilder(sequence.length());
		}
		this.sequence.replace(0, this.sequence.length(), sequence);
		return this;
	}