/src/main/java/nl/bitbrains/nebu/common/topology/PhysicalHost.java

https://github.com/deltaforge/nebu-common-java · Java · 93 lines · 43 code · 12 blank · 38 comment · 1 complexity · f747ba4974f51cc3eefdcd48a6755de9 MD5 · raw file

  1. package nl.bitbrains.nebu.common.topology;
  2. import java.util.Map;
  3. /**
  4. * This class represents a physical CPU placed inside a physical rack. Each
  5. * PhysicalCPU has a PhysicalRack parent and has a unique identifier through the
  6. * Identifiable interface.
  7. *
  8. * @author Jesse Donkervliet, Tim Hegeman, and Stefan Hugtenburg
  9. */
  10. public class PhysicalHost extends PhysicalResourceWithDisks {
  11. private PhysicalRack parent;
  12. private final double memUsage;
  13. private final double cpuUsage;
  14. /**
  15. * @param identifier
  16. * the unique identifier for the new PhysicalCPU.
  17. * @param parent
  18. * the parent of this new PhysicalCPU.
  19. * @param disks
  20. * the disks attached to this CPU.
  21. * @param cpuUsage
  22. * to set.
  23. * @param memUsage
  24. * to set.
  25. */
  26. protected PhysicalHost(final String identifier, final PhysicalRack parent,
  27. final Map<String, PhysicalStore> disks, final double cpuUsage, final double memUsage) {
  28. super(identifier, disks);
  29. this.parent = parent;
  30. this.cpuUsage = cpuUsage;
  31. this.memUsage = memUsage;
  32. }
  33. /**
  34. * Copyconstructor.
  35. *
  36. * @param other
  37. * cpu to adopt.
  38. */
  39. public PhysicalHost(final PhysicalHost other) {
  40. super(other.getUniqueIdentifier(), other.getDisks());
  41. this.cpuUsage = other.cpuUsage;
  42. this.memUsage = other.memUsage;
  43. }
  44. /**
  45. * @return the parent of this PhysicalCPU.
  46. */
  47. public PhysicalRack getParent() {
  48. return this.parent;
  49. }
  50. /**
  51. * @param parent
  52. * the new parent of the PhysicalCPU.
  53. */
  54. protected void setParent(final PhysicalRack parent) {
  55. this.parent = parent;
  56. }
  57. /**
  58. * @return the cpu usage. Number between 0 and 1.
  59. */
  60. public double getCpuUsage() {
  61. return this.cpuUsage;
  62. }
  63. /**
  64. * @return the memory usage. Number between 0 and 1.
  65. */
  66. public double getMemUsage() {
  67. return this.memUsage;
  68. }
  69. @Override
  70. public int hashCode() {
  71. return this.getUniqueIdentifier().hashCode();
  72. }
  73. @Override
  74. public boolean equals(final Object obj) {
  75. if (obj instanceof PhysicalHost) {
  76. final PhysicalHost that = (PhysicalHost) obj;
  77. return this.getUniqueIdentifier().equals(that.getUniqueIdentifier());
  78. }
  79. return false;
  80. }
  81. }