1. Introduction to the Development Environment for Enterprise Server Add-On Components
3. Extending the Administration Console
4. Extending the asadmin Utility
About the Administrative Command Infrastructure of Enterprise Server
Representing an asadmin Command as a Java Class
Specifying the Name of an asadmin Command
Adding Parameters to an asadmin Command
Representing a Parameter of an asadmin Command
Identifying a Parameter of an asadmin Command
Specifying Whether a Parameter Is an Option or an Operand
Specifying the Name of an Option
Specifying the Long Form of an Option Name
Specifying the Short Form of an Option Name
Specifying the Acceptable Values of a Parameter
Specifying the Default Value of a Parameter
Specifying Whether a Parameter Is Required or Optional
Example of Adding Parameters to an asadmin Command
Adding Message Text Strings to an asadmin Command
Enabling an asadmin Command to Run
Setting the Context of an asadmin Command
Changing the Brand in the Enterprise Server CLI
Examples of Extending the asadmin Utility
5. Adding Container Capabilities
6. Packaging, Integrating, and Delivering an Add-On Component
An asadmin command identifies the operation or task that a user is to perform. Adding an asadmin command enables the user to perform these tasks and operations through the asadmin utility.
The following topics are addressed here:
Each asadmin command that you are adding must be represented as a Java class. To represent an asadmin command as a Java class, write a Java class that implements the org.glassfish.api.admin.AdminCommand interface. Write one class for each command that you are adding. Do not represent multiple asadmin commands in a single class.
Annotate the declaration of your implementations of the AdminCommand interface with the org.jvnet.hk2.annotations.Service annotation. The @Service annotation ensures that the following requirements for your implementations are met:
The implementations are eligible for resource injection and resource extraction.
The implementations are location independent, provided that the component that contains them is made known to the Enterprise Server runtime.
For information about how to make a component known to the Enterprise Server runtime, see Integrating an Add-On Component With Enterprise Server.
To specify the name of the command, set the name element of the @Service annotation to the name.
Note - Command names are case-sensitive.
Commands that are supplied in Enterprise Server distributions typically create, delete, and list objects of a particular type. For consistency with the names of commands that are supplied in Enterprise Server distributions, follow these conventions when specifying the name of a command:
For commands that create an object of a particular type, use the name create-object.
For commands that delete an object of a particular type, use the name delete-object.
For commands that list all objects of a particular type, use the name list-objects.
For example, Enterprise Server provides the following commands for creating, deleting, and listing HTTP listeners:
create-http-listener
delete-http-listener
list-http-listeners
You must also ensure that the name of your command is unique.
To obtain a complete list of the names of all asadmin commands that are
installed, use the list-commands(1) command. For a complete list of asadmin commands
that are supplied in Enterprise Server distributions, see
Sun GlassFish Enterprise Server v3 Reference Manual.
To enable multiple clients to run a command simultaneously, ensure that the implementation of the AdminCommand interface for the command is stateless. To ensure that the implementation of the AdminCommand interface is stateless, annotate the declaration of your implementation with the org.jvnet.hk2.annotations.Scoped annotation. In the @Scoped annotation, set the scope as follows:
To instantiate the command for each lookup, set the scope to PerLookup.class.
To instantiate the command only once for each session, set the scope to Singleton.
This example shows the declaration of the class CreateMycontainer that represents an asadmin command that is named create-mycontainer. The command is instantiated for each lookup.
package com.example.mycontainer; import org.glassfish.api.admin.AdminCommand; ... import org.jvnet.hk2.annotations.Service; ... import org.jvnet.hk2.annotations.Scoped; import org.jvnet.hk2.component.PerLookup; /** * Sample command */ @Service(name="create-mycontainer") @Scoped(PerLookup.class) public Class CreateMycontainer implements AdminCommand { … }