public void recalculateStreamStates(PathChildrenCache streamDeployments) throws Exception {
		Assert.notNull(streamDeployments, "Stream deployment path cache shouldn't be null.");
		CuratorFramework client = zkConnection.getClient();
		for (Iterator<String> iterator =
				new ChildPathIterator<String>(ZooKeeperUtils.stripPathConverter, streamDeployments); iterator.hasNext(); ) {
			String streamName = iterator.next();
			String definitionPath = Paths.build(Paths.build(Paths.STREAM_DEPLOYMENTS, streamName));

			try {
				final Stream stream = DeploymentLoader.loadStream(client, streamName, streamFactory);
				if (stream != null) {
					String streamModulesPath = Paths.build(definitionPath, Paths.MODULES);
					List<ModuleDeploymentStatus> statusList = new ArrayList<ModuleDeploymentStatus>();
					try {
						List<String> moduleDeployments = client.getChildren().forPath(streamModulesPath);
						for (String moduleDeployment : moduleDeployments) {
							StreamDeploymentsPath streamDeploymentsPath = new StreamDeploymentsPath(
									Paths.build(streamModulesPath, moduleDeployment));
							statusList.add(new ModuleDeploymentStatus(
									streamDeploymentsPath.getContainer(),
									streamDeploymentsPath.getModuleSequence(),
									new ModuleDescriptor.Key(streamName,
											ModuleType.valueOf(streamDeploymentsPath.getModuleType()),
											streamDeploymentsPath.getModuleLabel()),
									ModuleDeploymentStatus.State.deployed, null));
						}
					}
					catch (KeeperException.NoNodeException e) {
						// indicates there are no modules deployed for this stream;
						// ignore as this will result in an empty statusList
					}
					writeDeploymentUnitStatus(DeploymentUnitType.Stream, streamName,
							stateCalculator.calculate(stream,
									new DefaultModuleDeploymentPropertiesProvider(stream), statusList));
				}
			}
			catch (Exception e) {
				logger.error(String.format("Exception calculating status for stream %s; status will be set to %s.",
						streamName, DeploymentUnitStatus.State.unknown), e);
				writeDeploymentUnitStatus(DeploymentUnitType.Stream, streamName,
						new DeploymentUnitStatus(DeploymentUnitStatus.State.unknown));
			}
		}
	}
Iterate all deployed streams, recalculate the state of each, and create
an ephemeral node indicating the stream state. This is typically invoked
upon leader election.

@throws Exception
spring-xd-dirt/src/main/java/org/springframework/xd/dirt/server/admin/deployment/zk/DefaultDeploymentStateRecalculator.java