Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
| 16 | package org.opencord.sadis.impl; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.module.SimpleModule; |
| 20 | import com.google.common.cache.CacheBuilder; |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | import org.onosproject.codec.JsonCodec; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.net.config.ConfigFactory; |
| 25 | import org.opencord.sadis.BandwidthProfileInformation; |
| 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
| 29 | import java.util.Set; |
| 30 | import java.util.concurrent.TimeUnit; |
| 31 | |
| 32 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
| 33 | |
| 34 | public class BandwidthProfileManager extends InformationAdapter<BandwidthProfileInformation, BandwidthProfileConfig> { |
| 35 | |
| 36 | private final Logger log = LoggerFactory.getLogger(this.getClass()); |
| 37 | |
| 38 | private ApplicationId appId; |
| 39 | |
| 40 | @SuppressWarnings("rawtypes") |
| 41 | private final Set<ConfigFactory> factories = ImmutableSet |
| 42 | .of(new ConfigFactory<ApplicationId, BandwidthProfileConfig>(APP_SUBJECT_FACTORY, |
| 43 | BandwidthProfileConfig.class, "bandwidthprofile") { |
| 44 | @Override |
| 45 | public BandwidthProfileConfig createConfig() { |
| 46 | return new BandwidthProfileConfig(); |
| 47 | } |
| 48 | }); |
| 49 | |
| 50 | public BandwidthProfileManager(ApplicationId appId) { |
| 51 | this.appId = appId; |
| 52 | this.registerModule(); |
| 53 | this.log.info("Started"); |
| 54 | } |
| 55 | |
| 56 | |
| 57 | @Override |
| 58 | public void registerModule() { |
| 59 | cache = CacheBuilder.newBuilder().maximumSize(maxiumCacheSize) |
| 60 | .expireAfterAccess(cacheEntryTtl, TimeUnit.SECONDS).build(); |
| 61 | mapper = new ObjectMapper(); |
| 62 | mapper.registerModule(new SimpleModule()); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public ApplicationId getAppId() { |
| 67 | return this.appId; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public Set<ConfigFactory> getConfigFactories() { |
| 72 | return factories; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public JsonCodec<BandwidthProfileInformation> getCodec() { |
| 77 | return new BandwidthProfileCodec(); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public Class<BandwidthProfileInformation> getInformationClass() { |
| 82 | return BandwidthProfileInformation.class; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Class<BandwidthProfileConfig> getConfigClass() { |
| 87 | return BandwidthProfileConfig.class; |
| 88 | } |
| 89 | |
| 90 | } |