Pages

Tuesday, May 31, 2011

While I was creating my daemon examples for my previous blog entry, I created a plist file for executing launchd based applications. The convention is to name the plist file to match the name of the main application. In this example, it is com.bluelotussoftware.examples.Daemon. Place the file int the ~/Library/LaunchAgents directory.
Here is the file: com.bluelotussoftware.examples.Daemon

In a previous post, I mentioned how to add a shutdown hook to your application. This is great for the case where you need to do some cleanup prior to exiting. The example below shows how to convert your class to work like a daemon on UNIX, or a service on Windows. I will not go into details on how to create a UNIX, or Windows service. I will provide a StartupItem example for Mac OS X, or a modern inetd plist for launchd.

In the example classes below, I create a value holder object, a Callable<ValueHolder>, a Future<ValueHolder>, an ExecutorService which uses a SingleThreadExecutor. The concurrency libraries are from java.util.concurrent which is based on the original work done by Doug Lea, et. al. These classes make doing Thread based programming much simpler.

Java has a built in logging mechanism. This mechanism was adding to provide logging functionality to the base Java libraries. This removes external dependencies from your project, and allows you to use logging within the base framework.

Log4J has an incredible amount functionality, but requires that you add the framework to your project and its dependencies. There is also configuration required up front to use the logging.

The default logging mechanism is very easy to use. We simply create a Logger instance from the static class. Using it is as simple as calling Logger.getAnonymousLogger();. This allows you to create an anonymous logger which is a console logger. There is no default mechanism for logging to the file system. This accomplished by using a FileHandler.

A simple sample implementation is located below. I have please note the comments. The NetBeans project is located here: ExampleLogger.zip

Saturday, May 28, 2011

There was a post on the nbj2ee forum about binding a Woodstock Calendar to a backing bean. This is a simple example which demonstrates how to do it. The project was done in NetBean 6.7.1 and should work on NetBeans 6.5, 6.7, and 6.8 with the Visual JSF plugins installed.

Friday, May 27, 2011

I was working with an application that needed to be run as a daemon. When the application is shutdown, we needed to do it in a clean manner, and release resources. So the question becomes how is it done.

Fortunately, the Runtime class provides mechanism for adding a shutdown hook. The shutdown hook code below was added to the constructor. The shutdown method is invoked when the application is shutdown, for example CTRL+C.

I was working on an application at the office which involved mixing RichFaces 3.3 along with Apache MyFaces Tomahawk. Although some JSF frameworks claim interoperability, it is best to test them out to confirm that they will work in your specific project.

In the example application attached, I have created a facelets based application which uses Tomahawk components combined with RichFaces A4J to provide AJAX support.

It is a simple demonstration using AJAX to answer a comical question of which came first, the chicken, or the egg. Here is the example code: a4j-example.zip

Monday, May 23, 2011

We were giving interviews to some prospective developers for our team at work. One of the questions/examples we asked for was to create a multi-threaded application which has a producer thread and a consumer thread which passes messages between them.

After a couple of really bad attempts by prospects, I decided to give it a try. I have not done a lot of multi-thread applications (standalone) since most of my work has to do with applications in containers. I wondered if I could do it. Well my results are in the included application. It is just one way of doing it, but I thought I would post the cleaned-up version.

Tuesday, May 10, 2011

Why does it need to be so difficult to find the right combinations of voodoo to make enterprise applications work? I don't really want an answer. It is just a rhetorical question.

Cay Horstmann has a really good blog entry on JSF 2.0 and Tomcat. It is from a couple of years ago though.

I thought that I would add a little more information to well of knowledge. I have JSF 2.1.1-b04 running on Tomcat 6.0.32 with the addition of new EL (Expression Language) libraries and a context parameter to the web.xml

Monday, May 02, 2011

The JCP is holding elections for the open Executive Committee seats. This includes ratified seats, and openly elected seats. If you are a JCP member, or would like to vote (you must join JCP to vote), please do so. It is so important for the community to make sure that it is adequately represented. In order for the JCP to function, we need dedicated individuals who can rise above the current tumult, and deliver a positive message. We need focus to be on the Java Community Process, and not on political infighting.

As a JCP member, I have cast my ballot. Have you?

Oracle's nominations for the two open ratified seats on the SE/EE Executive Committee are:

The nominees for the open elected seats on the Executive Committee are:

Alex Terrazas - ME

Central Ohio Java Users Group - SE/EE

George Gastaldi - SE/EE

Siddique Hameed - SE/EE

Liferay, Inc. - SE/EE

London Java Community - SE/EE

I would like to encourage all voting members to ratify Bruno Souza (Representing SouJava). Bruno has been the face of the Java community for many years. He is internationally recognized, and truly represents the heart of the Java community.

The other elected seats include two Java Users Groups: Central Ohio Users Group and London Java Community. I would encourage all voting members to vote for the Java User Groups (JUG) community membership. These groups represent the diversity of the JUG community, and have community interests rather than corporate interests at their heart.

Dan Sline represents the Central Ohio Users Group and I would encourage JCP members to consider him. Otherwise, please consider voting for the London Java Community. It is vitally important to support the communities that are here to serve you.