blob: f66f1bd40676941943e67198f4ec99a80c2a7347 [file] [log] [blame]
Thomas Vachuska5b48d6c2018-04-27 18:24:27 -07001/*
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.layout;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import com.google.common.collect.ImmutableSet;
20import org.onlab.osgi.ServiceDirectory;
21import org.onosproject.ui.RequestHandler;
22import org.onosproject.ui.UiConnection;
23import org.onosproject.ui.UiMessageHandler;
24import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
26
27import java.util.Collection;
28
29/**
30 * ONOS UI Layout Topology-Overlay message handler.
31 */
32public class LayoutOverlayMessageHandler extends UiMessageHandler {
33
34 private final Logger log = LoggerFactory.getLogger(getClass());
35
36 private static final String DO_LAYOUT = "doLayout";
37 private static final String TYPE = "type";
38
39 RoleBasedLayoutManager layoutManager;
40
41 @Override
42 public void init(UiConnection connection, ServiceDirectory directory) {
43 super.init(connection, directory);
44 layoutManager = directory.get(RoleBasedLayoutManager.class);
45 }
46
47 @Override
48 protected Collection<RequestHandler> createRequestHandlers() {
49 return ImmutableSet.of(
50 new LayoutHandler()
51 );
52 }
53
54 private final class LayoutHandler extends RequestHandler {
55
56 public LayoutHandler() {
57 super(DO_LAYOUT);
58 }
59
60 @Override
61 public void process(ObjectNode payload) {
62 String algorithm = string(payload, TYPE);
63 switch (algorithm) {
64 case "access":
65 layoutManager.layout(new AccessNetworkLayout());
66 break;
67 default:
68 layoutManager.layout(new DefaultForceLayout());
69 break;
70 }
71 }
72 }
73
74}