blob: a592801e7fd71bef2a4b901002be9b24db967078 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.core.impl;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070017
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Reference;
21import org.apache.felix.scr.annotations.ReferenceCardinality;
22import org.apache.felix.scr.annotations.Service;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.core.ApplicationId;
24import org.onosproject.core.ApplicationIdStore;
25import org.onosproject.core.CoreService;
26import org.onosproject.core.IdBlockStore;
27import org.onosproject.core.IdGenerator;
28import org.onosproject.core.Version;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070029import org.onlab.util.Tools;
30
31import java.io.File;
32import java.util.List;
33import java.util.Set;
34
35import static com.google.common.base.Preconditions.checkNotNull;
36
37/**
38 * Core service implementation.
39 */
Brian O'Connor520c0522014-11-23 23:50:47 -080040@Component(immediate = true)
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070041@Service
42public class CoreManager implements CoreService {
43
44 private static final File VERSION_FILE = new File("../VERSION");
Yuta HIGUCHI088e2682015-02-02 15:03:17 -080045 private static Version version = Version.version("1.1.0-SNAPSHOT");
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070046
47 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 protected ApplicationIdStore applicationIdStore;
49
Brian O'Connor520c0522014-11-23 23:50:47 -080050 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
51 protected IdBlockStore idBlockStore;
52
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070053 @Activate
54 public void activate() {
55 List<String> versionLines = Tools.slurp(VERSION_FILE);
56 if (versionLines != null && !versionLines.isEmpty()) {
57 version = Version.version(versionLines.get(0));
58 }
59 }
60
61 @Override
62 public Version version() {
63 return version;
64 }
65
66 @Override
67 public Set<ApplicationId> getAppIds() {
68 return applicationIdStore.getAppIds();
69 }
70
71 @Override
72 public ApplicationId getAppId(Short id) {
73 return applicationIdStore.getAppId(id);
74 }
75
76 @Override
Ray Milkey02479862015-02-17 17:02:19 -080077 public ApplicationId getAppId(String name) {
78 return applicationIdStore.getAppId(name);
79 }
80
81
82 @Override
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070083 public ApplicationId registerApplication(String name) {
84 checkNotNull(name, "Application ID cannot be null");
85 return applicationIdStore.registerApplication(name);
86 }
87
Brian O'Connor520c0522014-11-23 23:50:47 -080088 @Override
89 public IdGenerator getIdGenerator(String topic) {
Brian O'Connor520c0522014-11-23 23:50:47 -080090 IdBlockAllocator allocator = new StoreBasedIdBlockAllocator(topic, idBlockStore);
91 return new BlockAllocatorBasedIdGenerator(allocator);
92 }
93
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070094}