http://java.sun.com/javaone http://java.sun.com/javaone http://java.sun.com/javaone
JavaOne - Experiencing Java technology through education, industry, and community
  2009 Platinum Cosponsor
Intel
  Cosponsors
Cosponsors
  Gen Session Cosponsors
General Session Cosponsors
  Media Sponsors
Media Cosponsors
Home > Dynamic Languages Powered by GlassFish v3 Application Server

Dynamic Languages Powered by GlassFish v3 Application Server


Vivek Pandey, GlassFish technical lead for scripting languages support, and Jacob Kessler, GlassFish scripting engineer and self-described code monkey, presented Dynamic Languages Powered by GlassFish v3 Application Server (TS 4921) on Wednesday at the JavaOne conference. The two Sun engineers focused their presentation on the Python, Ruby, and Groovy languages.

GlassFish accommodates Python through the Jython interpreter, which provides interoperability with the JVM* through Java interfaces. For Ruby, the JRuby interpreter provides automatic translation and just-in-time compilation. Groovy was designed from the ground up to be fully compiled to Java bytecode. GlassFish handles each of these languages automatically.

The Right Tool for the Job

Kessler began by explaining what a dynamic language is: Broadly speaking, it is a language that allows a program to change its own code at runtime, often changing functions in response to runtime conditions. It can evaluate data as code and manipulate code as data. It lets you use higher-order functions, which are functions that take other functions as arguments. Many dynamic languages also use dynamic typing. Finally, dynamic languages usually emphasize a simple, human-readable syntax.

The GlassFish open-source application server is the reference Java EE implementation. GlassFish v3, now in preview release, will implement Java EE 6 in its full release, due later in 2009. GlassFish has typically been used to deploy Java EE applications, but it can also be used to deploy applications coded in several dynamic languages, both as web archive (WAR) files and in native formats.

Dynamic languages have some advantages over the Java programming language. Most importantly, coding is often quicker, with less overhead and shorter code iterations. Syntax is often cleaner, emphasizing essence over ceremony. GlassFish enables you to use dynamic languages while keeping the benefits of Java EE.

Running dynamic language applications on GlassFish has the advantages of agile development, flexibility, metaprogramming, and runtime code generation. In addition, dynamic languages are often specific to a problem domain. Disadvantages include slower execution, limits to scalability due to such constraints as global locks, and a general lack of maturity when compared with more established languages such as Java.

For all its verbosity, the Java programming language offers higher runtime performance and scalability, many libraries and frameworks to choose from, and the maturity that results from years of collaborator contributions and testing.

All of which is to say, choose the right tool for the job. By integrating dynamic languages with Java and deploying in GlassFish, you can use each language for the part of the overall project for which it is best suited. For example, you can access the Java Message Service (JMS) queue from Ruby on Rails, or access Java technology-based cryptography libraries from a Groovy web application.

About GlassFish v3

GlassFish v3 is a multilanguage application server with support for many web frameworks, among them Grails, Rails, Merb, Sinatra, and Django. No Java EE experience is required to use these frameworks. With GlassFish, you use the same deploy command for all of them. No packaging into WAR files is required, and no change in a framework's programming model. Deploying on GlassFish gives you the best of both worlds: You can run dynamic language applications along with Java EE applications.

GlassFish supports dynamic languages through its pluggable web framework architecture.


GlassFish Pluggable Web Framework Architecture

The centerpiece of the GlassFish architecture is its kernel. The kernel has two abstractions that allow containers to plug in to it: dependency injection and modularity.

A container is a piece of code that is responsible for running a language-specific application. For example, the web container is responsible for enabling a servlet to run; the JRuby container enables Ruby code to run; and the Jython container enables Python code to run.

Web applications almost always involve a web framework as well as a language interpreter. Web framework interfaces provide the contracts between containers and frameworks: the Servlet Specification interface for web containers, the Rack interface for JRuby containers, a Web Server Gateway Interface (WSGI) for Jython containers, and so on. GlassFish v3 is designed for this multiple level of extensibility.

