blob: e2ebf3a9ce47c4389f7e4d5683d8c535f021ad68 [file] [log] [blame]
Jimo Jung14e87bf2018-09-03 16:28:13 +09001/*
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 */
16package org.onosproject.openstackvtap.gui;
17
18import com.google.common.collect.ImmutableList;
Jimo Jung14e87bf2018-09-03 16:28:13 +090019import org.onosproject.ui.UiExtensionService;
20import org.onosproject.ui.UiMessageHandlerFactory;
21import org.onosproject.ui.UiTopoOverlayFactory;
22import org.onosproject.ui.UiView;
23import org.onosproject.ui.UiViewHidden;
24import org.onosproject.ui.UiExtension;
Ray Milkeyd5425682018-10-23 10:21:33 -070025import org.osgi.service.component.annotations.Activate;
26import org.osgi.service.component.annotations.Component;
27import org.osgi.service.component.annotations.Deactivate;
28import org.osgi.service.component.annotations.Reference;
29import org.osgi.service.component.annotations.ReferenceCardinality;
Jimo Jung14e87bf2018-09-03 16:28:13 +090030import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33import java.util.List;
34
35/**
36 * Mechanism to stream data to the GUI.
37 */
Ray Milkeyd5425682018-10-23 10:21:33 -070038@Component(immediate = true, service = {OpenstackVtapUI.class})
Jimo Jung14e87bf2018-09-03 16:28:13 +090039public class OpenstackVtapUI {
40 private static final String OPENSTACK_VTAP_ID = "openstackvtap";
41 private static final String RESOURCE_PATH = "gui";
42 private static final ClassLoader CL = OpenstackVtapUI.class.getClassLoader();
43
44 private final Logger log = LoggerFactory.getLogger(getClass());
45
Ray Milkeyd5425682018-10-23 10:21:33 -070046 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jimo Jung14e87bf2018-09-03 16:28:13 +090047 protected UiExtensionService uiExtensionService;
48
49 // Factory for UI message handlers
50 private final UiMessageHandlerFactory messageHandlerFactory =
51 () -> ImmutableList.of(new OpenstackVtapViewMessageHandler());
52
53 // List of application views
54 private final List<UiView> views = ImmutableList.of(
55 new UiViewHidden(OPENSTACK_VTAP_ID)
56 );
57
58 // Factory for UI topology overlays
59 private final UiTopoOverlayFactory topoOverlayFactory =
60 () -> ImmutableList.of(
61 new OpenstackVtapUiTopovOverlay()
62 );
63
64 // Application UI extension
65 private final UiExtension uiExtension =
66 new UiExtension.Builder(CL, views)
67 .messageHandlerFactory(messageHandlerFactory)
68 .resourcePath(RESOURCE_PATH)
69 .topoOverlayFactory(topoOverlayFactory)
70 .build();
71
72 @Activate
73 protected void activate() {
74 uiExtensionService.register(uiExtension);
75 log.info("Started");
76 }
77
78 @Deactivate
79 protected void deactivate() {
80 uiExtensionService.unregister(uiExtension);
81 log.info("Stopped");
82 }
83}