@Override
	public <S extends JobDefinition> S save(S entity) {
		try {
			Map<String, String> map = new HashMap<String, String>();
			map.put("definition", entity.getDefinition());

			CuratorFramework client = zkConnection.getClient();
			String path = Paths.build(Paths.JOBS, entity.getName());
			byte[] binary = ZooKeeperUtils.mapToBytes(map);

			BackgroundPathAndBytesable<?> op = client.checkExists().forPath(path) == null
					? client.create() : client.setData();

			op.forPath(path, binary);

			logger.info("Saved job {} with properties {}", path, map);
		}

		catch (Exception e) {
			//NodeExistsException indicates that we tried to create the
			// path just after another thread/jvm successfully created it
			ZooKeeperUtils.wrapAndThrowIgnoring(e, NodeExistsException.class);
		}
		return entity;
	}
A Zookeeper backed repository for persisting {@link JobDefinition}s.

@author Mark Fisher
@author David Turanski
spring-xd-dirt/src/main/java/org/springframework/xd/dirt/stream/zookeeper/ZooKeeperJobDefinitionRepository.java