01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.plugins.lock;
19:
20: import java.io.File;
21:
22: import org.apache.ivy.core.module.descriptor.Artifact;
23:
24: /**
25: * A lock strategy determines when and how lock should be performed when downloading data to a
26: * cache.
27: * <p>
28: * Note that some implementations may actually choose to NOT perform locking, when no lock is
29: * necessary (cache not shared). Some other implementations may choose to lock the cache for the
30: * download of a whole module (not possible yet), or at the artifact level.
31: * <p>
32: * </p>
33: * The lock methods should return true when the lock is either actually acquired or not performed by
34: * the strategy.
35: * </p>
36: * <p>
37: * Locking used in the locking strategy must support reentrant lock. Reentrant locking should be
38: * performed for the whole strategy.
39: * </p>
40: */
41: public interface LockStrategy {
42:
43: /**
44: * Returns the name of the strategy
45: * @return the name of the strategy
46: */
47: String getName();
48:
49: /**
50: * Performs a lock before downloading the given {@link Artifact} to the given file.
51: *
52: * @param artifact
53: * the artifact about to be downloaded
54: * @param artifactFileToDownload
55: * the file where the artifact will be downloaded
56: * @return true if the artifact is locked, false otherwise
57: * @throws InterruptedException
58: * if the thread is interrupted while waiting to acquire the lock
59: */
60: boolean lockArtifact(Artifact artifact, File artifactFileToDownload)
61: throws InterruptedException;
62:
63: /**
64: * Release the lock acquired for an artifact download.
65: *
66: * @param artifact
67: * the artifact for which the lock was acquired
68: * @param artifactFileToDownload
69: * the file where the artifact is supposed to have been downloaded
70: */
71: void unlockArtifact(Artifact artifact, File artifactFileToDownload);
72:
73: }
|