KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > console > JBIContainerPortlet


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 JavaDoc;
23 import javax.portlet.ActionRequest;
24 import javax.portlet.ActionResponse;
25 import javax.portlet.RenderRequest;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30
31 public class JBIContainerPortlet extends ServiceMixPortlet {
32
33     public static class ServiceInfo {
34         private String JavaDoc name;
35         private String JavaDoc description;
36         private String JavaDoc state;
37         
38         public String JavaDoc getDescription() {
39             return description;
40         }
41         public void setDescription(String JavaDoc description) {
42             this.description = description;
43         }
44         public String JavaDoc getName() {
45             return name;
46         }
47         public void setName(String JavaDoc name) {
48             this.name = name;
49         }
50         public String JavaDoc getState() {
51             return state;
52         }
53         public void setState(String JavaDoc state) {
54             this.state = state;
55         }
56     }
57     
58     protected void fillViewRequest(RenderRequest request) throws Exception JavaDoc {
59         LifeCycleMBean container = getJBIContainer();
60         ManagementContextMBean management = getManagementContext();
61         request.setAttribute("state", container.getCurrentState());
62         request.setAttribute("info", management.getSystemInfo());
63         ObjectName JavaDoc[] services = management.getSystemServices();
64         List JavaDoc infos = new ArrayList JavaDoc();
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 JavaDoc getAttribute(ObjectName JavaDoc name, String JavaDoc attribute) {
76         try {
77             return (String JavaDoc) getServerConnection().getAttribute(name, attribute);
78         } catch (Exception JavaDoc 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 JavaDoc {
85         String JavaDoc action = actionRequest.getParameter("action");
86         String JavaDoc name = actionRequest.getParameter("name");
87         System.err.println("doProcessAction: " + action + " for " + name);
88         ManagementContextMBean management = getManagementContext();
89         ObjectName JavaDoc service = management.getSystemService(getContainerName() + "." + name);
90         getServerConnection().invoke(service, action, new Object JavaDoc[0], new String JavaDoc[0]);
91     }
92 }
Popular Tags