public void setStreamThreadStateListener(final StreamThread.StateListener listener) {
        if (state == State.CREATED) {
            for (final StreamThread thread : threads) {
                thread.setStateListener(listener);
            }
        } else {
            throw new IllegalStateException("Can only set StateListener in CREATED state. " +
                "Current state is: " + state);
        }
    }
An app can set a single {@link StreamThread.StateListener} so that the app is notified when state changes.

@param listener a new StreamThread state listener
@throws IllegalStateException if this {@code KafkaStreams} instance is not in state {@link State#CREATED CREATED}.
streams/src/test/java/org/apache/kafka/streams/KafkaStreamsWrapper.java