private void refresh() throws KeeperException, InterruptedException {
    List<RepositoryModelEvent> events = new ArrayList<RepositoryModelEvent>();

    synchronized (reposLock) {
      Map<String, RepositoryDefinition> newRepos = loadRepositories(true);

      // Find out changes in repositories
      Set<String> removedRepos = Sets.difference(repos.keySet(), newRepos.keySet());
      for (String id : removedRepos) {
        events.add(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_REMOVED, id));
      }

      Set<String> addedRepos = Sets.difference(newRepos.keySet(), repos.keySet());
      for (String id : addedRepos) {
        events.add(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_ADDED, id));
      }

      for (RepositoryDefinition repoDef : newRepos.values()) {
        if (repos.containsKey(repoDef.getName()) && !repos.get(repoDef.getName()).equals(repoDef)) {
          events.add(
              new RepositoryModelEvent(
                  RepositoryModelEventType.REPOSITORY_UPDATED, repoDef.getName()));
        }
      }

      repos = newRepos;
    }

    notifyListeners(events);
  }
 @Override
 public void updateRepository(RepositoryDefinition repoDef)
     throws InterruptedException, RepositoryModelException, RepositoryNotFoundException {
   disallowDefaultRepository(repoDef.getName());
   try {
     storeRepository(repoDef);
   } catch (KeeperException.NoNodeException e) {
     throw new RepositoryNotFoundException(
         "Can't update repository, a repository with this name doesn't exist: "
             + repoDef.getName());
   } catch (KeeperException e) {
     throw new RepositoryModelException(e);
   }
 }
 private void assureDefaultRepositoryExists() throws KeeperException, InterruptedException {
   byte[] repoBytes = RepositoryDefinitionJsonSerDeser.INSTANCE.toJsonBytes(DEFAULT_REPOSITORY);
   try {
     zk.create(
         REPOSITORY_COLLECTION_PATH + "/" + DEFAULT_REPOSITORY.getName(),
         repoBytes,
         ZooDefs.Ids.OPEN_ACL_UNSAFE,
         CreateMode.PERSISTENT);
   } catch (KeeperException.NodeExistsException e) {
     // it already exists, fine
   }
 }
 @Override
 public void delete(String repositoryName)
     throws InterruptedException, RepositoryModelException, RepositoryNotFoundException {
   disallowDefaultRepository(repositoryName);
   RepositoryDefinition repoDef =
       new RepositoryDefinition(repositoryName, RepositoryLifecycleState.DELETE_REQUESTED);
   try {
     storeRepository(repoDef);
   } catch (KeeperException.NoNodeException e) {
     throw new RepositoryNotFoundException(
         "Can't delete-request repository, a repository with this name doesn't exist: "
             + repoDef.getName());
   } catch (KeeperException e) {
     throw new RepositoryModelException(e);
   }
 }
 public void storeRepository(RepositoryDefinition repoDef)
     throws InterruptedException, KeeperException {
   byte[] repoBytes = RepositoryDefinitionJsonSerDeser.INSTANCE.toJsonBytes(repoDef);
   zk.setData(REPOSITORY_COLLECTION_PATH + "/" + repoDef.getName(), repoBytes, -1);
 }
 private void disallowDefaultRepository(String repositoryName) throws RepositoryModelException {
   if (DEFAULT_REPOSITORY.getName().equals(repositoryName)) {
     throw new RepositoryModelException(
         "This operation is not allowed on the default repository.");
   }
 }