1
2
3
4
5 package oshi.hardware.common;
6
7 import static oshi.util.Memoizer.memoize;
8
9 import java.util.List;
10 import java.util.function.Supplier;
11
12 import oshi.annotation.concurrent.ThreadSafe;
13 import oshi.hardware.CentralProcessor;
14 import oshi.hardware.ComputerSystem;
15 import oshi.hardware.GlobalMemory;
16 import oshi.hardware.HardwareAbstractionLayer;
17 import oshi.hardware.NetworkIF;
18 import oshi.hardware.Sensors;
19
20
21
22
23 @ThreadSafe
24 public abstract class AbstractHardwareAbstractionLayer implements HardwareAbstractionLayer {
25
26 private final Supplier<ComputerSystem> computerSystem = memoize(this::createComputerSystem);
27
28 private final Supplier<CentralProcessor> processor = memoize(this::createProcessor);
29
30 private final Supplier<GlobalMemory> memory = memoize(this::createMemory);
31
32 private final Supplier<Sensors> sensors = memoize(this::createSensors);
33
34 @Override
35 public ComputerSystem getComputerSystem() {
36 return computerSystem.get();
37 }
38
39
40
41
42
43
44 protected abstract ComputerSystem createComputerSystem();
45
46 @Override
47 public CentralProcessor getProcessor() {
48 return processor.get();
49 }
50
51
52
53
54
55
56 protected abstract CentralProcessor createProcessor();
57
58 @Override
59 public GlobalMemory getMemory() {
60 return memory.get();
61 }
62
63
64
65
66
67
68 protected abstract GlobalMemory createMemory();
69
70 @Override
71 public Sensors getSensors() {
72 return sensors.get();
73 }
74
75
76
77
78
79
80 protected abstract Sensors createSensors();
81
82 @Override
83 public List<NetworkIF> getNetworkIFs() {
84 return getNetworkIFs(false);
85 }
86 }