Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.core.impl; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 17 | |
| 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Reference; |
| 21 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 22 | import org.apache.felix.scr.annotations.Service; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.core.ApplicationIdStore; |
| 25 | import org.onosproject.core.CoreService; |
| 26 | import org.onosproject.core.IdBlockStore; |
| 27 | import org.onosproject.core.IdGenerator; |
| 28 | import org.onosproject.core.Version; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 29 | import org.onlab.util.Tools; |
| 30 | |
| 31 | import java.io.File; |
| 32 | import java.util.List; |
| 33 | import java.util.Set; |
| 34 | |
| 35 | import static com.google.common.base.Preconditions.checkNotNull; |
| 36 | |
| 37 | /** |
| 38 | * Core service implementation. |
| 39 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 40 | @Component(immediate = true) |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 41 | @Service |
| 42 | public class CoreManager implements CoreService { |
| 43 | |
| 44 | private static final File VERSION_FILE = new File("../VERSION"); |
Yuta HIGUCHI | 088e268 | 2015-02-02 15:03:17 -0800 | [diff] [blame] | 45 | private static Version version = Version.version("1.1.0-SNAPSHOT"); |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 46 | |
| 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 48 | protected ApplicationIdStore applicationIdStore; |
| 49 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 50 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 51 | protected IdBlockStore idBlockStore; |
| 52 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 53 | @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 Milkey | 0247986 | 2015-02-17 17:02:19 -0800 | [diff] [blame] | 77 | public ApplicationId getAppId(String name) { |
| 78 | return applicationIdStore.getAppId(name); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | @Override |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 83 | public ApplicationId registerApplication(String name) { |
| 84 | checkNotNull(name, "Application ID cannot be null"); |
| 85 | return applicationIdStore.registerApplication(name); |
| 86 | } |
| 87 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 88 | @Override |
| 89 | public IdGenerator getIdGenerator(String topic) { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 90 | IdBlockAllocator allocator = new StoreBasedIdBlockAllocator(topic, idBlockStore); |
| 91 | return new BlockAllocatorBasedIdGenerator(allocator); |
| 92 | } |
| 93 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 94 | } |