/hudson-core/src/main/java/hudson/slaves/AbstractCloudImpl.java

http://github.com/hudson/hudson · Java · 53 lines · 26 code · 7 blank · 20 comment · 3 complexity · eac75d64fa1c3e5c7e8cfa05b153caa3 MD5 · raw file

  1. package hudson.slaves;
  2. /**
  3. * Additional convenience implementation on top of {@link Cloud} that are likely useful to
  4. * typical {@link Cloud} implementations.
  5. *
  6. * <p>
  7. * Whereas {@link Cloud} is the contract between the rest of Hudson and a cloud implementation,
  8. * this class focuses on providing a convenience to minimize the effort it takes to integrate
  9. * a new cloud to Hudson.
  10. *
  11. * @author Kohsuke Kawaguchi
  12. */
  13. public abstract class AbstractCloudImpl extends Cloud {
  14. /**
  15. * Upper bound on how many instances we may provision.
  16. */
  17. private int instanceCap;
  18. protected AbstractCloudImpl(String name, String instanceCapStr) {
  19. super(name);
  20. setInstanceCapStr(instanceCapStr);
  21. }
  22. protected void setInstanceCapStr(String value) {
  23. if(value==null || value.equals(""))
  24. this.instanceCap = Integer.MAX_VALUE;
  25. else
  26. this.instanceCap = Integer.parseInt(value);
  27. }
  28. /**
  29. * Gets the instance cap as string. Used primarily for form binding.
  30. */
  31. public String getInstanceCapStr() {
  32. if(instanceCap==Integer.MAX_VALUE)
  33. return "";
  34. else
  35. return String.valueOf(instanceCap);
  36. }
  37. /**
  38. * Gets the instance cap as int, where the capless is represented as {@link Integer#MAX_VALUE}
  39. */
  40. public int getInstanceCap() {
  41. return instanceCap;
  42. }
  43. protected void setInstanceCap(int v) {
  44. this.instanceCap = v;
  45. }
  46. }