Karthik Vegesna | 9901271 | 2017-07-20 12:07:23 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Karthik Vegesna | 9901271 | 2017-07-20 12:07:23 -0700 | [diff] [blame] | 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.packetstats; |
| 18 | |
| 19 | |
| 20 | import com.google.common.collect.ImmutableList; |
| 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 26 | import org.onosproject.ui.UiExtension; |
| 27 | import org.onosproject.ui.UiExtensionService; |
| 28 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 29 | import org.onosproject.ui.UiView; |
| 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
| 33 | import java.util.List; |
| 34 | |
| 35 | /** |
| 36 | * ONOS UI Custom-View application component for the Packet Statistics Application. |
| 37 | */ |
| 38 | @Component(immediate = true) |
| 39 | public class PacketStatsUiComponent { |
| 40 | private static final String VIEW_ID = "sampleCustom"; |
| 41 | private static final String VIEW_TEXT = "Packet Statistics Application"; |
| 42 | |
| 43 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 44 | |
| 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 46 | protected UiExtensionService uiExtensionService; |
| 47 | |
| 48 | // List of application views |
| 49 | private final List<UiView> uiViews = ImmutableList.of( |
| 50 | new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT) |
| 51 | ); |
| 52 | |
| 53 | |
| 54 | // Factory for UI message handlers |
| 55 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 56 | () -> ImmutableList.of(new PacketStatsUiMessageHandler()); |
| 57 | |
| 58 | |
| 59 | // Application UI extension |
| 60 | protected UiExtension extension = |
| 61 | new UiExtension.Builder(getClass().getClassLoader(), uiViews) |
| 62 | .resourcePath(VIEW_ID) |
| 63 | .messageHandlerFactory(messageHandlerFactory) |
| 64 | .build(); |
| 65 | |
| 66 | @Activate |
| 67 | protected void activate() { |
| 68 | uiExtensionService.register(extension); |
| 69 | log.info("Started"); |
| 70 | } |
| 71 | |
| 72 | @Deactivate |
| 73 | protected void deactivate() { |
| 74 | uiExtensionService.unregister(extension); |
| 75 | log.info("Stopped"); |
| 76 | } |
| 77 | |
| 78 | } |