
mardi novembre 24, 2009
Back from Devoxx 2009 (a JavaEE 6/GlassFish v3 perspective)
This was Devoxx' 8th edition and my personal 5th (I think).
I think the Java EE 6 and particularly GlassFish v3 were very well received at this year's Devoxx 2009 conference. Of course some of it has to do with the fact that both are almost final (Java EE 6 spec lead Roberto Chinnici announced at the event that it'll be done on December 10th 2009). But I like to think that there's much more to it.
The Java EE 6 session that Antonio Goncalves and myself ran as a university 3-hour talk was packed and (this is the real test), all came back after the break. We went through 12 or so demos (with minimal failure I should say) from a simple managed beans to a working application with JSF 2, Servlet 3.0, JAX-RS 1.1, JPA 2, EJB 3.1 (including testing, Antonio's favorite). It seems that people enjoyed the level of information and the step-by-step approach. As any other talks at the conference, this one should be made available on parlays (for a fee) real soon. We're working to make to code for the samples available one way or another. Stay tuned. Update: the session is now live on Parleys: Part 1 and Part 2. Antonio's 1-hour talk is here. All talks are for a fee.
The Java EE BOF (a last minute addition) was packed and a good moment, and to me what BOF's should look like (too many people use it do deliver regular PPT-based presentations). With a panel of JSR and project leads, the discussion centered around availability of Java EE 6 implementations, new features such as managed beans and JSR 299, how JSR's can produce multiple specs, etc... Nice interactive crowd. The speaker's diner that evening was an occasion to meet Oracle's Steve Harris, the keynote speaker for the next morning.
The first "conference" day had three keynotes : Oracle, Sun, and Adobe. The feedback on Oracle's keynote via tweets, blogs, and discussions wasn't so good but I think that with the given circumstances it made clear that Oracle cared and was no stranger to how the Java community is structured, how it evolves, and what the challenges are. The demos were what people remembered it seems. Sun's keynote was given by Roberto and Ludo (already available on Parleys) and, in 30 minutes, covered Java EE 6 and demoed GlassFish v3 - fast startup, deploy on change, preserve session on redeploy, and OSGi bundle invocation straight from a servlet were all shown in only a few minutes. I think that this is the first conference in a while where people don't ask me about GlassFish's future (and I did talk to many people during the event). This is both the result of what they saw and of the recently updated FAQ by Oracle.
JBoss was pretty well represented this year but for some (planning?) reason there was no dedicated talk on JSR299. It was certainly very nice to see JBoss strongly supporting Java EE 6 (beanvalidation, 299, JSF 2, etc...). Other highlights for me at the conference were the JDK 7 closure proposal, project Lombok looks interesting (including in a Java EE context), not quite convinced by Gradle (Maven 3 releasing in January may steal its thunder), and Kees Jan's monitoring/performance talk was pretty good. I'm amazed to see the number of people attend those performance talks - the GC is no longer the issue and there hasn't been any technology or performance tool break-through in a while (btrace is the only thing that comes close and Simon covered that). Clearly SOA is disappearing from the agenda year after year (although people had good things to say about SOA in Practice session), and leaving room for the cloud talks.
( nov. 24 2009, 12:14:21 PM CET )
Permalink

lundi novembre 23, 2009
GlassFish Embedded Reloaded, an appserver in your pocket
It wasn't enough for GlassFish v3 to be broken into 200+ OSGi bundles executable on different OSGi implementations such as Felix or Equinox (or even without OSGi, i.e. in "Static" mode), we also had to make it embeddable.
In a previous entry, I discussed EJBContainer.createEJBContainer() (a standard EJB 3.1 API) which is really a specific use-case of the more generic case of using the GlassFish Embedded API. The latter is the topic of this newer post and whichever you decide to use, you should remember that this is all one code-base offering different facets with as many entry points.
Definition
GlassFish embedded is in-process integration of the GlassFish v3 features (not just the web container) using an API to start/stop/configure the server and its containers and to deploy/undeploy applications.
While this definition and the use-cases (testing, shipping shrink-wrapped apps, ...) has not changed since GlassFish v3 Prelude which shipped a year ago, the API has substantially evolved (up to promoted build 65 in late September I believe) as you can read below and can now be considered stable. As you'll see later in this post, the deployment can be trivial.
An overview of the API
Main classes are :
org.glassfish.api.embedded.Server
org.glassfish.api.embedded.EmbeddedFileSystem
org.glassfish.api.embedded.ContainerBuilder
org.glassfish.api.embedded.EmbeddedDeployer
org.glassfish.api.deployment.DeployCommandParameters
The API offer a flexible inner-class Builder pattern :
EmbeddedFileSystem.Builder efsb = new EmbeddedFileSystem.Builder();
efsb.installRoot(EmbeddedServerUtils.getServerLocation());
Simple Hello world
Let me walk you through a simple example which deploys an existing WAR from a main() which in turn would let you ship and start the entire app using a JAR (full source here). I'll leave it as a simple exercise to the reader to adapt it to the testing use-case.
First the logic :
foo.Embedded myGlassFish = new foo.Embedded("myArchive.war"); // init with the archive name
myGlassFish.start();
boolean deployed = myGlassFish.deploy();
if (deployed) {
// TODO: do something useful like wait for a shutdown order
}
myGlassFish.undeployAndStop(); // stops and exits the JVM
The startup process :
public void start() throws IOException {
Server.Builder builder = new Server.Builder("testBuilder");
// get the builder for EmbeddedFileSystem
EmbeddedFileSystem.Builder efsb = new EmbeddedFileSystem.Builder();
EmbeddedFileSystem efs = efsb.build();
builder.embeddedFileSystem(efs);
// Start the embedded server (should take no more than a few of seconds)
server = builder.build();
// Add a WEB container (other containers include ejb, jpa, all, ...)
ContainerBuilder containerBuilder = server.createConfig(ContainerBuilder.Type.web);
server.addContainer(containerBuilder);
containerBuilder.create(server);
server.createPort(port); // Starts grizzly on the given port
}
The deployment :
public boolean deploy() {
// Setup machinery to deploy
deployer = server.getDeployer(); // type is EmbeddedDeployer
DeployCommandParameters deployParams = new DeployCommandParameters();
deployParams.name = "myApplication"; // needed for undeploy
deployParams.contextroot = context; // overrides whatever the WAR contains
// Creates default virtual server, web listener, does the deploy and
// returns the applicationName as a String (null means something went wrong)
// duration depends on application size and nature. Heavy lifting done here.
File archive = new File(archiveName);
applicationName = deployer.deploy(archive, deployParams);
return (applicationName == null) ? false : true;
}
... and the cleaning up :
public void undeployAndStop() throws LifecycleException {
deployer.undeploy(applicationName, null); // Could have undeploy params like cascade, ...
server.stop(); // May take a little while to clean everything up
System.exit(0); // to kill any threads left running
}
The above example is only scratching the surface. You can deploy exploded archives (check out the org.glassfish.api.embedded.ScatteredArchive API) or reuse an existing domain.xml configuration file for instance. I'd like to encourage you to look around the various Embedded tests to find out more about the richness of the API.
As little as one JAR
There are two modes for running GlassFish Embedded :
• implanted: this uses an existing GlassFish installation and requires having glassfish/lib/embedded/glassfish-embedded-static-shell.jar in your classpath. The JAR itself is an empty shell with relative references to all the JARs in the GlassFish v3 distribution. This is approach taken by NetBeans project tests for example.
• autonomous: for easier distribution an all-in-one JAR file is available in two flavors: full profile (40 MB) and web profile (30 MB). Not bad for a full-blown app server! The complete application+runtime bundle can then be deployed using Maven, an installer (such as IzPack), a jar file (eventually wrapped in an .exe) or even via Java Web Start.
Still early days
Whether you're using the implanted or autonomous mode (using the uber-jar), you'll be running the same code, simply using different entry paths. Because of the different packaging and the temporary filesystem layout the autonomous mode uses, differences are always possible. Many issues were fixed in the past couple of months thanks, including some by users themselves.
Note that there is no OSGi involved in the embedded mode (I don't think this is a limitation, but it's certainly an important data point). It is much like running in static mode (same classloader hierarchy). There are also some limitations such as TimerEJB not being supported for the time being. But other than that, a non-trivial application like Hudson deploys to GlassFish embedded like a charm.
If this sounds interesting to you, please use a recent promoted build (b73 and above) or wait (a few weeks) for the GlassFish v3 final release in December (2009) and certainly ask questions on the USERS mailing list (or forum), and share your experience via blogs, tweets, etc...
( nov. 23 2009, 04:38:56 PM CET )
Permalink

mercredi novembre 11, 2009
Atmosphere jeudi, Devoxx lundi
Pas le temps de respirer, demain Jeudi Jean-François Arcand sera là au ParisJUG pour vous donner un cours de bon français et pour vous parler d'Atmosphere, le framework multi-serveur pour faire du Comet (AjaxPush). Il y sera également question de comparaison avec Servlet 3.0 (ne pas oublier de s'inscrire, il doit rester des places).
Lundi, direction Anvers pour la conférence Devoxx. J'y présente avec notre Antonio Goncalves national (enfin c'est surtout lui qui fait le gros du boulot!) une session de trois heures sur Java EE 6 (dont les JSR sont approuvées les unes après les autres ces jours-ci). Entre consolidation des slides, mise au point des démos, et ajouts de dernière minute, on n'est pas tout à fait près...
Avec servlet 3, managed beans, bean validation, etc... cette session ira clairement au delà du contenu du bouquin d'Antonio (pourtant déjà très riche). Reste la question du JSR 299 qui mérite une session à lui tout seul (difficile de ne faire qu'une intro, la technologie a un ticket d'entrée non négligeable). En tout cas je trouve la progression dans la douzaine de démos plutôt sympa (une idée d'Antonio).
Pour ce qui est du contenu GlassFish (keynote, sessions, etc...): les détails sont ici.
( nov. 11 2009, 11:24:55 AM CET )
Permalink

