By sirajg on May 27, 2010
If you have a specific interesting project around a new use case for embedded API, I might be able to spend some time to help you with your POC. Please drop me a line at firstname.lastname@example.org
One of the ways the embedded feature could be used is through maven. A maven plugin exists specifically for embedded glassfish. It allows a simple way to use the various embedded features.
Following are the maven goals supported by the plugin :
embedded-glasfish:run - starts the embedded server if it is not already running and deploys the specfied application. The goal keeps the server running, so the user can make changes in the application, reploy and test iteratively.
embedded-glassfish:start - starts the embedded server with the specified parameters
embedded-glassfish:deploy - deploys the specified application
embedded-glassfish:undeploy - undeploys the application identified by the "name" parameter. If no name is specifed all applications are undeployed.
embedded-glassfish:stop - stops the embedded server
embedded-glassfish:admin - executes the specified admin command on the embedded server. For example, you could create a jdbc resource.
A sample pom.xml snippet that would execute the run goal :
Here I will talk a bit about some of the basic embedded APIs that you can use.
The org.glassfish.api.embedded.Server object lets you perform lifecycle operations on the embedded server. It can be configured using the corresponding Builder object. For example :
// get the server builder
Server.Builder builder = new Server.Builder("test");
If you have a a preconfigured domain.xml that you want to use, you can do something like this :
// get the builder for EmbeddedFileSystem
EmbeddedFileSystem.Builder efsb = new EmbeddedFileSystem.Builder();
// specify the domain.xml location
EmbeddedFileSystem efs = efsb.build();
You could also specify the install root of the server and the instance(or domain) root to the EmbeddedFileSystem.Builder. For example, you can specify the installRoot using
Then create the server object
Server server = builder.build();
You don't have to specify the EmbeddedFileSystem - if you don't specify it a temporary file system would be created automatically and used.
You can then specify the containers that you want to use. For example for web container,
ContainerBuilder b = server.getConfig(ContainerBuilder.Type.web);
You can also specify the port that you want to use. For example,
The next interesting thing to do would be to deploy applications to it. For example, if you are deploying a packaged web app, hello.war, you can do this :
EmbeddedDeployer deployer = server.getDeployer();
DeployCommandParameters cmdParams = new DeployCommandParameters();
cmdParams.name = "appname";
cmdParams.contextRoot = "hello";
Now your application is running on the embedded server.
You can undeploy like this :
To stop the server,
The Log Entry Alert sends an email alert whenever there is an entry in the application server's log file for user-specified logger(s) at user specified level. The logger could be one of the predefined application server logger or it could be any logger that your application uses. So this feature can be particularly useful when user applications want to send out email to users or admninistrators, in certain conditions.
For example, consider the case when someone tries to login to your application and the authentication fails for a certain number of times. You may want to be alerted when this happens. Your application could log this in the application server's log file at the WARNING level in a logger of your choice, say com.xyz.mylogger. You can configure the Performance Advisor to send out an email alert when there is a log entry at WARNING level in the logger com.xyz.mylogger. And that's it!
Once you have the Performance advisor setup and running, go to the admin console and click on Management Rules->LogEntry Alert. This is the Log Entry Alert configuration screen that you will see :
In the above screen you specify the log level and the logger name for which you want to be alerted. You could specify multiple loggers, separating them by commas. For example, if you want to be alerted when a WARNING level entry takes place for loggers com.xyz.logger1 and com.xyz.logger2, you specify "com.xyz.logger1,com.xys.logger2" in the logger names field. If you want to be alerted for all loggers just enter "\*".
Besides that, you need to specify the email address of the recipient and other email settings. You can either use the JavaMail Resource or specify other email values to get the email going. At the bottom of the screen, you can specify the targets for which you want to set up this alert.
The GlassFish application server allows users to configure the logger settings in such a way that the server would automatically rotate log files, when certain user-configurable conditions are met. This typically happens when the log file exceeds a certain size. Over a period of time, you could end up with a number of rotated log files. The Log Rotation Manager feature of the Performance Advisor lets you manage the rotated log files.
To set up the Log Rotation Manager, click on the Performance Advisor->Management Rules->Log Rotation Manager node on the admin console. This is how the screen to set up the Log Rotation Manager looks like :
In the above screen you can specify whether you want to move the rotated log files to a different directory(typically, for archiving) or delete the files. The Rotation Policy can be one of the three options : Number Of Files, Size or Time. I'll explain these 3 options below.
Number Of Files : When you select this option, the Log Rotation Manager will periodically check the log directory and if the number of log files exceeds the user configured number of files, the log files are either delete or moved to a different directory. So for example, if you chose the "NumberOfFiles" rotation policy option and set the NumberOfFiles to 3, the server will move or delete rotated files, when their number exceeds 3, so there are no more than 3 rotated log files in the log directory.
Size : When you select this option, the Log Rotation Manager will periodically check the log directory and if the total size of log files exceeds the user configured size, the log files are either delete or moved to a different directory. So for example, if you chose the "Size" rotation policy option and set the Size limit to 100 MB, the server will move or delete rotated files, when their total size exceeds 100MB, so the total size of rotated log files does not exceed 100 MB.
Time : When you select this option, the Log Rotation Manager will periodically check the log directory and if there are any files older than the specified time, they are moved or deleted.
The Log Rotation Manager can be setup on any instance or cluster. From the admingui, all you need to do is select the list of targets for which you want set this rule up and the rest will be taken care of by the Performance Advisor.
As the name suggests, the Performance Advisor is designed to help users improve the performance of the application server. It does so in various ways :
With this brief introduction, I will talk about how to install and set up the Performance Advisor.
The Performance Advisor is available as a patch from SunSolve, look for patch id 140751. After downloading the patch do these steps :
The "Performance Advisor" node will appear in the tree in the left frame of the console. This is how it would look like :
The Performance Advisor node consists of two parts -
So what exactly is the Application Platform SDK? Well, there are a few similar sounding SDKs, and it gets all confusing. So I have summarized what these different bundles include :
JavaEE5 SDK : Sun Java Application Server(aka Glassfish) + API doc + tutorial + Blueprints + Samples (+ Optionally, Java SE)
Java Application Platform SDK : JavaEE5 SDK + PortletContainer + Open ESB + Access Manager
The Tools Bundle includes the NetBeans IDE and the Portal Pack as well. This all is made clearer in the new downloads page.
Back the Application Platform SDK - the latest update includes updated versions of Sun Java Application Server, Java SE, Access Manager, Open ESB and the Portlet Container.
A little more detail on all the different components of the SDK :
Java SE 6 (JDK) Update 4 : includes the Java Runtime Environment (JRE) and command-line development tools for producing applets and applications.
Open ESB V2 : Java Business Integration (JBI)-based platform for delivering composite applications on a service-oriented architecture.
Portlet Container 1.0.2 : implements the Java Portlet Specification (JSR 168), a standard for developing portal components, and provides a portlet driver, a lightweight portlet rendering environment.
Java EE 5 Samples : demonstrate the technologies and features specific to Java EE 5, including annotations, Enterprise JavaBeans 3.0, persistence, security, web services and more.
Java BluePrints define the application programming model for end-to-end solutions using the Java EE platform.
Tutorial : The FirstCup tutorial is an Introduction to the Java EE Platform to help you understand Java EE basics and then build and deploy multitiered Java EE applications.
API documentation(Javadocs) details all the classes and packages in the Java EE 5 SDK.
Also included in the tools bundle is the NetBeans IDE , an open-source Integrated Development Environment for building desktop, enterprise, web, and mobile applications in Java, C/C++, and even Ruby.So go ahead with the free download. You can always share your comments or see what others think, at the SDK forum
After installing Glassfish, I downloaded blojsom which is packaged as a web app. Then I copied blojsom.war to GlassFish's autodeploy directory, <glassfish-install-dir>/domains/domain1/autodeploy. I then pointed the browser to http://localhost:8080/blojsom/blog/default and was able to access the blojsom application. To log into blojsom, I went to http://localhost:8080/blojsom/blog/default/?flavor=admin (username "default", password "123default456"). Then I added some categories and blog entries.
I also added some users by modifying
file and gave permissions to these users by modifying
file. I did all this by following instructions in blojsom configuration guide