Jonathan Hart | 3d7730a | 2013-02-22 11:51:17 -0800 | [diff] [blame^] | 1 | package net.onrc.onos.registry.controller; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | |
| 6 | import org.restlet.resource.Get; |
| 7 | import org.restlet.resource.ServerResource; |
| 8 | import org.slf4j.Logger; |
| 9 | import org.slf4j.LoggerFactory; |
| 10 | |
| 11 | public class ControllerRegistryResource extends ServerResource { |
| 12 | |
| 13 | protected static Logger log = LoggerFactory.getLogger(ControllerRegistryResource.class); |
| 14 | |
| 15 | @Get("json") |
| 16 | public Collection<String> getControllers() { |
| 17 | IControllerRegistryService registry = |
| 18 | (IControllerRegistryService) getContext().getAttributes(). |
| 19 | get(IControllerRegistryService.class.getCanonicalName()); |
| 20 | |
| 21 | Collection<String> controllers = null; |
| 22 | try { |
| 23 | controllers = registry.getAllControllers(); |
| 24 | } catch (RegistryException e) { |
| 25 | log.warn("Error retrieving controller list: {}", e.getMessage()); |
| 26 | } |
| 27 | |
| 28 | if (controllers == null){ |
| 29 | controllers = new ArrayList<String>(); |
| 30 | } |
| 31 | |
| 32 | return controllers; |
| 33 | } |
| 34 | |
| 35 | } |