]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/eclipse/aether/SyncContext.java
Start working on migration to new format.
[gpl/argeo-slc.git] / org.argeo.slc.repo / src / org / eclipse / aether / SyncContext.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 Sonatype, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.aether;
12
13 import java.io.Closeable;
14 import java.util.Collection;
15
16 import org.eclipse.aether.artifact.Artifact;
17 import org.eclipse.aether.metadata.Metadata;
18
19 /**
20 * A synchronization context used to coordinate concurrent access to artifacts or metadatas. The typical usage of a
21 * synchronization context looks like this:
22 *
23 * <pre>
24 * SyncContext syncContext = repositorySystem.newSyncContext( ... );
25 * try {
26 * syncContext.acquire( artifacts, metadatas );
27 * // work with the artifacts and metadatas
28 * } finally {
29 * syncContext.close();
30 * }
31 * </pre>
32 *
33 * Within one thread, synchronization contexts may be nested which can naturally happen in a hierarchy of method calls.
34 * The nested synchronization contexts may also acquire overlapping sets of artifacts/metadatas as long as the following
35 * conditions are met. If the outer-most context holding a particular resource is exclusive, that resource can be
36 * reacquired in any nested context. If however the outer-most context is shared, the resource may only be reacquired by
37 * nested contexts if these are also shared.
38 * <p>
39 * A synchronization context is meant to be utilized by only one thread and as such is not thread-safe.
40 * <p>
41 * Note that the level of actual synchronization is subject to the implementation and might range from OS-wide to none.
42 *
43 * @see RepositorySystem#newSyncContext(RepositorySystemSession, boolean)
44 */
45 public interface SyncContext
46 extends Closeable
47 {
48
49 /**
50 * Acquires synchronized access to the specified artifacts and metadatas. The invocation will potentially block
51 * until all requested resources can be acquired by the calling thread. Acquiring resources that are already
52 * acquired by this synchronization context has no effect. Please also see the class-level documentation for
53 * information regarding reentrancy. The method may be invoked multiple times on a synchronization context until all
54 * desired resources have been acquired.
55 *
56 * @param artifacts The artifacts to acquire, may be {@code null} or empty if none.
57 * @param metadatas The metadatas to acquire, may be {@code null} or empty if none.
58 */
59 void acquire( Collection<? extends Artifact> artifacts, Collection<? extends Metadata> metadatas );
60
61 /**
62 * Releases all previously acquired artifacts/metadatas. If no resources have been acquired before or if this
63 * synchronization context has already been closed, this method does nothing.
64 */
65 void close();
66
67 }