GlassFish V3 update

We published the first version of the V3 build during JavaOne, and it was time for an update of bits for the folks that don't want to build themselves...

The new build does not have new features compared to the list announced at JavaOne, it is basically bug fixes coupled with some rework of the implementation that I did not have the time to finish in may. One of the cool new feature is how the admin commands are discovered and processed by the runtime.

One of the difficulties associated with supporting multiple container types from various sources and that you want to make it easy for these container providers to simply use the runtime services offered by GlassFish. One of these services are administrative commands, during my JavaOne session, I actually demonstrated how to add new command : version.

So as everything in V3, we rely on HK2 components to identify administrative commands. So in this case, the AdminCommand interface is annotated with @Contract, so all you have to do to add a new command to GlassFish V3 is to create a Service implementing the AdminCommand interface and the runtime will find it :

package com.foo.bar;

@Service(name="super")
public class MySuperCommand implements AdminCommand {
...
}

Now this is nice but we can do better, for instance because admin commands are Services, we can use injection, so say for instance you want to have access the domain configuration, you just do

@Inject
Domain domain;

and the domain information will be injected in the instance field before the command execute() is invoked, that's nice but why not extending this to the command parameters. Too many times, I have seen command implementations code just ensure that all mandatory parameters to the command are present, values are correct, and extraction from the String[] representation.

This is where the new annotation @Param become useful, annotate any instance field of the command implementation with the @Param annotation to make it a command parameter. So for instance adding the following

@Param
String name

adds a name parameter to the command. Of course, parameters can be optional

@Param(optional=true)
String myoptionalparam

or the default parameter for the legion of lazy typers like me :

@Param(default=true)
String path
so you can now do : 
asadmin deploy --path foo.war
or
asadmin deploy foo.war

Of course there can be only one default parameter. Also the param tag is automatically linked to the resource file of your classloader, so when you add the

com.sun.foo.bar.mysupercommand=Some random super command
com.sun.foo.bar.mysupercommand.path=path to the file the command applies to.

strings to your LocalStrings.properties, the system will find them and use it for any type of error checking or help :

$prompt>asadmin super
FAILURE : super command requires the path parameter : path to the file the command applies to.

$prompt>asadmin super --help
Some random super command

Parameters :
        path : path to the file the command applies to.

The above behaviours are completely handled by the system, the command will not be executed as long as all mandatory parameters are provided by the users. There is more of course, like automatic help page and localized page creation.

Other things new in this build :
  1. HK2 injection manager is now reusable with other types of annotation than @Inject. I got the idea from Adam Bien, I also use it to inject the @Param we saw above
  2. Adding drivers to lib/shared will make them automatically discovered by the persistence provider.
  3. Support for all content types as defined in the domains/domain1/config/default-web.xml
  4. gem support (you can now build a gem file from the distribution and use jRuby to automatically install GlassFish V3 within a jRuby install)
Enjoy, spam me with comments.
Comments:

Post a Comment:
Comments are closed for this entry.
About

dochez

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today