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; |
Simon Hunt | 9fec43f | 2015-03-25 11:36:30 -0700 | [diff] [blame] | 23 | import org.onlab.util.Tools; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.core.ApplicationIdStore; |
| 26 | import org.onosproject.core.CoreService; |
| 27 | import org.onosproject.core.IdBlockStore; |
| 28 | import org.onosproject.core.IdGenerator; |
| 29 | import org.onosproject.core.Version; |
Thomas Vachuska | 8dc1a69 | 2015-03-31 01:01:37 -0700 | [diff] [blame^] | 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 32 | |
| 33 | import java.io.File; |
| 34 | import java.util.List; |
| 35 | import java.util.Set; |
| 36 | |
| 37 | import static com.google.common.base.Preconditions.checkNotNull; |
| 38 | |
| 39 | /** |
| 40 | * Core service implementation. |
| 41 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 42 | @Component(immediate = true) |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 43 | @Service |
| 44 | public class CoreManager implements CoreService { |
| 45 | |
Thomas Vachuska | 8dc1a69 | 2015-03-31 01:01:37 -0700 | [diff] [blame^] | 46 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 47 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 48 | private static final File VERSION_FILE = new File("../VERSION"); |
Simon Hunt | 9fec43f | 2015-03-25 11:36:30 -0700 | [diff] [blame] | 49 | private static Version version = Version.version("1.2.0-SNAPSHOT"); |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 50 | |
| 51 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 52 | protected ApplicationIdStore applicationIdStore; |
| 53 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 55 | protected IdBlockStore idBlockStore; |
| 56 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 57 | @Activate |
| 58 | public void activate() { |
| 59 | List<String> versionLines = Tools.slurp(VERSION_FILE); |
| 60 | if (versionLines != null && !versionLines.isEmpty()) { |
| 61 | version = Version.version(versionLines.get(0)); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public Version version() { |
| 67 | return version; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public Set<ApplicationId> getAppIds() { |
| 72 | return applicationIdStore.getAppIds(); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public ApplicationId getAppId(Short id) { |
| 77 | return applicationIdStore.getAppId(id); |
| 78 | } |
| 79 | |
| 80 | @Override |
Ray Milkey | 0247986 | 2015-02-17 17:02:19 -0800 | [diff] [blame] | 81 | public ApplicationId getAppId(String name) { |
| 82 | return applicationIdStore.getAppId(name); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | @Override |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 87 | public ApplicationId registerApplication(String name) { |
| 88 | checkNotNull(name, "Application ID cannot be null"); |
| 89 | return applicationIdStore.registerApplication(name); |
| 90 | } |
| 91 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 92 | @Override |
| 93 | public IdGenerator getIdGenerator(String topic) { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 94 | IdBlockAllocator allocator = new StoreBasedIdBlockAllocator(topic, idBlockStore); |
| 95 | return new BlockAllocatorBasedIdGenerator(allocator); |
| 96 | } |
| 97 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 98 | } |