PageRenderTime 14ms CodeModel.GetById 9ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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