@Override
	public void delete(String id) {
		logger.info("Undeploying stream {}", id);

		String streamDeploymentPath = Paths.build(Paths.STREAM_DEPLOYMENTS, id);
		String streamModuleDeploymentPath = Paths.build(streamDeploymentPath, Paths.MODULES);
		CuratorFramework client = zkConnection.getClient();
		Deque<String> paths = new ArrayDeque<String>();

		try {
			client.setData().forPath(
					Paths.build(Paths.STREAM_DEPLOYMENTS, id, Paths.STATUS),
					ZooKeeperUtils.mapToBytes(new DeploymentUnitStatus(
							DeploymentUnitStatus.State.undeploying).toMap()));
		}
		catch (Exception e) {
			logger.warn("Exception while transitioning stream {} state to {}", id,
					DeploymentUnitStatus.State.undeploying, e);
		}

		// Place all module deployments into a tree keyed by the
		// ZK transaction id. The ZK transaction id maintains
		// total ordering of all changes. This allows the
		// undeployment of modules in the reverse order in
		// which they were deployed.
		Map<Long, String> txMap = new TreeMap<Long, String>();
		try {
			List<String> deployments = client.getChildren().forPath(streamModuleDeploymentPath);
			for (String deployment : deployments) {
				String path = new StreamDeploymentsPath(Paths.build(streamModuleDeploymentPath, deployment)).build();
				Stat stat = client.checkExists().forPath(path);
				Assert.notNull(stat);
				txMap.put(stat.getCzxid(), path);
			}
		}
		catch (Exception e) {
			//NoNodeException - nothing to delete
			ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NoNodeException.class);
		}

		for (String deployment : txMap.values()) {
			paths.add(deployment);
		}

		for (Iterator<String> iterator = paths.descendingIterator(); iterator.hasNext();) {
			try {
				String path = iterator.next();
				logger.trace("removing path {}", path);
				client.delete().deletingChildrenIfNeeded().forPath(path);
			}
			catch (Exception e) {
				ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NoNodeException.class);
			}
		}

		try {
			client.delete().deletingChildrenIfNeeded().forPath(streamDeploymentPath);
		}
		catch (KeeperException.NotEmptyException e) {
			List<String> children = new ArrayList<String>();
			try {
				children.addAll(client.getChildren().forPath(streamModuleDeploymentPath));
			}
			catch (Exception ex) {
				children.add("Could not load list of children due to " + ex);
			}
			throw new IllegalStateException(String.format(
					"The following children were not deleted from %s: %s", streamModuleDeploymentPath, children), e);
		}
		catch (Exception e) {
			ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NoNodeException.class);
		}
	}
Stream instance repository. It should only return values for Streams that are deployed.

@author Mark Fisher
@author Gunnar Hillert
spring-xd-dirt/src/main/java/org/springframework/xd/dirt/stream/zookeeper/ZooKeeperStreamRepository.java