Package hudson.slaves

Class WorkspaceList

java.lang.Object
hudson.slaves.WorkspaceList

public final class WorkspaceList extends Object
Used by Computer to keep track of workspaces that are actively in use.
Since:
1.319
Author:
Kohsuke Kawaguchi
See Also:
  • Field Details

    • COMBINATOR

      public static final String COMBINATOR
      The token that combines the project name and unique number to create unique workspace directory.
      Since:
      2.244
    • TMP_DIR_SUFFIX

      public static final String TMP_DIR_SUFFIX
      Suffix for temporary folders.
  • Constructor Details

    • WorkspaceList

      public WorkspaceList()
  • Method Details

    • allocate

      public WorkspaceList.Lease allocate(@NonNull FilePath base) throws InterruptedException
      Allocates a workspace by adding some variation to the given base to make it unique.

      This method doesn't block prolonged amount of time. Whenever a desired workspace is in use, the unique variation is added.

      Throws:
      InterruptedException
    • allocate

      public WorkspaceList.Lease allocate(@NonNull FilePath base, Object context) throws InterruptedException
      Parameters:
      context - Threads that share the same context can re-acquire the same lock (which will just increment the lock count.) This allows related executors to share the same workspace.
      Throws:
      InterruptedException
    • record

      public WorkspaceList.Lease record(@NonNull FilePath p)
      Just record that this workspace is being used, without paying any attention to the synchronization support.
    • acquire

      public WorkspaceList.Lease acquire(@NonNull FilePath p) throws InterruptedException
      Acquires the given workspace. If necessary, this method blocks until it's made available.
      Returns:
      The same FilePath as given to this method.
      Throws:
      InterruptedException
    • acquire

      public WorkspaceList.Lease acquire(@NonNull FilePath p, boolean quick) throws InterruptedException
      Parameters:
      quick - If true, indicates that the acquired workspace will be returned quickly. This makes other calls to allocate(FilePath) to wait for the release of this workspace.
      Throws:
      InterruptedException
    • acquire

      public WorkspaceList.Lease acquire(@NonNull FilePath p, boolean quick, Object context) throws InterruptedException
      Parameters:
      context - Threads that share the same context can re-acquire the same lock (which will just increment the lock count.) This allows related executors to share the same workspace.
      Throws:
      InterruptedException
    • tempDir

      @CheckForNull public static FilePath tempDir(FilePath ws)
      Locates a conventional temporary directory to be associated with a workspace.

      This directory is suitable for temporary files to be deleted later in the course of a build, or caches and local repositories which should persist across builds done in the same workspace. (If multiple workspaces are present for a single job built concurrently, via allocate(FilePath), each will get its own temporary directory.)

      It may also be used for security-sensitive files which DirectoryBrowserSupport ought not serve, acknowledging that these will be readable by builds of other jobs done on the same node.

      Each plugin using this directory is responsible for specifying sufficiently unique subdirectory/file names. FilePath.createTempFile(java.lang.String, java.lang.String) may be used for this purpose if desired.

      The resulting directory may not exist; you may call FilePath.mkdirs() on it if you need it to. It may be deleted alongside the workspace itself during cleanup actions.

      Parameters:
      ws - a directory such as a build workspace
      Returns:
      a sibling directory, for example …/something@tmp for …/something, or null if FilePath.getParent() is null
      Since:
      1.652