lundi novembre 09, 2009
La présentation du séminaire GlassFish
( nov. 09 2009, 03:02:00 PM CET )
Permalink
javax.annotation.ManagedBean
You might have hear or "managed beans" before, but chances are these will be new to you. These are not specific to JSF and not related to JMX in any way. Rather, Java EE 6 (well EJB 3.1 to be precise) specifies Managed Beans 1.0, or lightweight components.
Managed beans are plain old java objects whose life-cycle is governed by the container (allowing for creation and destruction callbacks) and supports resource injection (and of course can themselves be injected). To define a managed bean, you simply need to annotate a class with @java.annotation.ManagedBean. You can apply the existing (JSR 250) @PostConstruct and @PreDestroy annotations to methods in that bean and inject resources using @Resources (as well as with @EJB or @WebServiceRef). Here's a simple example :
@javax.annotation.ManagedBean
public class MessagesBean {
@Resource
TranslationBean localizer;
@PostConstruct
public void myInit() {
System.out.println("*** Constructed!");
// Do something useful
}
public String getTranslatedMessage(String message) {
return localizer.translate(message);
}
}
Such a class can then be deployed within a WAR, an EJB-JAR or an ACC-JAR and can be injected within another Managed Bean, a servlet, an EJB or a JSF Managed Bean using a simple @Resource MessagesBean bean; statement. Life-cycle and injection in itself is nice but it gets even better with interceptors which can also be applied to managed beans (no longer to just EJB's) :
@Interceptors(LogInterceptor.class)
@javax.annotation.ManagedBean
public class MessagesBean {
...
}
Whether Managed Beans will be used directly by application developers or mostly for building higher level abstractions such as EJB's (transactional managed beans in a sense), JAX-WS endpoints (SOAP-enabled managed beans) or JSR 299 is yet to be defined. You decide.
You can of course try all of the above in GlassFish v3.
( nov. 09 2009, 09:19:56 AM CET )
Permalink

vendredi novembre 06, 2009
IzPack and GlassFish v2.1.1
My friend Julien announces that IzPack 4.3.2 has just been released.
As a cherry on the cake, he also refreshed the GlassFish v2 IzPack installer to v2.1.1 which was just release a few days ago. Thanks Julien!
( nov. 06 2009, 02:42:16 PM CET )
Permalink

mardi novembre 03, 2009
Webinar GlassFish - aujourd'hui à 16h
La présentation en ligne GlassFish est toujours prévue pour aujourd'hui (mardi 3 novembre) à 16h00 (heure de Paris, amis francophones du monde entier vous êtes les bienvenus!). Il n'est pas trop tard pour s'inscrire.
Jérôme Dochez (l'architecte de GlassFish) et Didier Burkhalter (la cheville ouvrière de nombreux projets GlassFish en entreprise) seront là pour m'aider à répondre au question pendant et après la présentation qui sera relativement courte (environ 30 minutes). A tout à l'heure.
( nov. 03 2009, 08:26:21 AM CET )
Permalink

samedi octobre 31, 2009
Bug hunting and FishCAT'ing
If anything, the traffic on the "issues" GlassFish mailing list should be a hint on the stabilization work going on before v3 is declared final later this year.
At the same time the FishCAT team is also busy testing the latest releases.
( oct. 31 2009, 11:29:33 PM CET )
Permalink

jeudi octobre 29, 2009
GlassFish v2.1.1 est là
Je ne sais pas si c'est pour fêter la sortie de GlassFish v2.1.1, mais Oracle vient de publier des nouvelles largement rassurantes sur GlassFish dans une nouvelle FAQ sur l'avenir de plusieurs produits Sun dans l'eco-système Oracle une fois l'acquisition finalisée. Il y est entre autre question de continuer un support actif à la communauté et aux clients GlassFish ainsi que d'alignements technologiques entre GlassFish Enterprise et Weblogic. Pour qui connaît les deux offres, je pense que cela apparaîtra assez naturel.
On notera qu'aujourd'hui déjà GlassFish utilise EclipseLink (l'implémentation de référence de JPA) alors que WebLogic 10g et 11g utilisent de multiples technologies de GlassFish comme en témoigne ces pages de modifications apportées par Oracle.
Quoi qu'il en soit, comme je le disais en début de billet, c'est la version 2.1.1 qui est rendue aujourd'hui disponible en même temps que Sun GlassFish Communication Server 2.0 (Sailfin 2.0), l'offre de serveur d'application Telco (SIP, Diameter, etc...) développée avec Ericsson. En attendant la version 3 en décembre, voici donc une version pour tous les clients actuels de GlassFish qui attendent avant tout des évolutions mineures (pour eux, plus de 200 bugs corrigés ce n'est pas mineur) pour leurs systèmes en production plus que des nouveautés comme v3 en apportera. Rarement l'équipe GlassFish aura été aussi sollicitée.
GlassFish 2.1.1 est une mise à jour de la version la plus largement déployée de GlassFish en production (niveau d'API Java EE 5). On y trouve de nouvelles versions de composants importants (Java MQ 4.4 / Jersey 1.0.3 / JSF 1.2_13 / Grizzly 1.0.30 / Metro 1.1.6), le support de AIX 6 et de mod_jk ainsi qu'une nouvelle option de partage de charge (par connexion) dans l'ORB. Enfin, le méchanisme de gestion de groupe Shoal propose des améliorations des node agents pour une meilleure détection (plus rapide, plus fiable) des noeuds d'un cluster. Bien entendu cette version continue de proposer une extreme simplicité pour la mise en place d'un cluster et les outils de gestion production GlassFish Enterprise Manager.
Téléchargement de GlassFish 2.1.1 ici: https://glassfish.dev.java.net/downloads/v2.1.1-final.html et n'oubliez pas le séminaire en ligne GlassFish de la semaine prochaine.
( oct. 29 2009, 08:39:57 AM CET )
Permalink

mercredi octobre 28, 2009
Oracle's take on GlassFish
On don't think this will quite stop people from asking (me and others on the team) the same question, but this new FAQ from Oracle certainly has some positive information on GlassFish's future. The blogosphere and twitosphere have been quite active on that news today...
( oct. 28 2009, 11:55:28 PM CET )
Permalink
Séminaire en ligne GlassFish la semaine prochaine
Avec l'activité autour de GlassFish (sortie imminente de v2.1.1, v3 dans quelques semaines avec Java EE 6) et le succès du livre blanc, il nous a semblé opportun d'organiser un séminaire en ligne pour faire le point sur l'avancement du projet et pour répondre à vos questions. Ce sera donc le
Mardi le 3 novembre 2009 (dans une semaine) à 16h00
Le format est classique: 45 minutes de présentation et le reste de questions/réponses. N'oubliez pas de vous inscrire pour obtenir les détails (URL et mot de passe).
( oct. 28 2009, 09:47:46 AM CET )
Permalink

mercredi octobre 07, 2009
Recent GlassFish endorsements
• Servlet 3.0 (JSR 315) support in Maia
• How to install and use JRebel with Glassfish and Eclipse IDE
• ColdFusion - Installation, deployment, and platforms
• New Java-monitor probe for Glassfish users.
I think I also saw something recently on either EHCache or TerraCotta as well...
( oct. 07 2009, 03:20:06 PM CEST )
Permalink
Attending and presenting at Java2Days this week in Sofia
I'll be attending the Java2Days conference at the end of this week in Sofia, Bulgaria.
The conference is quite geared towards server-side Java with Spring and Java EE getting great coverage with SpringSource employees and Java EE expert group member Reza Rahman.
My first talk on Thursday is on GlassFish v3 while the second is on portability of J2EE/JavaEE applications (lessons learned while migrating customer applications to GlassFish). Should be fun!
( oct. 07 2009, 10:13:50 AM CEST )
Permalink

lundi octobre 05, 2009
Using the EJBContainer API with or without Maven (but with GlassFish v3)
Updated this blog on October 28th as you no longer need to have a full GlassFish install to test EJBs
The typical way to start GlassFish is to use $asadmin start-domain but you could also start it using java -jar modules/glassfish.jar. Both start a standalone instance of GlassFish. The following paragraphs discuss GlassFish Embedded (i.e. start it using an API).
There are at least two ways to start GlassFish in embedded mode: using org.glassfish.api.embedded.Server and associated classes but also using the (now standard in EJB 3.1) EJBContainer.createEJBContainer() API. Let me describe here the latter one and reserve the more general embedded case for a later blog entry.
The goal is to write something like as simple as this to test your EJB :
EJBContainer c = EJBContainer.createEJBContainer(); // new in EJB 3.1!
Context ic = c.getContext();
SimpleEjb ejb = (SimpleEjb) ic.lookup("java:global/sample/SimpleEjb");
ejb.sayHello();
EJB's found in the classpath of the running code above will automatically be deployed and made available via lookups.
Calls to EJBContainer.createEJBContainer() are likely to be made from your tests. If you're making those calls by constructing yourself the execution classpath, then you simply need to add glassfish/lib/embedded/glassfish-embedded-static-shell.jar, an empty jar with a Class-Path: listing the required jars and that is part of the GlassFish distro. In fact, if you're using recent builds of NetBeans 6.8 (and the soon-to-be-released beta), the IDE does this for you when GlassFish is the target server. If you are using Maven, it's a bit trickier.
To use EJBContainer.createEJBContainer() from Maven tests, you'll need to add the following dependency to your POM (updated to promoted b70):
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.0-b70</version>
<scope>test</scope>
You could restrict this to a smaller set of GlassFish artifacts but for non-trivial tests (if you use JPA for instance), you would start to have a fairly long list of dependencies so the above sounds like a reasonable thing to do. This will require Maven to download the GlassFish All-in-one JAR file (40MB or so). The reason I wrote it would be trickier with maven is that you need to pass a property during the createEJBContainer() call indicating the location of a GlassFish v3 install. The above Java code would need to read something like this:
Map p = new HashMap();
p.put ("org.glassfish.ejb.embedded.glassfish.installation.root",
"/path/to/glassfish"); // include trailing "/glassfish"
ec = EJBContainer.createEJBContainer(p);
As of build 69 (maybe 70?), this is no longer needed - i.e. you can simply have glassfish-embedded-all.jar as a dependency or simply in your classpath. A full install of GlassFish is no longer required (although it may be interesting if you want to use JDBC configurations). Read this blog by Thomas for another interesting approach: Nice follow-up blog here: http://ctpjava.blogspot.com/2009/10/unit-testing-ejbs-and-jpa-with.html
Starting the appserver this way (with or without Maven) exercises the actual GlassFish code, not another implementation or a customized fork. There are some limitations to what you can run and in particular port configuration is ignored (not listening on any) and only local EJB interfaces are available (the spec only requires EJB 3.1 lite support). On the other hand, JPA calls are very much possible.
This should all work with v3 promoted build 66 (I just tested this with promoted build 70, see above simplification). Adam Bien beat me to covering that topic, but I hope you get some additional info here. In my case the start-up, setup, deploy and shutdown of GlassFish Embedded are worth about 6 seconds. Note that there is no OSGi involved here.
For a complete working example with JPA calls, check out this sample code.
The EJB 3.1 specification has a chapter (#22) on "Embeddable Usage". Check it out for further details about EJBContainer.
( oct. 05 2009, 05:40:10 PM CEST )
Permalink

lundi septembre 28, 2009
"Le futur de Java" ce jeudi à l'OpenWorldForum
Ce jeudi, vous êtes conviés à venir à l'Open World Forum qui se tient à Paris (Eurosites George V dans le 8ème) et en particulier à la series de courtes sessions autour de Java.
Avec l'imminence du rachat par Oracle de Sun, un point sur Java semblait intéressant et utile. Au programme, le chemin parcouru par Java SE depuis sa mise en Open Source et les avancées prochaines de JDK7, une table ronde sur les langages dynamiques sur la JVM (Groovy, Scala, Fan, et Clojure, ou Jython, JRuby et PHP?), et enfin un point sur Java EE 6 et son implémentation de référence GlassFish v3. Notre Guillaume Laforge sera de la partie pour la table ronde.
Ce sera bref (1h30 au total), mais une occasion concrète de faire le point sur les travaux en cours et sur ce que le futur proche nous réserve.
• Programme: http://openworldforum.org/program/floss-java.
• Enregistrement, c'est ici: http://openworldforum.org/Register.
( sept. 28 2009, 09:02:24 AM CEST )
Permalink