1 2 3 Previous Next


38 posts
Glassfish 4.0 is released. This is the reference implementation for Java EE 7 and focusses on HTML 5 and improving developer productivity.  You can download the bits from here https://glassfish.java.net/download.html Apart from the Java EE 7 support in GlassFish 4.0 there have been numerous other areas where Glassfish 4 has provided lots of improvements and innovation [url=https://twitter.com/MartinJMares/]Martin Mares[/url]  ,[url=https://blogs.oracle.com/kasso/] Chris Kasso[/url] and I have been working  on the Admin Command Framework. These are some new enhancements that were added to Glassfish 4.0. [b]o Support for Progress status using Server Sent Events[/b] [b]o Job Management support[/b] [h2]Support for Progress status in commands using Server Sent Events.[/h2] This section will cover the newly introduced [b]@Progress[/b] annotation. We will walk through the basic usages of Progress API. Next we will see how ServerSentEvents fits in with the Progress API. [h3] Progress API in Glassfish 4.0[/h3] Consider some long running commands say start-cluster. It would be useful to be notified about the progress of the command as it is executing. To facilitate support for Progress status in AdminCommands a new annotation [b]@Progress[/b] is added. Any command which wants to use the Progress status API can be annotated with [b]@Progress[/b] The ProgressStatus object can be obtained from the [b]AdminCommandContext[/b]. The Progress API can be used to specify the total steps for execution. Once the total steps are known the percentage can be computed. Additionally the ProgressStatus API takes a message that can be added as the command progresses like Installing, Parsing... etc. As the command is executing, the progress can be updated by specifying the steps and the message to be sent to the client.
public class SomeCommand implements AdminCommand {
  public void execute(AdminCommandContext context) {

       ProgressStatus ps = context.getProgressStatus();
       ps.progress(1, "Parsing files..");
The above snippet shows the [b]@Progress[/b] annotation on the command. It also demonstrates how to get the [b]ProgressStatus[/b] object from the [b]AdminCommandContext[/b]. It shows how to use the[b] ProgressStatus.progress()[/b] method to specify the number of steps taken and a message to be emitted. Here is the Progress Status API which command developers can read for detailed information. http://grepcode.com/file/maven.java.net/content/groups/promoted/org.glassfish.main.common/glassfish-api/4.0-b78/org/glassfish/api/admin/ProgressStatus.java [h3] Using ServerSentEvents to emit progress[/h3] Server-Sent Events (SSE) is a technology for providing push notifications from servers  to clients once an initial client connection has been established. For our case of long running commands which emits progress as it executes, the server can continuously sending the progress using Server Sent Events API. [h3]Definition of a ManagedJob[/h3] Any command which has progress information in it ie annotated with [b]@Progress[/b] or which is run with [b]--detach[/b] (See section below) option is known as a [b]ManagedJob[/b]. Each job has a job id associated with it. You can query the status of a [b]ManagedJob[/b] using [b]list-jobs[/b] command. [h2]How it fits together [/h2] 1. When a managed job is executed in GlassFish the REST client will open an SSE connection with header Accept: text/event-stream. 2. The command gets executed on a dedicated thread pool which is provided by the JobManager. 3. Once the channel of communication is established all the progress feedback is sent as Server Sent Events and the channel is kept open to keep sending progress as it occurs. 4. The Response is closed when the command finishes execution. [img=600x400]http://weblogs.java.net/sites/default/files/sse.png[/img] The above figure shows the interaction between the Server and the command which is annotated with @Progress executed by the client. The progress is sent via SSE and finally the ActionReport is sent once the command finishes execution. [h2]Job Management commands[/h2] These are newer commands which are introduced [list]   [*]detach option to commands   [*]attach command   [*]list-jobs command   [*] configure-managed-jobs   [/list] [h3]detach option to commands [/h3] Any command can be run with [b]--detach[/b] option. This will give a job id associated with the command and the job is run in the background. You can then lookup the job using the [b]list-jobs[/b] command. (Similar to the jobs command in Unix) You can later attach to the job using the [b]attach[/b] command with the job id too and see the progress. [h3]attach command [/h3] The following image shows a sample command started by the client which emits progress status information. 1. Client 1 starts the sample command which has some progress information 2. The server executes the command and sends the progress to the client using ServerSentEvents. You can open another terminal for Client 2 and attach to the same job and see the same progress updates on both the clients. [img=500x300]http://weblogs.java.net/sites/default/files/image.png[/img] Fig 1. Multiple clients attaching to get progress via Server Sent Events. Bboth the terminals Client1 and Client2 are both getting the same set of progress related Server Sent Events at the same time. Even if one client kills using Ctrl C the other will still see the updates. [h3]list-jobs[/h3] The [b]list-jobs[/b] command can provide information regarding the jobs. It lists the job id, the name, the time the job was started, the state and the Exitcode. Here is a sample output of list-jobs command asadmin list-jobs NAME                         JOB ID   TIME                                STATE                EXIT CODE   USER  sample-command1   1            2013-02-05 14:11:24   COMPLETED   SUCCESS     admin You can even run list-jobs with a single job id
asadmin list-jobs 1
NAME                         JOB ID   TIME                                STATE                EXIT CODE   USER  
sample-command1   1            2013-02-05 14:11:24   COMPLETED   SUCCESS     admin 

Using curl to get the data of the list-jobs
This will get the information of all jobs 
curl  -vSs -H 'X-Requested-By foo' -X GET http://localhost:4848/management/jobs
This will get the information of job whose id is 1
curl  -vSs -H 'X-Requested-By foo' -X GET http://localhost:4848/management/jobs/id/1 
[h3]configure-manage-jobs command[/h3] The [b]configure-managed-jobs[/b] command is used to clean up these [b]ManagedJobs[/b]. By default the job retention period is 24 hours. But using this command you can specify how long you want to keep the jobs. [h3]How you can contribute[/h3] Download GlassFish 4.0 from https://glassfish.java.net/download.html and try the newer features. Java EE 7 tutorial is here http://docs.oracle.com/javaee/7/tutorial/doc/home.htm You can file bugs using this link https://java.net/jira/browse/GLASSFISH Provide feedback at users@glassfish.dev.java.net.
GlassFish  comes preconfigured with Apache Felix Gogo, which is an  implementation of OSGi RFC 147, and is a proposed standard shell for OSGi environments.  For Glassfish 4.0 there is no longer need to open  a separate port to access the shell. The OSGi shell commands are integrated with asadmin, so you can now access the OSGi shell commands via asadmin tool. There is a remote command called osgi which accepts subcommands which are fed to the OSGi shell and their result returned via asadmin. This integration allows you to secure the OSGi commands using GlassFish admin credentials as well. If you have turned on
Masoud Kalali and I will be presenting a BOF at Javaone 2012 Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together! This session focuses on how Java EE 7 provides extensive set of new and enhanced features to support standards like HTML5, WebSockets, and Server Sent Events among others. In this session we will show how these new features are designed and matched to work together for developing lightweight solutions matching end users high expectation from a web application

 We are pleased to announce the release of Glassfish 3.1.2 . 

These are the highlights of some of the main features in Glassfish 3.1.2

Main Features

  • Improved Administration Console with better startup time             and option to load in background after server startup. [blog]
  • Improved clustering with new DCOM Support for Windows (as             an alternative to SSH for remote management of GlassFish             instances) and Non-Multicast clustering.
  • Improved EclipseLink integration with EclipseLink MOXy             support and TopLink Grid support (Coherence as 2nd level             data cache)
  • WebSocket (RFC 6455) Support
  • Transaction recovery using database (in addition to the             existing file system support)
  • Improved Security (secure admin requires password, Oracle             GlassFish Server secure by default with new password             required be set during installation or on first use), and
        SSL Encrypted traffic between the Domain Administration             Server and remote instances
  • NetBeans 7.1.1 ships with GlassFish Server 3.1.2

As you can see the newly released Netbeans 7.1.1 ships with Glassfish 3.1.2.

We have added 3 new samples which will work out of the box using Netbeans 7.1.1 and Glassfish 3.1.2.

This blog talks about the new samples.

To download Netbeans 7.1.1 go to http://netbeans.org/downloads/index.html Choose the Javaee supported technology

Once Netbeans is installed you can try the samples by clicking File->New Project->Samples->JavaEE

 Netbeans projects

You will see 3 new samples which are introduced in Netbeans 7.1.1

1.Embedded Glassfish

This is a simple maven sample which shows the Embedded API in Glassfish 3.1.2 and demonstrates

        1. Start/stop GlassFish Server
        2. Deploy & Undeploy an application
        3. Scattered Archive
        4. Running asadmin commands from CommandRunner

You can right select the sample as shown above right click and Click Build. It will download the maven dependency  glassfish-embedded-all jar.

Under the Source Packages you can see the embedded.telephonedirectory.client and embedded.telephonedirectory.server packages
The embedded.telephonedirectory.server has few JPA entities defined   and a PersistenceManager CDI bean.
The embedded.telephonedirectory.client has all the code which shows how to use the embedded apis in Glassfish. You can see we define an http-listener,
?then the JDBC pool and resource required for the application is created, the application is deployed using org.glassfish.embeddable.Deployer API.
To access the application launch the URL in the bowser http://localhost:9590/td

 Once the user finishes accessing the application type quit in the Tasks panel, the application is undeployed and embedded glassfish is stopped.

2.EjbContainer sample in Glassfish

This sample demonstrates the use of Maven to test EJB's using the standard EjbContainer support in Glassfish 3.1.2.

Open the project in Netbeans and right click and click Build.
Under the Source Packages tab you will see the org.glassfish.embedded.tempconverter package and see a StatelessSession bean called TemperatureConverter
which does basic conversion from Farenheit to Celcius and vice versa.
Under the Test Packages tab you will see the TemperatureConverterTest.java which is a simple junit test which

1. Creates the EjbContainer
2. Gets the Context object and does a lookup for the TemperatureConverterBean
3. Invokes the methods on the TemperatureConverterBean

 3.Application scoped resources sample in Glassfish

This is a simple sample which shows Application scoped resources in Glassfish. You can right click and click on Run to run this project.

When you open the project you will see ApplicationScopedResources-app-client and ApplicationScopedResources-ejb modules.

The ApplicationScopedResources-ejb module defines a StatelessSessionBean HelloBean which takes in a DataSource
and does a lookup and returns the name of the  datasource or the default if it does not find any matching datasource.

The main file of interest is the glassfish-resources.xml which you can see under the Files tab which is next to the Projects tab.
You can see it the jdbc-resource java:app/app-scoped-resource in  java:app : namespace which is shared by all components, modules in an application
(eg: application-client, web component, ejb component in an application, .ear). The application client looks for the "java:app/app-scoped-resource and prints 
it since the application client is part of the ear  it can access it.

Please try these samples in Netbeans 7. 1.1.and give us your feedback. Also go ahead download and try Glassfish 3.1.2 and we look forward to hear from you!


















Filter Blog

By date: