Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 | |
| 17 | package org.onosproject.drivers.server.gui; |
| 18 | |
| 19 | import org.onosproject.ui.UiExtension; |
| 20 | import org.onosproject.ui.UiExtensionService; |
| 21 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 22 | import org.onosproject.ui.UiView; |
| 23 | |
| 24 | import com.google.common.collect.ImmutableList; |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 25 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 26 | import org.osgi.service.component.annotations.Activate; |
| 27 | import org.osgi.service.component.annotations.Component; |
| 28 | import org.osgi.service.component.annotations.Deactivate; |
| 29 | import org.osgi.service.component.annotations.Reference; |
| 30 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
| 33 | |
| 34 | import java.util.List; |
| 35 | |
| 36 | import static org.onosproject.ui.UiView.Category.NETWORK; |
| 37 | import static org.onosproject.ui.GlyphConstants.ENDSTATION; |
| 38 | |
| 39 | /** |
| 40 | * Mechanism to stream throughput data to the GUI. |
| 41 | */ |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 42 | @Component(immediate = true, service = ThroughputUI.class) |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 43 | public class ThroughputUI { |
| 44 | |
| 45 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 46 | |
| 47 | /** |
| 48 | * GUI Information. |
| 49 | */ |
| 50 | private static final String THROUGHPUT_ID = "throughput"; |
| 51 | private static final String THROUGHPUT_TEXT = "Servers-Throughput"; |
| 52 | private static final String RES_PATH = "gui"; |
| 53 | private static final ClassLoader CL = ThroughputUI.class.getClassLoader(); |
| 54 | |
| 55 | // Factory for UI message handlers |
| 56 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 57 | () -> ImmutableList.of(new ThroughputViewMessageHandler()); |
| 58 | |
| 59 | // List of application views |
| 60 | private final List<UiView> views = ImmutableList.of( |
| 61 | new UiView(NETWORK, THROUGHPUT_ID, THROUGHPUT_TEXT, ENDSTATION) |
| 62 | ); |
| 63 | |
| 64 | // Application UI extension |
| 65 | private final UiExtension uiExtension = |
| 66 | new UiExtension.Builder(CL, views) |
| 67 | .messageHandlerFactory(messageHandlerFactory) |
| 68 | .resourcePath(RES_PATH) |
| 69 | .build(); |
| 70 | |
| 71 | /** |
| 72 | * Interact with ONOS. |
| 73 | */ |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 74 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 75 | protected UiExtensionService uiExtensionService; |
| 76 | |
| 77 | @Activate |
| 78 | protected void activate() { |
| 79 | uiExtensionService.register(uiExtension); |
| 80 | log.info("Started"); |
| 81 | } |
| 82 | |
| 83 | @Deactivate |
| 84 | protected void deactivate() { |
| 85 | uiExtensionService.unregister(uiExtension); |
| 86 | log.info("Stopped"); |
| 87 | } |
| 88 | |
| 89 | } |