Package com.kolich.havalo.entities.types

Examples of com.kolich.havalo.entities.types.Repository


  public Repository createRepository(final HavaloUUID id,
    final KeyPair keyPair) {
    // Get a proper pointer to this Repository.  Do not fail
    // if the underlying File (directory) is not found yet -- it
    // won't exist yet because it hasn't been created.
    final Repository repo = getRepository(id, false);
    try {
      // Grab an exclusive "write" lock on the Repository and
      // attempt to actually create the corresponding/underlying
      // directory on disk.
      return new ReentrantReadWriteEntityLock<Repository>(repo) {
        @Override
        public Repository transaction() throws Exception {
          // Attempt to create the repository directory if it does
          // not already exist (it shouldn't).
          if(repo.getFile().exists()) {
            throw new DuplicateRepositoryException("Repository " +
              "already exists (file=" +
                repo.getFile().getAbsolutePath() + ", id=" +
                  repo.getRepoId() + ")");
          }
          // Create the new directory (and any required parent
          // directories).
          forceMkdir(repo.getFile());
          // Set the access key pair on this repository to the one
          // provided by the caller.
          repo.setKeyPair(keyPair);
          return repo;
        }
        @Override
        public void success(final Repository repo) throws Exception {         
          // Queue the repository to be flushed to disk.
View Full Code Here


      // "Cache" should be thread safe, and therefore, wrapping accesses
      // to a Cache instance with synchronized is unnecessary.
      return repositories_.get(id, new Callable<Repository>() {
        @Override
        public Repository call() throws Exception {
          Repository repo = null;
          final File repoFile = getCanonicalObject(storeDir_,
            id.toString(), false).getFile();
          if(repoFile.exists()) {
            // Repository already exists. Load from disk.
            repo = metaStore_.loadById(id);
          } else if(!repoFile.exists() && !failIfNotFound) {
            // The repository does not exist, and we are not
            // supposed to fail.  Create a new one!
            repo = new Repository(
              // Canonical File pointing at the repo directory
              repoFile,
              // Owner ID
              id);
          } else {
View Full Code Here

    metaWriter_ = metaWriter;
  }

  @Override
  public void onRemoval(final RemovalNotification<HavaloUUID,Repository> removed) {
    Repository repo = null;
    try {
      // The repo that was "evicted" could be null if it was
      // garbage collected between the time it was evicted
      // and this listener was called.  This should _not_
      // happen given that we've asked the Cache to maintain
      // _STRONG_ references to the keys and values in the
      // cache, but we should check just in case.
      if((repo = removed.getValue()) != null) {
        // If the repository directory has been deleted (invalidated),
        // we should not attempt to flush the meta data for it
        // to disk -- the underlying repository has been deleted.
        if(repo.getFile().exists()) {
          // Queue the repository to be flushed to disk.
          metaWriter_.queue(repo);
        } else {
          logger__.debug("Not flushing repo meta " +
            "data, underlying repo directory is " +
            "missing (id=" + repo.getKey() + ", " +
            "file=" + repo.getFile().getCanonicalPath() +
            ") -- was probably for a deleted repository.");
        }
      } else {
        // Should really _not_ happen based on the notes
        // provided above.
        throw new RepositoryFlushException("Could not " +
          "flush NULL repository -- was perhaps " +
            "already GC'ed?");
      }
    } catch (Exception e) {
      logger__.error("Failed miserably to flush repository " +
        "(id=" + ((repo != null) ? repo.getRepoId() : "NULL") +
          ") -- could be trouble!", e);
    }
  }
View Full Code Here

                    value="/api/repository",
                    matcher=AntPathMatcher.class,
                    filters=HavaloAuthenticationFilter.class)
    public final ObjectList get(@Query("startsWith") final String startsWith,
                                final KeyPair userKp) throws Exception {
        final Repository repo = getRepository(userKp.getKey());
        return new ReentrantReadWriteEntityLock<ObjectList>(repo) {
            @Override
            public ObjectList transaction() throws Exception {
                return repo.startsWith((startsWith != null) ?
                    // Only load objects that start with the given
                    // prefix, if one was provided.
                    startsWith : "");
            }
        }.read(false); // Shared read lock on repo, no wait
View Full Code Here

                    filters=HavaloAuthenticationFilter.class)
    public final void head(final ObjectKey key,
                           final KeyPair userKp,
                           final HttpServletResponse response,
                           final AsyncContext context) throws Exception {
        final Repository repo = getRepository(userKp.getKey());
        new ReentrantReadWriteEntityLock<Void>(repo) {
            @Override
            public Void transaction() throws Exception {
                final HashedFileObject hfo = getHashedFileObject(repo,
                    // The URL-decoded key of the object to delete.
View Full Code Here

                    filters=HavaloAuthenticationFilter.class)
    public final void get(final ObjectKey key,
                          final KeyPair userKp,
                          final HttpServletResponse response,
                          final AsyncContext context) throws Exception {
        final Repository repo = getRepository(userKp.getKey());
        new ReentrantReadWriteEntityLock<Void>(repo) {
            @Override
            public Void transaction() throws Exception {
                final HashedFileObject hfo = getHashedFileObject(repo,
                    // The URL-decoded key of the object to delete.
View Full Code Here

                                      @IfMatch final String ifMatch,
                                      @ContentType final String contentType,
                                      @ContentLength final Long contentLength,
                                      final HttpServletRequest request,
                                      final HttpServletResponse response) throws Exception {
        final Repository repo = getRepository(userKp.getKey());
        return new ReentrantReadWriteEntityLock<HashedFileObject>(repo) {
            @Override
            public HashedFileObject transaction() throws Exception {
                // Havalo requires the consumer to send a Content-Length
                // request header with the request when uploading an
View Full Code Here

TOP

Related Classes of com.kolich.havalo.entities.types.Repository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.