/hudson-core/src/main/java/hudson/model/queue/WorkUnit.java

http://github.com/hudson/hudson · Java · 95 lines · 34 code · 11 blank · 50 comment · 0 complexity · c03febb4ffa4a0ea4620f30da036e727 MD5 · raw file

  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2010, InfraDNA, Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package hudson.model.queue;
  25. import hudson.model.Executor;
  26. import hudson.model.Queue;
  27. import hudson.model.Queue.Executable;
  28. import hudson.model.Queue.Task;
  29. import org.kohsuke.stapler.export.ExportedBean;
  30. /**
  31. * Represents a unit of hand-over to {@link Executor} from {@link Queue}.
  32. *
  33. * @author Kohsuke Kawaguchi
  34. * @since 1.377
  35. */
  36. @ExportedBean
  37. public final class WorkUnit {
  38. /**
  39. * Task to be executed.
  40. */
  41. //TODO: review and check whether we can do it private
  42. public final SubTask work;
  43. /**
  44. * Shared context among {@link WorkUnit}s.
  45. */
  46. //TODO: review and check whether we can do it private
  47. public final WorkUnitContext context;
  48. private volatile Executor executor;
  49. WorkUnit(WorkUnitContext context, SubTask work) {
  50. this.context = context;
  51. this.work = work;
  52. }
  53. public SubTask getWork() {
  54. return work;
  55. }
  56. public WorkUnitContext getContext() {
  57. return context;
  58. }
  59. /**
  60. * {@link Executor} running this work unit.
  61. * <p>
  62. * {@link Executor#getCurrentWorkUnit()} and {@link WorkUnit#getExecutor()}
  63. * form a bi-directional reachability between them.
  64. */
  65. public Executor getExecutor() {
  66. return executor;
  67. }
  68. public void setExecutor(Executor e) {
  69. executor = e;
  70. }
  71. /**
  72. * If the execution has already started, return the current executable.
  73. */
  74. public Executable getExecutable() {
  75. return executor!=null ? executor.getCurrentExecutable() : null;
  76. }
  77. /**
  78. * Is this work unit the "main work", which is the primary {@link SubTask}
  79. * represented by {@link Task} itself.
  80. */
  81. public boolean isMainWork() {
  82. return context.task==work;
  83. }
  84. }