blob: c0480ef30612bf9a01b9f879caacab1efd77a65d [file] [log] [blame]
Simon Hunte11ce5a2015-07-21 12:11:04 -07001#set( $symbol_pound = '#' )
2#set( $symbol_dollar = '$' )
3#set( $symbol_escape = '\' )
4/*
HIGUCHI Yuta9caa3a02016-01-09 23:17:54 -08005 * Copyright 2016 Open Networking Laboratory
Simon Hunte11ce5a2015-07-21 12:11:04 -07006 *
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;
Simon Hunte11ce5a2015-07-21 12:11:04 -070025import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
Simon Hunte11ce5a2015-07-21 12:11:04 -070028import java.util.Collection;
Simon Hunte11ce5a2015-07-21 12:11:04 -070029
30/**
Simon Hunt84f4c2a2015-09-23 17:52:45 -070031 * Skeletal ONOS UI Custom-View message handler.
Simon Hunte11ce5a2015-07-21 12:11:04 -070032 */
33public class AppUiMessageHandler extends UiMessageHandler {
34
Simon Hunt84f4c2a2015-09-23 17:52:45 -070035 private static final String SAMPLE_CUSTOM_DATA_REQ = "sampleCustomDataRequest";
36 private static final String SAMPLE_CUSTOM_DATA_RESP = "sampleCustomDataResponse";
Simon Hunte11ce5a2015-07-21 12:11:04 -070037
Simon Hunt89577e52015-09-25 18:15:19 -070038 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";
Simon Hunte11ce5a2015-07-21 12:11:04 -070043
44 private final Logger log = LoggerFactory.getLogger(getClass());
45
Simon Hunt89577e52015-09-25 18:15:19 -070046 private long someNumber = 1;
47 private long someIncrement = 1;
Simon Hunte11ce5a2015-07-21 12:11:04 -070048
49 @Override
50 protected Collection<RequestHandler> createRequestHandlers() {
51 return ImmutableSet.of(
Simon Hunt89577e52015-09-25 18:15:19 -070052 new SampleCustomDataRequestHandler()
Simon Hunte11ce5a2015-07-21 12:11:04 -070053 );
54 }
55
Simon Hunt89577e52015-09-25 18:15:19 -070056 // handler for sample data requests
57 private final class SampleCustomDataRequestHandler extends RequestHandler {
Simon Hunte11ce5a2015-07-21 12:11:04 -070058
Simon Hunt84f4c2a2015-09-23 17:52:45 -070059 private SampleCustomDataRequestHandler() {
Simon Hunt89577e52015-09-25 18:15:19 -070060 super(SAMPLE_CUSTOM_DATA_REQ);
Simon Hunte11ce5a2015-07-21 12:11:04 -070061 }
62
63 @Override
64 public void process(long sid, ObjectNode payload) {
Simon Hunt89577e52015-09-25 18:15:19 -070065 someIncrement++;
66 someNumber += someIncrement;
67 log.debug("Computing data for {}...", someNumber);
Simon Hunte11ce5a2015-07-21 12:11:04 -070068
Simon Hunt89577e52015-09-25 18:15:19 -070069 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));
74 sendMessage(SAMPLE_CUSTOM_DATA_RESP, 0, result);
Simon Hunte11ce5a2015-07-21 12:11:04 -070075 }
76 }
Simon Hunte11ce5a2015-07-21 12:11:04 -070077}