Jian Li | e044d1a | 2016-01-25 09:01:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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 | */ |
Jian Li | 6b86a76 | 2016-01-29 09:30:40 -0800 | [diff] [blame] | 16 | package org.onosproject.cpman.impl; |
Jian Li | e044d1a | 2016-01-25 09:01:20 -0800 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Control metrics class for storing system specification. |
| 20 | */ |
| 21 | public final class ControlMetricsSystemSpec { |
| 22 | private int numOfCores; |
| 23 | private int numOfCpus; |
| 24 | private int cpuSpeed; // in MHz |
| 25 | private long totalMemory; // in bytes |
| 26 | |
| 27 | private ControlMetricsSystemSpec(int numOfCores, int numOfCpus, |
| 28 | int cpuSpeed, long totalMemory) { |
| 29 | this.numOfCores = numOfCores; |
| 30 | this.numOfCpus = numOfCpus; |
| 31 | this.cpuSpeed = cpuSpeed; |
| 32 | this.totalMemory = totalMemory; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Returns number of CPU cores. |
| 37 | * |
| 38 | * @return number of CPU cores |
| 39 | */ |
| 40 | public int numOfCores() { |
| 41 | return this.numOfCores; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns number of CPUs. |
| 46 | * |
| 47 | * @return number of CPUs |
| 48 | */ |
| 49 | public int numOfCpus() { |
| 50 | return this.numOfCpus; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns CPU speed in MHz. |
| 55 | * |
| 56 | * @return CPU speed |
| 57 | */ |
| 58 | public int cpuSpeed() { |
| 59 | return this.cpuSpeed; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns the total amount of memory. |
| 64 | * |
| 65 | * @return memory size |
| 66 | */ |
| 67 | public long totalMemory() { |
| 68 | return this.totalMemory; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * ControlMetricsSystemSpec builder class. |
| 73 | */ |
| 74 | public static final class Builder { |
| 75 | private int numOfCores; |
| 76 | private int numOfCpus; |
| 77 | private int cpuSpeed; // in MHz |
| 78 | private long totalMemory; // in bytes |
| 79 | |
| 80 | /** |
| 81 | * Sets number of CPU cores. |
| 82 | * |
| 83 | * @param numOfCores number of CPU cores |
| 84 | * @return Builder object |
| 85 | */ |
| 86 | public Builder numOfCores(int numOfCores) { |
| 87 | this.numOfCores = numOfCores; |
| 88 | return this; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Sets number of CPUs. |
| 93 | * @param numOfCpus number of CPUs |
| 94 | * @return Builder object |
| 95 | */ |
| 96 | public Builder numOfCpus(int numOfCpus) { |
| 97 | this.numOfCpus = numOfCpus; |
| 98 | return this; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Sets CPU speed. |
| 103 | * |
| 104 | * @param cpuSpeed CPU speed |
| 105 | * @return Builder object |
| 106 | */ |
| 107 | public Builder cpuSpeed(int cpuSpeed) { |
| 108 | this.cpuSpeed = cpuSpeed; |
| 109 | return this; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Sets total amount of memory. |
| 114 | * |
| 115 | * @param totalMemory memory size |
| 116 | * @return Builder object |
| 117 | */ |
| 118 | public Builder totalMemory(long totalMemory) { |
| 119 | this.totalMemory = totalMemory; |
| 120 | return this; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Builds a ControlMetricsSystemSpec object. |
| 125 | * |
| 126 | * @return ControlMetricsSystemSpec object |
| 127 | */ |
| 128 | public ControlMetricsSystemSpec build() { |
| 129 | return new ControlMetricsSystemSpec(numOfCores, numOfCpus, cpuSpeed, totalMemory); |
| 130 | } |
| 131 | } |
| 132 | } |