001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.activemq.console;
021
022 import java.util.ArrayList;
023 import java.util.Arrays;
024 import java.util.List;
025
026 import org.apache.activemq.console.command.Command;
027 import org.apache.activemq.console.command.ShutdownCommand;
028 import org.apache.activemq.console.command.StartCommand;
029 import org.apache.activemq.console.CommandContext;
030 import org.apache.activemq.console.formatter.CommandShellOutputFormatter;
031 import org.apache.commons.daemon.Daemon;
032 import org.apache.commons.daemon.DaemonContext;
033
034 /**
035 * This class launches ActiveMQ under <a href="http://commons.apache.org/daemon/jsvc.html">Apache JSVC</a>
036 *
037 * @author areese
038 *
039 */
040 public class ActiveMQLauncher implements Daemon {
041 private List<String> args;
042
043 /**
044 *
045 */
046 public ActiveMQLauncher() {
047 }
048
049 /*
050 * (non-Javadoc)
051 *
052 * @see org.apache.commons.daemon.Daemon#destroy()
053 */
054 public void destroy() {
055 }
056
057 /*
058 * (non-Javadoc)
059 *
060 * @see
061 * org.apache.commons.daemon.Daemon#init(org.apache.commons.daemon.DaemonContext
062 * )
063 */
064 public void init(DaemonContext arg0) throws Exception {
065 // we need to save the args we started with.
066 args = Arrays.asList(arg0.getArguments());
067 }
068
069 /*
070 * (non-Javadoc)
071 *
072 * @see org.apache.commons.daemon.Daemon#start()
073 */
074 public void start() throws Exception {
075 CommandContext context = new CommandContext();
076 context.setFormatter(new CommandShellOutputFormatter(System.out));
077
078 Command command = new StartCommand();
079 command.setCommandContext(context);
080
081 command.execute(args);
082 }
083
084 /*
085 * (non-Javadoc)
086 *
087 * @see org.apache.commons.daemon.Daemon#stop()
088 */
089 public void stop() throws Exception {
090 CommandContext context = new CommandContext();
091 context.setFormatter(new CommandShellOutputFormatter(System.out));
092
093 Command command = new ShutdownCommand();
094 command.setCommandContext(context);
095
096 List<String> tokens = new ArrayList<String>(Arrays.asList(new String[] {
097 "--jmxlocal", "--all", }));
098
099 command.execute(tokens);
100 }
101
102 }