blob: 32ae426ebb5230c0e044fe7d89688a1abcd139fe [file] [log] [blame]
Jian Li1a424692016-02-03 16:21:18 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jian Li1a424692016-02-03 16:21:18 -08003 *
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 */
16package org.onosproject.cpman.impl;
17
18import org.onosproject.cpman.SystemInfo;
19import org.slf4j.Logger;
20
21import static org.slf4j.LoggerFactory.getLogger;
22
23/**
24 * A factory class which instantiates a system info object.
25 */
26public final class SystemInfoFactory {
27
28 private final Logger log = getLogger(getClass());
29
30 private SystemInfo systemInfo;
31
32 // non-instantiable (except for our Singleton)
33 private SystemInfoFactory() {
34 }
35
36 /**
37 * Returns system information.
38 *
39 * @return reference object of system info
40 */
41 public SystemInfo getSystemInfo() {
42 synchronized (systemInfo) {
43 return this.systemInfo;
44 }
45 }
46
47 /**
48 * Set system information only if it is empty.
49 *
50 * @param systemInfo reference object of system info
51 */
52 public void setSystemInfo(SystemInfo systemInfo) {
53 synchronized (systemInfo) {
54 if (this.systemInfo == null) {
55 this.systemInfo = systemInfo;
56 } else {
57 log.warn("System information has already been set");
58 }
59 }
60 }
61
62 /**
63 * Returns an instance of system info factory.
64 *
65 * @return instance of system info factory
66 */
67 public static SystemInfoFactory getInstance() {
68 return SingletonHelper.INSTANCE;
69 }
70
71 private static class SingletonHelper {
72 private static final SystemInfoFactory INSTANCE = new SystemInfoFactory();
73 }
74}