blob: 18c0968f89e8debdc9aea8d97dad1895abc7cfc4 [file] [log] [blame]
Sean Condona36f65c2019-05-20 08:21:41 +01001#set( $symbol_pound = '#' )
2#set( $symbol_dollar = '$' )
3#set( $symbol_escape = '\' )
4/*
5 * Copyright ${year}-present Open Networking Foundation
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 */
19package ${package};
20
21import com.fasterxml.jackson.databind.node.ObjectNode;
22import com.google.common.collect.ImmutableSet;
23import org.onosproject.ui.RequestHandler;
24import org.onosproject.ui.UiMessageHandler;
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
28import java.util.Collection;
29
30/**
31 * Skeletal ONOS UI Custom-View message handler.
32 */
Sean Condon13f42b72019-05-31 16:17:52 +010033public class ${appNameTitle}UiMessageHandler extends UiMessageHandler {
Sean Condona36f65c2019-05-20 08:21:41 +010034
Sean Condon13f42b72019-05-31 16:17:52 +010035 private static final String ${appNameAllCaps}_DATA_REQ = "${appNameAllLower}DataRequest";
36 private static final String ${appNameAllCaps}_DATA_RESP = "${appNameAllLower}DataResponse";
Sean Condona36f65c2019-05-20 08:21:41 +010037
38 private static final String NUMBER = "number";
39 private static final String SQUARE = "square";
40 private static final String CUBE = "cube";
41 private static final String MESSAGE = "message";
42 private static final String MSG_FORMAT = "Next incrememt is %d units";
43
44 private final Logger log = LoggerFactory.getLogger(getClass());
45
46 private long someNumber = 1;
47 private long someIncrement = 1;
48
49 @Override
50 protected Collection<RequestHandler> createRequestHandlers() {
51 return ImmutableSet.of(
Sean Condon13f42b72019-05-31 16:17:52 +010052 new ${appNameTitle}DataRequestHandler()
Sean Condona36f65c2019-05-20 08:21:41 +010053 );
54 }
55
56 // handler for sample data requests
Sean Condon13f42b72019-05-31 16:17:52 +010057 private final class ${appNameTitle}DataRequestHandler extends RequestHandler {
Sean Condona36f65c2019-05-20 08:21:41 +010058
Sean Condon13f42b72019-05-31 16:17:52 +010059 private ${appNameTitle}DataRequestHandler() {
60 super(${appNameAllCaps}_DATA_REQ);
Sean Condona36f65c2019-05-20 08:21:41 +010061 }
62
63 @Override
64 public void process(ObjectNode payload) {
65 someIncrement++;
66 someNumber += someIncrement;
67 log.debug("Computing data for {}...", someNumber);
68
69 ObjectNode result = objectNode();
70 result.put(NUMBER, someNumber);
71 result.put(SQUARE, someNumber * someNumber);
72 result.put(CUBE, someNumber * someNumber * someNumber);
73 result.put(MESSAGE, String.format(MSG_FORMAT, someIncrement + 1));
Sean Condon13f42b72019-05-31 16:17:52 +010074 sendMessage(${appNameAllCaps}_DATA_RESP, result);
Sean Condona36f65c2019-05-20 08:21:41 +010075 }
76 }
77}