001: /**
002: * Copyright 2004 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.cli.commands.subscriptions;
013:
014: import java.util.*;
015: import java.util.logging.Logger;
016: import java.util.logging.Level;
017:
018: // JMX
019: import javax.management.MBeanServerConnection;
020: import javax.management.ObjectName;
021: import javax.management.InstanceNotFoundException;
022: import javax.management.MBeanException;
023: import javax.management.ReflectionException;
024:
025: // CLI framework
026: import com.sun.enterprise.cli.framework.*;
027: import com.sun.portal.admin.cli.commands.GenericCommand;
028:
029: // PS Admin Common
030: import com.sun.portal.admin.common.util.AdminUtil;
031:
032: /**
033: * This class implements the psadmin stop-profiler subcommand.
034: * <UL>
035: * <LI>stop profiler
036: * <UL>
037: */
038:
039: public class StopProfilerCommand extends GenericCommand {
040:
041: public Logger logger = super .getLogger();
042: public static final String cmdName = "StopProfilerCommand";
043:
044: //command options
045: String organization = null;
046:
047: public void runCommand() throws CommandException,
048: CommandValidationException {
049: validateOptions();
050: validatePortalId();
051:
052: organization = getOption("organization");
053: String result = null;
054: try {
055: LinkedList path = new LinkedList();
056: // setting the CACAO path
057: path.addFirst(getDomainId());
058: path.addFirst(getPortalId());
059: path.addFirst("Profiler");
060: MBeanServerConnection msc = getMBeanServerConnection(
061: getUserId(), getPassword(), getHost());
062: ObjectName objName = AdminUtil.getResourceMBeanObjectName(
063: AdminUtil.PROFILER_MBEAN_TYPE, path);
064:
065: Object[] params = { getPortalId(), organization,
066: getUserId(), getPassword() };
067: String[] signature = { "java.lang.String",
068: "java.lang.String", "java.lang.String",
069: "java.lang.String" };
070: result = (String) msc.invoke(objName, "stopProfiler",
071: params, signature);
072:
073: } catch (InstanceNotFoundException ie) {
074: logger.logp(Level.SEVERE, cmdName, "cmdName", ie
075: .getMessage(), ie);
076: throw new CommandException(getLocalizedString(
077: ERROR_MBEAN_INSTANCE_NOT_FOUND,
078: new Object[] { "stopProfiler" }), ie);
079: } catch (MBeanException me) {
080: logger.logp(Level.SEVERE, cmdName, "cmdName", me
081: .getMessage(), me);
082: throw new CommandException(getLocalizedString(
083: ERROR_JMX_INVOKE, new Object[] { "stopProfiler" }),
084: me);
085: } catch (ReflectionException re) {
086: logger.logp(Level.SEVERE, cmdName, "cmdName", re
087: .getMessage(), re);
088: throw new CommandException(getLocalizedString(
089: ERROR_MBEAN_REFLECTION_ERROR,
090: new Object[] { "stopProfiler" }), re);
091: } catch (CommandException ce) {
092: logger.logp(Level.SEVERE, cmdName, "cmdName", ce
093: .getMessage(), ce);
094: throw ce;
095: } catch (Exception ex) {
096: ex.printStackTrace();
097: logger.logp(Level.SEVERE, cmdName, "cmdName", ex
098: .getMessage(), ex);
099: throw new CommandException(
100: getLocalizedString(COMMAND_FAILED));
101: } finally {
102: closeMBeanServerConnection();
103: }
104: }
105:
106: }
|