admin@glassfish.java.net

How to Implement a "unsupported-legacy-command-name" in 3.1

From: Byron Nevins <byron.nevins_at_oracle.com>
Date: Wed, 05 May 2010 11:11:35 -0700

I just implemented the remote command stop-instance.  But  I had to make some edits in admin/cli because the command was an "unsupported-legacy-command-name". 
See below for details.
 
-------- Original Message --------
Subject: svn commit: r36773 - trunk/v3: admin/cli/src/main/resources cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster
Date: Wed, 05 May 2010 18:00:00 +0000
From: bnevins@dev.java.net
Reply-To: commits@glassfish-svn.dev.java.net
To: commits@glassfish-svn.dev.java.net


Author: bnevins
Date: 2010-05-05 17:59:56+0000
New Revision: 36773

Added:
   trunk/v3/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/LocalStrings.properties   (contents, props changed)
   trunk/v3/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/StopInstanceCommand.java   (contents, props changed)
Modified:
   trunk/v3/admin/cli/src/main/resources/supported-legacy-command-names
   trunk/v3/admin/cli/src/main/resources/unsupported-legacy-command-names

Log:
* Added the remote command -- stop-instance


Modified: trunk/v3/admin/cli/src/main/resources/supported-legacy-command-names
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/admin/cli/src/main/resources/supported-legacy-command-names?view=diff&rev=36773&p1=trunk/v3/admin/cli/src/main/resources/supported-legacy-command-names&p2=trunk/v3/admin/cli/src/main/resources/supported-legacy-command-names&r1=36772&r2=36773
==============================================================================
--- trunk/v3/admin/cli/src/main/resources/supported-legacy-command-names	(original)
+++ trunk/v3/admin/cli/src/main/resources/supported-legacy-command-names	2010-05-05 17:59:56+0000
@@ -152,3 +152,5 @@
 crete-jms-host R
 delete-jms-host R
 list-jms-hosts R
+stop-instance R
+

Modified: trunk/v3/admin/cli/src/main/resources/unsupported-legacy-command-names
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/admin/cli/src/main/resources/unsupported-legacy-command-names?view=diff&rev=36773&p1=trunk/v3/admin/cli/src/main/resources/unsupported-legacy-command-names&p2=trunk/v3/admin/cli/src/main/resources/unsupported-legacy-command-names&r1=36772&r2=36773
==============================================================================
--- trunk/v3/admin/cli/src/main/resources/unsupported-legacy-command-names	(original)
+++ trunk/v3/admin/cli/src/main/resources/unsupported-legacy-command-names	2010-05-05 17:59:56+0000
@@ -37,7 +37,6 @@
 delete-node-agent-config R
 list-instances R
 start-instance R
-stop-instance R
 start-cluster R
 stop-cluster R
 copy-config R

Added: trunk/v3/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/LocalStrings.properties
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/LocalStrings.properties?view=auto&rev=36773
==============================================================================
--- (empty file)
+++ trunk/v3/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/LocalStrings.properties	2010-05-05 17:59:56+0000
@@ -0,0 +1,3 @@
+
+stop.instance.command=Stop a running instance
+stop.instance.init=Server shutdown initiated

Added: trunk/v3/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/StopInstanceCommand.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/StopInstanceCommand.java?view=auto&rev=36773
==============================================================================
--- (empty file)
+++ trunk/v3/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/StopInstanceCommand.java	2010-05-05 17:59:56+0000
@@ -0,0 +1,95 @@
+/*
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008-2010 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License").  You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code.  If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license."  If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above.  However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package com.sun.enterprise.v3.admin.cluster;
+
+import com.sun.enterprise.module.ModulesRegistry;
+import com.sun.enterprise.module.Module;
+import com.sun.enterprise.util.LocalStringManagerImpl;
+import org.glassfish.api.Async;
+import org.glassfish.api.I18n;
+import org.glassfish.api.Param;
+import org.glassfish.api.admin.AdminCommand;
+import org.glassfish.api.admin.AdminCommandContext;
+import org.jvnet.hk2.annotations.Inject;
+import org.jvnet.hk2.annotations.Service;
+
+import java.util.Iterator;
+import java.util.Collection;
+
+/**
+ * AdminCommand to stop the instance
+ * server.
+ *
+ * @author Byron Nevins
+ */
+@Service(name="stop-instance")
+@Async
+@I18n("stop.instance.command")
+public class StopInstanceCommand implements AdminCommand {
+
+    final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(StopInstanceCommand.class);
+    
+    @Inject
+    ModulesRegistry registry;
+
+    @Param(optional=true, defaultValue="true")
+    Boolean force;
+    
+
+    /**
+     * Shutdown of the application server : 
+     *
+     * All running services are stopped. 
+     * LookupManager is flushed.
+     */
+    public void execute(AdminCommandContext context) {
+         
+        context.getLogger().info(localStrings.getLocalString("stop.instance.init","Server shutdown initiated"));
+        Collection<Module> modules = registry.getModules(
+                "org.glassfish.core.glassfish");
+        if (modules.size() == 1) {
+            final Module mgmtAgentModule = modules.iterator().next();
+            mgmtAgentModule.stop();
+        } else {
+            context.getLogger().warning(modules.size() + " no of primordial modules found");
+        }
+        if (force) {
+            System.exit(0);
+        }
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@glassfish-svn.dev.java.net
For additional commands, e-mail: commits-help@glassfish-svn.dev.java.net