X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.repo%2Fsrc%2Forg%2Feclipse%2Faether%2FSyncContext.java;fp=org.argeo.slc.repo%2Fsrc%2Forg%2Feclipse%2Faether%2FSyncContext.java;h=a05d512fde67dccc8db1b82b5c1e0fea08dc2248;hb=825d60c5348dbe3f5be25b0bccf7bdebfe694219;hp=0000000000000000000000000000000000000000;hpb=5e991fff5cba01858dcc5747a27e637325bc5c8e;p=gpl%2Fargeo-jcr.git diff --git a/org.argeo.slc.repo/src/org/eclipse/aether/SyncContext.java b/org.argeo.slc.repo/src/org/eclipse/aether/SyncContext.java new file mode 100644 index 0000000..a05d512 --- /dev/null +++ b/org.argeo.slc.repo/src/org/eclipse/aether/SyncContext.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether; + +import java.io.Closeable; +import java.util.Collection; + +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.metadata.Metadata; + +/** + * A synchronization context used to coordinate concurrent access to artifacts or metadatas. The typical usage of a + * synchronization context looks like this: + * + *
+ * SyncContext syncContext = repositorySystem.newSyncContext( ... );
+ * try {
+ *     syncContext.acquire( artifacts, metadatas );
+ *     // work with the artifacts and metadatas
+ * } finally {
+ *     syncContext.close();
+ * }
+ * 
+ * + * Within one thread, synchronization contexts may be nested which can naturally happen in a hierarchy of method calls. + * The nested synchronization contexts may also acquire overlapping sets of artifacts/metadatas as long as the following + * conditions are met. If the outer-most context holding a particular resource is exclusive, that resource can be + * reacquired in any nested context. If however the outer-most context is shared, the resource may only be reacquired by + * nested contexts if these are also shared. + *

+ * A synchronization context is meant to be utilized by only one thread and as such is not thread-safe. + *

+ * Note that the level of actual synchronization is subject to the implementation and might range from OS-wide to none. + * + * @see RepositorySystem#newSyncContext(RepositorySystemSession, boolean) + */ +public interface SyncContext + extends Closeable +{ + + /** + * Acquires synchronized access to the specified artifacts and metadatas. The invocation will potentially block + * until all requested resources can be acquired by the calling thread. Acquiring resources that are already + * acquired by this synchronization context has no effect. Please also see the class-level documentation for + * information regarding reentrancy. The method may be invoked multiple times on a synchronization context until all + * desired resources have been acquired. + * + * @param artifacts The artifacts to acquire, may be {@code null} or empty if none. + * @param metadatas The metadatas to acquire, may be {@code null} or empty if none. + */ + void acquire( Collection artifacts, Collection metadatas ); + + /** + * Releases all previously acquired artifacts/metadatas. If no resources have been acquired before or if this + * synchronization context has already been closed, this method does nothing. + */ + void close(); + +}