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;
013:
014: import java.io.*;
015: import java.lang.*;
016: import java.util.*;
017: import java.text.MessageFormat;
018:
019: import java.util.logging.Logger;
020: import java.util.logging.Level;
021:
022: // JMX
023: import javax.management.MBeanServerConnection;
024: import javax.management.ObjectName;
025: import javax.management.InstanceNotFoundException;
026: import javax.management.MBeanException;
027: import javax.management.ReflectionException;
028: import javax.management.MalformedObjectNameException;
029:
030: // PS Admin Common
031: import com.sun.portal.admin.common.util.AdminClientUtil;
032:
033: //CLI framework
034: import com.sun.enterprise.cli.framework.*;
035:
036: /**
037: * This class implements the psadmin unschedule-tasks subcommand.
038: * The unschedule subcommand calls the SchedulerMBean
039: * and unschedules commands.
040: */
041: public class UnscheduleTasksCommand extends AdminBaseCommand {
042:
043: /**
044: * Executes the subcommand.
045: *
046: * @exception CLIException If error occurrs during the execution.
047: */
048: public void runCommand() throws CommandException,
049: CommandValidationException {
050: validateOptions();
051: String operation = "";
052:
053: try {
054: LinkedList path = new LinkedList();
055: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
056: path.addFirst("scheduler");
057: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
058: AdminClientUtil.SCHEDULER_MBEAN_TYPE, path);
059: Object[] params = { getActions() };
060: String[] signatures = { "java.util.List" };
061: MBeanServerConnection msc = getMBeanServerConnection(
062: getUserId(), getPassword(), getHost());
063: operation = "unschedule";
064:
065: msc.invoke(on, operation, params, signatures);
066: } catch (InstanceNotFoundException ie) {
067: logger.log(Level.SEVERE, "PSALI_CSPACC0005", ie);
068: throw new CommandException(getLocalizedString(
069: ERROR_MBEAN_INSTANCE_NOT_FOUND,
070: new Object[] { operation }), ie);
071: } catch (MBeanException me) {
072: logger.log(Level.SEVERE, "PSALI_CSPACC0006", me);
073: throw new CommandException(getLocalizedString(
074: ERROR_JMX_INVOKE, new Object[] { operation }), me);
075: } catch (ReflectionException re) {
076: logger.log(Level.SEVERE, "PSALI_CSPACC0007", re);
077: throw new CommandException(getLocalizedString(
078: ERROR_MBEAN_REFLECTION_ERROR,
079: new Object[] { operation }), re);
080: } catch (MalformedObjectNameException mle) {
081: logger.log(Level.SEVERE, "PSALI_CSPACC0004", mle);
082: throw new CommandException(
083: getLocalizedString(ERROR_OBJECT_NAME), mle);
084: } catch (CommandException ce) {
085: logger.log(Level.SEVERE, "PSALI_CSPACC0008", ce);
086: throw ce;
087: } catch (Exception e) {
088: logger.log(Level.SEVERE, "PSALI_CSPACC0010", e);
089: throw new CommandException(
090: getLocalizedString(COMMAND_FAILED), e);
091: } finally {
092: closeMBeanServerConnection();
093: }
094: }
095:
096: private List getActions() {
097: ArrayList actions = new ArrayList();
098: try {
099: final String commandFile = getOption("commandfile");
100: if (commandFile != null) {
101: BufferedReader br = new BufferedReader(new FileReader(
102: commandFile));
103: String line;
104: while ((line = br.readLine()) != null) {
105: actions.add(line);
106: }
107: br.close();
108: }
109: } catch (Exception e) {
110: }
111: return (List) actions;
112: }
113:
114: }
|