blob: 806855287548ba7f21424bd0072b44a5033979d0 [file] [log] [blame]
Pavlin Radoslavovcf2b5532014-05-23 18:12:23 -07001package net.onrc.onos.core.topology.web;
2
3import net.onrc.onos.core.topology.ITopologyService;
4import net.onrc.onos.core.topology.Topology;
5
Yuta HIGUCHIa0dcd472014-07-06 21:06:29 -07006import org.restlet.engine.io.BufferingRepresentation;
Pavlin Radoslavovcf2b5532014-05-23 18:12:23 -07007import org.restlet.representation.Representation;
8import org.restlet.resource.Get;
9import org.restlet.resource.ServerResource;
10
11/**
12 * A class to access the network topology information.
13 */
Yuta HIGUCHI2ffc3b72014-06-09 15:38:28 -070014public class TopologyResource extends ServerResource {
Pavlin Radoslavovcf2b5532014-05-23 18:12:23 -070015 /**
16 * Gets the network topology information.
17 *
18 * @return a Representation of the network topology.
19 */
20 @Get("json")
21 public Representation retrieve() {
22 ITopologyService topologyService =
23 (ITopologyService) getContext().getAttributes()
24 .get(ITopologyService.class.getCanonicalName());
25
26 Topology topology = topologyService.getTopology();
27 topology.acquireReadLock();
28 try {
Yuta HIGUCHIa0dcd472014-07-06 21:06:29 -070029 return eval(toRepresentation(topology, null));
Pavlin Radoslavovcf2b5532014-05-23 18:12:23 -070030 } finally {
31 topology.releaseReadLock();
32 }
33 }
Yuta HIGUCHIa0dcd472014-07-06 21:06:29 -070034
35 /**
36 * Workaround code to trigger evaluation of Representation immediately.
37 *
38 * @param repr Representation to evaluate immediately
39 * @return Evaluated Representation
40 */
41 public static Representation eval(final Representation repr) {
42
43 BufferingRepresentation eval = new BufferingRepresentation(repr);
44 // trigger evaluation
45 eval.getSize();
46 return eval;
47 }
Pavlin Radoslavovcf2b5532014-05-23 18:12:23 -070048}