blob: c68c3385bff198e59b3d5520fae12654a2bf5fff [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;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Service;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.Activate;
23import org.apache.felix.scr.annotations.Deactivate;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.onosproject.ui.UiExtensionService;
26import org.onosproject.ui.UiMessageHandlerFactory;
27import org.onosproject.ui.UiTopoOverlayFactory;
28import org.onosproject.ui.UiView;
29import org.onosproject.ui.UiViewHidden;
30import org.onosproject.ui.UiExtension;
31import org.slf4j.Logger;
32import org.slf4j.LoggerFactory;
33
34import java.util.List;
35
36/**
37 * Mechanism to stream data to the GUI.
38 */
39@Component(immediate = true, enabled = true)
40@Service(value = OpenstackVtapUI.class)
41public class OpenstackVtapUI {
42 private static final String OPENSTACK_VTAP_ID = "openstackvtap";
43 private static final String RESOURCE_PATH = "gui";
44 private static final ClassLoader CL = OpenstackVtapUI.class.getClassLoader();
45
46 private final Logger log = LoggerFactory.getLogger(getClass());
47
48 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
49 protected UiExtensionService uiExtensionService;
50
51 // Factory for UI message handlers
52 private final UiMessageHandlerFactory messageHandlerFactory =
53 () -> ImmutableList.of(new OpenstackVtapViewMessageHandler());
54
55 // List of application views
56 private final List<UiView> views = ImmutableList.of(
57 new UiViewHidden(OPENSTACK_VTAP_ID)
58 );
59
60 // Factory for UI topology overlays
61 private final UiTopoOverlayFactory topoOverlayFactory =
62 () -> ImmutableList.of(
63 new OpenstackVtapUiTopovOverlay()
64 );
65
66 // Application UI extension
67 private final UiExtension uiExtension =
68 new UiExtension.Builder(CL, views)
69 .messageHandlerFactory(messageHandlerFactory)
70 .resourcePath(RESOURCE_PATH)
71 .topoOverlayFactory(topoOverlayFactory)
72 .build();
73
74 @Activate
75 protected void activate() {
76 uiExtensionService.register(uiExtension);
77 log.info("Started");
78 }
79
80 @Deactivate
81 protected void deactivate() {
82 uiExtensionService.unregister(uiExtension);
83 log.info("Stopped");
84 }
85}