blob: c41a74a1041aa98e89e6ed981b2188b1149589fc [file] [log] [blame]
Georgios Katsikas973a2652018-06-28 08:45:47 +02001/*
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
17package org.onosproject.drivers.server.gui;
18
19import org.onosproject.ui.UiExtension;
20import org.onosproject.ui.UiExtensionService;
21import org.onosproject.ui.UiMessageHandlerFactory;
22import org.onosproject.ui.UiView;
23
24import com.google.common.collect.ImmutableList;
Georgios Katsikas973a2652018-06-28 08:45:47 +020025
Ray Milkey86ad7bb2018-09-27 12:32:28 -070026import org.osgi.service.component.annotations.Activate;
27import org.osgi.service.component.annotations.Component;
28import org.osgi.service.component.annotations.Deactivate;
29import org.osgi.service.component.annotations.Reference;
30import org.osgi.service.component.annotations.ReferenceCardinality;
Georgios Katsikas973a2652018-06-28 08:45:47 +020031import org.slf4j.Logger;
32import org.slf4j.LoggerFactory;
33
34import java.util.List;
35
36import static org.onosproject.ui.UiView.Category.NETWORK;
37import static org.onosproject.ui.GlyphConstants.ENDSTATION;
38
39/**
40 * Mechanism to stream throughput data to the GUI.
41 */
Ray Milkey86ad7bb2018-09-27 12:32:28 -070042@Component(immediate = true, service = ThroughputUI.class)
Georgios Katsikas973a2652018-06-28 08:45:47 +020043public 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 Milkey86ad7bb2018-09-27 12:32:28 -070074 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Georgios Katsikas973a2652018-06-28 08:45:47 +020075 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}