Jian Li | 1a42469 | 2016-02-03 16:21:18 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jian Li | 1a42469 | 2016-02-03 16:21:18 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.cpman.impl; |
| 17 | |
| 18 | import org.onosproject.cpman.SystemInfo; |
| 19 | |
Jian Li | 1a66d61 | 2016-02-20 13:31:27 +0900 | [diff] [blame] | 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
Jian Li | 1a42469 | 2016-02-03 16:21:18 -0800 | [diff] [blame] | 24 | /** |
| 25 | * Implementation class of storing system specification. |
| 26 | */ |
| 27 | public final class DefaultSystemInfo implements SystemInfo { |
Jian Li | 1a66d61 | 2016-02-20 13:31:27 +0900 | [diff] [blame] | 28 | private final int numOfCores; |
| 29 | private final int numOfCpus; |
| 30 | private final int cpuSpeedMhz; |
| 31 | private final int totalMemoryMbytes; |
Jian Li | 1a42469 | 2016-02-03 16:21:18 -0800 | [diff] [blame] | 32 | |
| 33 | private DefaultSystemInfo(int numOfCores, int numOfCpus, |
| 34 | int cpuSpeedMhz, int totalMemoryMbytes) { |
| 35 | this.numOfCores = numOfCores; |
| 36 | this.numOfCpus = numOfCpus; |
| 37 | this.cpuSpeedMhz = cpuSpeedMhz; |
| 38 | this.totalMemoryMbytes = totalMemoryMbytes; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public int coreCount() { |
| 43 | return this.numOfCores; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public int cpuCount() { |
| 48 | return this.numOfCpus; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public int cpuSpeed() { |
| 53 | return this.cpuSpeedMhz; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public int totalMemory() { |
| 58 | return this.totalMemoryMbytes; |
| 59 | } |
| 60 | |
Jian Li | 1a66d61 | 2016-02-20 13:31:27 +0900 | [diff] [blame] | 61 | |
| 62 | @Override |
| 63 | public int hashCode() { |
| 64 | return Objects.hash(numOfCores, numOfCpus, cpuSpeedMhz, totalMemoryMbytes); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public boolean equals(Object obj) { |
| 69 | if (this == obj) { |
| 70 | return true; |
| 71 | } |
| 72 | if (obj instanceof DefaultSystemInfo) { |
| 73 | final DefaultSystemInfo other = (DefaultSystemInfo) obj; |
| 74 | return Objects.equals(this.numOfCores, other.numOfCores) && |
| 75 | Objects.equals(this.numOfCpus, other.numOfCpus) && |
| 76 | Objects.equals(this.cpuSpeedMhz, other.cpuSpeedMhz) && |
| 77 | Objects.equals(this.totalMemoryMbytes, other.totalMemoryMbytes); |
| 78 | } |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public String toString() { |
| 84 | return toStringHelper(this) |
| 85 | .add("numOfCores", numOfCores) |
| 86 | .add("numOfCpus", numOfCpus) |
| 87 | .add("cpuSpeedMhz", cpuSpeedMhz) |
| 88 | .add("totalMemoryMbytes", totalMemoryMbytes) |
| 89 | .toString(); |
| 90 | } |
| 91 | |
Jian Li | 1a42469 | 2016-02-03 16:21:18 -0800 | [diff] [blame] | 92 | /** |
| 93 | * ControlMetricsSystemSpec builder class. |
| 94 | */ |
| 95 | public static final class Builder implements SystemInfo.Builder { |
| 96 | private int numOfCores; |
| 97 | private int numOfCpus; |
| 98 | private int cpuSpeedMHz; |
| 99 | private int totalMemoryBytes; |
| 100 | |
| 101 | @Override |
| 102 | public SystemInfo.Builder numOfCores(int numOfCores) { |
| 103 | this.numOfCores = numOfCores; |
| 104 | return this; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public Builder numOfCpus(int numOfCpus) { |
| 109 | this.numOfCpus = numOfCpus; |
| 110 | return this; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public Builder cpuSpeed(int cpuSpeedMhz) { |
| 115 | this.cpuSpeedMHz = cpuSpeedMhz; |
| 116 | return this; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public Builder totalMemory(int totalMemoryBytes) { |
| 121 | this.totalMemoryBytes = totalMemoryBytes; |
| 122 | return this; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public DefaultSystemInfo build() { |
| 127 | return new DefaultSystemInfo(numOfCores, numOfCpus, cpuSpeedMHz, totalMemoryBytes); |
| 128 | } |
| 129 | } |
| 130 | } |