Embedded interpreters in GlassFish v3 are configured for optimized usage. For example, because most dynamic languages are single-threaded, they occasionally produce global locks that limit performance. The embedded interpreters furnish dynamic runtime pools to improve performance and scalability.

Ruby Scaling

Ruby scaling on native servers is accomplished through load balancing and a separate server, typically Mongrel, for each session. For scaling to larger loads, you enlarge the server cluster and add more application instances.


Ruby Scaling on Native Servers

In contrast, scaling for Ruby in GlassFish v3 is based on dynamic runtime code. When you deploy a Ruby application, you can set up the runtime so that each of the interpreted runtimes is instantiated and added to a pool. The pool can dynamically shrink and grow and is highly customizable.


Ruby Scaling on GlassFish v3

Ruby Support

Ruby support on GlassFish is Rack compliant, meaning that GlassFish wires a web server to a Ruby application. The strategy is based on WSGI from Python.

On GlassFish, you can run any Ruby application that supports Rack, which in turn is supported by all Ruby frameworks: Rails (starting with version 2.3.2), Merb, Sinatra, and Campsite among them.

GlassFish v3 has built-in support for Rails, Merb, and Sinatra -- and if that's not enough, you can run your own Ruby framework because pluggable frameworks are supported. Using the Rack autodetector, GlassFish can automatically detect your framework.


Ruby Pluggable Framework Support

Ruby deployment is enabled by the pluggable framework architecture. When you deploy a Ruby application, a Rack autodetector introspects your application. If it is based on Rails, Merb, Sinatra, or another framework, GlassFish knows how to deploy it automatically. If you want to write your own framework, you may need to provide a Rack-up script that implements the Rack interface. GlassFish then detects your framework automatically when you deploy the application.

Monitoring in GlassFish

Monitoring in GlassFish is based on a probe infrastructure that is transport agnostic. There are several ways to monitor your application under GlassFish v3. GlassFish probes emit monitoring data and are exposed as DTrace probes, but they are also available to Java Management Extensions (JMX) beans or RESTful services.

If your system is extraordinarily complex and requires special monitoring, you can write your own monitoring client in JavaScript and deploy as a service on GlassFish.

Ruby Monitoring

With Ruby applications running in GlassFish, you can monitor HTTP statistics, JRuby interpreter statistics, and JRuby runtime pool statistics using DTrace, JMX, your custom script, or REST.

You can develop, deploy, and debug your Ruby applications with the NetBeans IDE. Full support for GlassFish v3 is provided by NetBeans IDE 6.7, now a release candidate.

GlassFish as a Ruby Gem

For a lightweight and robust deployment solution for Ruby applications deployed on the JRuby runtime, try the GlassFish Ruby gem. Based on the GlassFish v3 kernel, the gem is approximately 2.5 MB in size.

Python and Django on GlassFish

GlassFish uses Jython as its interpreter for Python applications. The Jython container, like that for JRuby, extends GlassFish. It uses the Jython Grizzly Adapter for HTTP processing. WSGI support makes other Python frameworks simple to plug in.

Deployment of a Python or Django application on GlassFish is as simple as the following command:

$ asadmin deploy myDjangoApp/ 

Groovy and Grails

Groovy is a dynamic language that is especially friendly to Java developers. It shares many Java constructs and was originally written to run on the JVM. Groovy is usually developed with the Grails framework for easier programming.

On GlassFish, Grails applications are deployed in the web container. When deployed as a WAR file, a typical Grails application contains 48 JARs and may be 18 MB in size. A more efficient deployment creates a shared WAR file of only 200 KB.

The Grails package for GlassFish is available on the GlassFish v3 update center. For more efficient development, GlassFish can be installed as a Grails plug-in. It will be invoked whenever you run the Grails application.

Java EE 6

The presenters touched on Java EE 6 and its future with dynamic languages, but they left details to other technical sessions that are focused on the Java EE 6 release.

_______
* As used on this web site, the terms "Java Virtual Machine" and "JVM" mean a virtual machine for the Java platform.

 

Do you have comments about this article? We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of replies - your information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.