Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 1 | #set( $symbol_pound = '#' ) |
| 2 | #set( $symbol_dollar = '$' ) |
| 3 | #set( $symbol_escape = '\' ) |
| 4 | /* |
| 5 | * Copyright 2014 Open Networking Laboratory |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | package ${package}; |
| 20 | |
| 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 22 | import com.google.common.collect.ImmutableList; |
| 23 | import com.google.common.collect.ImmutableSet; |
| 24 | import org.apache.felix.scr.annotations.Activate; |
| 25 | import org.apache.felix.scr.annotations.Component; |
| 26 | import org.apache.felix.scr.annotations.Deactivate; |
| 27 | import org.apache.felix.scr.annotations.Service; |
| 28 | import org.apache.felix.scr.annotations.Reference; |
| 29 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Thomas Vachuska | 9e5dd90 | 2015-05-04 12:49:03 -0700 | [diff] [blame] | 30 | import org.onosproject.ui.RequestHandler; |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 31 | import org.onosproject.ui.UiExtension; |
| 32 | import org.onosproject.ui.UiExtensionService; |
| 33 | import org.onosproject.ui.UiMessageHandler; |
| 34 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 35 | import org.onosproject.ui.UiView; |
| 36 | import org.slf4j.Logger; |
| 37 | import org.slf4j.LoggerFactory; |
| 38 | |
Thomas Vachuska | 9e5dd90 | 2015-05-04 12:49:03 -0700 | [diff] [blame] | 39 | import java.util.Collection; |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 40 | import java.util.List; |
| 41 | |
| 42 | /** |
| 43 | * Skeletal ONOS UI application component. |
| 44 | */ |
| 45 | @Component(immediate = true) |
| 46 | public class AppUiComponent { |
| 47 | |
| 48 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 49 | |
| 50 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 51 | protected UiExtensionService uiExtensionService; |
| 52 | |
| 53 | // List of application views |
| 54 | private final List<UiView> uiViews = ImmutableList.of( |
| 55 | new UiView(UiView.Category.OTHER, "sample", "Sample") |
| 56 | ); |
| 57 | |
| 58 | // Factory for UI message handlers |
| 59 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 60 | () -> ImmutableList.of( |
| 61 | new AppUiMessageHandler() |
| 62 | ); |
| 63 | |
Thomas Vachuska | 9290053 | 2015-05-20 17:21:44 -0700 | [diff] [blame^] | 64 | // Application UI extension |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 65 | protected UiExtension extension = new UiExtension(uiViews, messageHandlerFactory, |
| 66 | getClass().getClassLoader()); |
| 67 | |
| 68 | @Activate |
| 69 | protected void activate() { |
| 70 | uiExtensionService.register(extension); |
| 71 | log.info("Started"); |
| 72 | } |
| 73 | |
| 74 | @Deactivate |
| 75 | protected void deactivate() { |
| 76 | uiExtensionService.unregister(extension); |
| 77 | log.info("Stopped"); |
| 78 | } |
| 79 | |
| 80 | // Application UI message handler |
| 81 | private class AppUiMessageHandler extends UiMessageHandler { |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 82 | |
| 83 | @Override |
Thomas Vachuska | 9290053 | 2015-05-20 17:21:44 -0700 | [diff] [blame^] | 84 | protected Collection<RequestHandler> createRequestHandlers() { |
Thomas Vachuska | 9e5dd90 | 2015-05-04 12:49:03 -0700 | [diff] [blame] | 85 | return ImmutableSet.of(new SampleRequest()); |
| 86 | } |
| 87 | |
| 88 | private class SampleRequest extends RequestHandler { |
| 89 | public SampleRequest() { |
| 90 | super("sampleRequest"); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void process(long sid, ObjectNode objectNode) { |
| 95 | log.info("We got a message: {}", objectNode); |
| 96 | } |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
| 100 | } |