View Javadoc
1   package org.eclipse.aether;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.Closeable;
23  import java.util.Collection;
24  
25  import org.eclipse.aether.artifact.Artifact;
26  import org.eclipse.aether.metadata.Metadata;
27  
28  /**
29   * A synchronization context used to coordinate concurrent access to artifacts or metadatas. The typical usage of a
30   * synchronization context looks like this:
31   * 
32   * <pre>
33   * SyncContext syncContext = repositorySystem.newSyncContext( ... );
34   * try {
35   *     syncContext.acquire( artifacts, metadatas );
36   *     // work with the artifacts and metadatas
37   * } finally {
38   *     syncContext.close();
39   * }
40   * </pre>
41   * 
42   * Within one thread, synchronization contexts may be nested which can naturally happen in a hierarchy of method calls.
43   * The nested synchronization contexts may also acquire overlapping sets of artifacts/metadatas as long as the following
44   * conditions are met. If the outer-most context holding a particular resource is exclusive, that resource can be
45   * reacquired in any nested context. If however the outer-most context is shared, the resource may only be reacquired by
46   * nested contexts if these are also shared.
47   * <p>
48   * A synchronization context is meant to be utilized by only one thread and as such is not thread-safe.
49   * <p>
50   * Note that the level of actual synchronization is subject to the implementation and might range from OS-wide to none.
51   * 
52   * @see RepositorySystem#newSyncContext(RepositorySystemSession, boolean)
53   */
54  public interface SyncContext
55      extends Closeable
56  {
57  
58      /**
59       * Acquires synchronized access to the specified artifacts and metadatas. The invocation will potentially block
60       * until all requested resources can be acquired by the calling thread. Acquiring resources that are already
61       * acquired by this synchronization context has no effect. Please also see the class-level documentation for
62       * information regarding reentrancy. The method may be invoked multiple times on a synchronization context until all
63       * desired resources have been acquired.
64       * 
65       * @param artifacts The artifacts to acquire, may be {@code null} or empty if none.
66       * @param metadatas The metadatas to acquire, may be {@code null} or empty if none.
67       */
68      void acquire( Collection<? extends Artifact> artifacts, Collection<? extends Metadata> metadatas );
69  
70      /**
71       * Releases all previously acquired artifacts/metadatas. If no resources have been acquired before or if this
72       * synchronization context has already been closed, this method does nothing.
73       */
74      void close();
75  
76  }