提交 a398cabd 编写于 作者: J Jesse Glick

Make WorkspaceList.Lease implement AutoCloseable for Java 7 callers, to make...

Make WorkspaceList.Lease implement AutoCloseable for Java 7 callers, to make releasing the lease more convenient.
上级 62af87b6
......@@ -26,10 +26,12 @@ package hudson.slaves;
import hudson.FilePath;
import hudson.Functions;
import hudson.model.Computer;
import java.io.Closeable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
......@@ -104,7 +106,7 @@ public final class WorkspaceList {
/**
* Represents a leased workspace that needs to be returned later.
*/
public static abstract class Lease {
public static abstract class Lease implements /*Auto*/Closeable {
public final @Nonnull FilePath path;
protected Lease(@Nonnull FilePath path) {
......@@ -117,6 +119,14 @@ public final class WorkspaceList {
*/
public abstract void release();
/**
* By default, calls {@link #release}, but should be idempotent.
* @since TODO
*/
@Override public void close() {
release();
}
/**
* Creates a dummy {@link Lease} object that does no-op in the release.
*/
......@@ -261,9 +271,15 @@ public final class WorkspaceList {
*/
private Lease lease(@Nonnull FilePath p) {
return new Lease(p) {
final AtomicBoolean released = new AtomicBoolean();
public void release() {
_release(path);
}
@Override public void close() {
if (released.compareAndSet(false, true)) {
release();
}
}
};
}
......
......@@ -51,7 +51,7 @@ public class BuildExecutionTest {
try {
assertEquals(ws, lease.path);
} finally {
lease.release();
lease.close();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册