コード例 #1
0
  /**
   * Handles packets received from the repository after the start write request. It's looking for a
   * RepoInfo packet indicating a repository has responded.
   */
  public Interest handleContent(ContentObject co, Interest interest) {

    if (Log.isLoggable(Log.FAC_REPO, Level.INFO))
      Log.info(Log.FAC_REPO, "handleContent: got potential repo message: {0}", co.name());
    if (co.signedInfo().getType() != ContentType.DATA) return null;
    RepositoryInfo repoInfo = new RepositoryInfo();
    try {
      repoInfo.decode(co.content());
      switch (repoInfo.getType()) {
        case INFO:
          for (Client client : _clients) {
            if (client._name.isPrefixOf(co.name())) {
              if (Log.isLoggable(Log.FAC_REPO, Level.FINE))
                Log.fine(Log.FAC_REPO, "Marked client {0} initialized", client._name);
              synchronized (this) {
                client._initialized = true;
                notifyAll();
              }
            }
          }
          break;
        default:
          break;
      }
    } catch (ContentDecodingException e) {
      Log.info(
          Log.FAC_REPO,
          "ContentDecodingException parsing RepositoryInfo: {0} from content object {1}, skipping.",
          e.getMessage(),
          co.name());
    }

    return null;
  }
コード例 #2
0
 RepositoryInfo findOrCreateByLocation(final URI repositoryURI) {
   List<RepositoryInfo> repos = getAll();
   for (RepositoryInfo info : repos) {
     if (Objects.equal(info.getLocation(), repositoryURI)) {
       return info;
     }
   }
   RepositoryInfo info = new RepositoryInfo();
   info.setLocation(repositoryURI);
   return save(info);
 }
コード例 #3
0
  public RepositoryInfo save(RepositoryInfo info) {
    Preconditions.checkNotNull(info.getLocation());
    if (info.getId() == null) {
      create(info);
    } else {
      // see if the name has changed. If so, update the repo config
      try {
        RepositoryInfo currentInfo = get(info.getId());
        handleRepoRename(currentInfo, info);
      } catch (IOException ioe) {

      }
    }
    // so far we don't need to invalidate the GeoGIG instance from the cache here... re-evaluate
    // if any configuration option would require so in the future
    return store.save(info);
  }
コード例 #4
0
  private void create(final RepositoryInfo repoInfo) {
    // File targetDirectory = new File(repoInfo.getLocation());
    // Preconditions.checkArgument(!isGeogigDirectory(targetDirectory));

    URI repoURI = repoInfo.getLocation();
    RepositoryResolver resolver = RepositoryResolver.lookup(repoURI);
    if (!resolver.repoExists(repoURI)) {
      Hints hints = new Hints();
      hints.set(Hints.REPOSITORY_URL, repoURI);
      hints.set(Hints.REPOSITORY_NAME, repoInfo.getRepoName());
      Context context = GlobalContextBuilder.builder().build(hints);
      GeoGIG geogig = new GeoGIG(context);
      try {
        Repository repository = geogig.command(InitOp.class).call();
        Preconditions.checkState(repository != null);
      } finally {
        geogig.close();
      }
    }
  }
コード例 #5
0
 private void handleRepoRename(RepositoryInfo oldRepo, RepositoryInfo newRepo) {
   if (Objects.equal(oldRepo.getId(), newRepo.getId())) {
     // repos have the same ID, check the names
     final String oldName = oldRepo.getRepoName();
     final String newName = newRepo.getRepoName();
     if (!Objects.equal(oldName, newName)) {
       // name has been changed, update the repo
       try {
         getRepository(oldRepo.getId())
             .command(ConfigOp.class)
             .setAction(ConfigOp.ConfigAction.CONFIG_SET)
             .setName("repo.name")
             .setScope(ConfigOp.ConfigScope.LOCAL)
             .setValue(newName)
             .call();
       } catch (IOException ioe) {
         // log?
       }
     }
   }
 }
 /**
  * Gets current repository information to be used as content in a ContentObject
  *
  * @param names intended for nonimplemented repository ACK protocol - currently unused
  */
 public RepositoryInfoObject getRepoInfo(
     ContentName name, String info, ArrayList<ContentName> names) {
   try {
     RepositoryInfo rri = _info;
     if (names != null || info != null) {
       if (names != null)
         rri =
             new RepositoryInfo(
                 getVersion(), _info.getGlobalPrefix(), _info.getLocalName(), names);
       else
         rri =
             new RepositoryInfo(getVersion(), _info.getGlobalPrefix(), _info.getLocalName(), info);
     }
     RepositoryInfoObject rio = new RepositoryInfoObject(name, rri, SaveType.RAW, _handle);
     rio.setFreshnessSeconds(12); // Same time as repo will express interest
     return rio;
   } catch (Exception e) {
     Log.logStackTrace(Level.WARNING, e);
     e.printStackTrace();
   }
   return null;
 }