001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.sun.manager.jbi.actions;
042:
043: import com.sun.esb.management.api.administration.AdministrationService;
044: import com.sun.esb.management.common.ManagementRemoteException;
045: import com.sun.esb.management.common.data.IEndpointStatisticsData;
046: import java.util.Date;
047: import org.netbeans.modules.sun.manager.jbi.management.AppserverJBIMgmtController;
048: import org.netbeans.modules.sun.manager.jbi.management.wrapper.api.PerformanceMeasurementServiceWrapper;
049: import org.netbeans.modules.sun.manager.jbi.nodes.JBIComponentNode;
050: import org.openide.nodes.Node;
051: import org.openide.util.HelpCtx;
052: import org.openide.util.actions.NodeAction;
053: import org.openide.windows.IOProvider;
054: import org.openide.windows.InputOutput;
055: import org.openide.windows.OutputWriter;
056:
057: /**
058: * Action to show endpoint statistics of a SE/BC.
059: *
060: * @author jqian
061: */
062: public class ShowComponentEndpointsStatisticsAction extends NodeAction {
063:
064: protected void performAction(Node[] activatedNodes) {
065:
066: for (Node node : activatedNodes) {
067: JBIComponentNode componentNode = node.getLookup().lookup(
068: JBIComponentNode.class);
069: String compName = node.getName();
070:
071: InputOutput io = IOProvider.getDefault().getIO(
072: "Endpoint Statistics", false);
073: io.select();
074: OutputWriter writer = io.getOut();
075:
076: writer
077: .println("==================================================");
078: writer.println("Endpoint Statistics for " + compName
079: + " (" + new Date() + ")");
080: writer.println();
081:
082: try {
083: AppserverJBIMgmtController controller = componentNode
084: .getAppserverJBIMgmtController();
085: AdministrationService adminService = controller
086: .getAdministrationService();
087: PerformanceMeasurementServiceWrapper perfService = controller
088: .getPerformanceMeasurementServiceWrapper();
089:
090: writer.println(" * Provisioning Endpoints:");
091: String[] pEndpoints = adminService
092: .getProvisioningEndpoints(
093: compName,
094: AppserverJBIMgmtController.SERVER_TARGET);
095: for (String pEndpoint : pEndpoints) {
096: if (pEndpoint.endsWith(",Provider")) {
097: pEndpoint = pEndpoint.substring(0, pEndpoint
098: .length() - 9);
099: }
100: IEndpointStatisticsData statistics = perfService
101: .getEndpointStatistics(
102: pEndpoint,
103: AppserverJBIMgmtController.SERVER_TARGET);
104: writer.println(" " + pEndpoint);
105: writer.println(statistics.getDisplayString());
106: }
107:
108: writer.println(" * Consuming Endpoints:");
109: String[] cEndpoints = adminService
110: .getConsumingEndpoints(
111: compName,
112: AppserverJBIMgmtController.SERVER_TARGET);
113: for (String cEndpoint : cEndpoints) {
114: if (cEndpoint.endsWith(",Consumer")) {
115: cEndpoint = cEndpoint.substring(0, cEndpoint
116: .length() - 9);
117: }
118: IEndpointStatisticsData statistics = perfService
119: .getEndpointStatistics(
120: cEndpoint,
121: AppserverJBIMgmtController.SERVER_TARGET);
122: writer.println(" " + cEndpoint);
123: writer.println(statistics.getDisplayString());
124: }
125: writer.println();
126: } catch (ManagementRemoteException e) {
127: System.err.println(e.getMessage());
128: }
129: }
130: }
131:
132: protected boolean enable(Node[] activatedNodes) {
133: return true;
134: }
135:
136: @Override
137: protected boolean asynchronous() {
138: return false;
139: }
140:
141: public HelpCtx getHelpCtx() {
142: return HelpCtx.DEFAULT_HELP;
143: }
144:
145: public String getName() {
146: return "Show Endpoint Statistics"; //NbBundle.getMessage(RefreshAction.class, "LBL_RefreshAction"); // NOI18N
147: }
148: }
|