1 17 package org.apache.servicemix.console; 18 19 import org.apache.servicemix.jbi.management.ManagementContextMBean; 20 21 import javax.jbi.management.LifeCycleMBean; 22 import javax.management.ObjectName ; 23 import javax.portlet.ActionRequest; 24 import javax.portlet.ActionResponse; 25 import javax.portlet.RenderRequest; 26 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 31 public class JBIContainerPortlet extends ServiceMixPortlet { 32 33 public static class ServiceInfo { 34 private String name; 35 private String description; 36 private String state; 37 38 public String getDescription() { 39 return description; 40 } 41 public void setDescription(String description) { 42 this.description = description; 43 } 44 public String getName() { 45 return name; 46 } 47 public void setName(String name) { 48 this.name = name; 49 } 50 public String getState() { 51 return state; 52 } 53 public void setState(String state) { 54 this.state = state; 55 } 56 } 57 58 protected void fillViewRequest(RenderRequest request) throws Exception { 59 LifeCycleMBean container = getJBIContainer(); 60 ManagementContextMBean management = getManagementContext(); 61 request.setAttribute("state", container.getCurrentState()); 62 request.setAttribute("info", management.getSystemInfo()); 63 ObjectName [] services = management.getSystemServices(); 64 List infos = new ArrayList (); 65 for (int i = 0; i < services.length; i++) { 66 ServiceInfo info = new ServiceInfo(); 67 info.name = getAttribute(services[i], "name"); 68 info.description = getAttribute(services[i], "description"); 69 info.state = getAttribute(services[i], "currentState"); 70 infos.add(info); 71 } 72 request.setAttribute("services", infos); 73 } 74 75 protected String getAttribute(ObjectName name, String attribute) { 76 try { 77 return (String ) getServerConnection().getAttribute(name, attribute); 78 } catch (Exception e) { 79 log.error("Could not retrieve attribute '" + attribute + "' for mbean '" + name + "'"); 80 return null; 81 } 82 } 83 84 protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { 85 String action = actionRequest.getParameter("action"); 86 String name = actionRequest.getParameter("name"); 87 System.err.println("doProcessAction: " + action + " for " + name); 88 ManagementContextMBean management = getManagementContext(); 89 ObjectName service = management.getSystemService(getContainerName() + "." + name); 90 getServerConnection().invoke(service, action, new Object [0], new String [0]); 91 } 92 } | Popular Tags |