Tuesday Mar 17, 2009

JRuby Fusion

I recently ported a medium-sized Java web application to Ruby on Rails. Overall it was a gratifying experience but I struggled with PDF generation, and specifically the limits of the Ruby PDF generator PDF::Writer and associated SimpleTable.

Actually PDF::Writer itself is fairly powerful but unfortunately SimpleTable lives up to its name by lacking many of the features found in other PDF generators.

My original Java app uses the awesome iText PDF generator which has extensive table support.

After fiddling with SimpleTable for a while, I gave up and wrote a simple bridge between my Rails app and my original Java PDF generation servlet. On the rails side I create a delimited string containing each record to be printed, and post that to the servlet with:

    http.post(path_to_servlet, delimited_string)

On the Java side I parse the InputStream to retrieve the values, and generate table cells using the iText APIs.

This is straightforward, but it bugs me having to maintain two codebases in two languages, and deploy two separate applications, one in an app server, to support PDF generation. It would be far preferable to access iText directly from Ruby.

Enter JRuby

So I installed JRuby on my S10 box, and entered these two commands (courtesy Charles Nutter):

  % gem install glassfish-gem-10.0-SNAPSHOT.gem
  % glassfish_rails myapp

And voila: my app is running inside Glassfish on JRuby. Wow - that was easy! I can get rid of my mongrels and manage everything from GlassFish. Even better, I can now call Java from within ruby:

setenv CLASSPATH itext.jar

require 'java'

include_class 'java.io.FileOutputStream'
include_class 'com.lowagie.text.Document'

document = Document.new(PageSize::A4.rotate(), 10, 10, 10, 10)
pdfFile = FileOutputStream.new("it_works.pdf")

writer = PdfWriter.getInstance(document, pdfFile)

table = PdfPTable.new(9)

This is the best of all worlds. Of course there are some downsides with this approach, such as inevitable impedance mismatches between Java and Ruby, code maintainability issues, etc. but this approach quickly and elegantly solved my original problem of not being able to access iText.

First impressions: JRuby Rocks.

Thursday Feb 26, 2009

Find Binds

JavaFX binds are cool. They significantly simplify the structure of an application by eliminating completely the need to use observer patterns to allow objects to receive notifications of application state changes.

I spent several days at Mobile World Congress demoing JavaFX to MIDP developers, and overall I'd say bind was the feature of the language most appreciated.

With all its advantages, it seems to me that code maintainability (not to mention performance) potentially suffers by the use of this construct. With multiple binds scattered throughout an application, it's likely that at some point an update to a bound variable will cause unexpected behavior, a situation not easy to trace.

I would love it if NetBeans had a "Find Binds" feature, similar to "Find Usages" which shows all variables affected by bindings to a selected variable or code block.

Without such a feature, debugging obscure issues related to bindings can be tedious.

I just submitted this as a NetBeans feature request.

Video Surveillance System Demo Script

The demo script for the Video Surveillance system we built for Mobile World Congress in Barcelona unfolds as follows.

Background: A centralized console shows six video feeds from cameras situated throughout a corporate campus. All feeds are active simultaneously, with each shown as a thumbnail. The system cycles through the feeds, expanding one at a time to highlight it.

Several security guards, each with a JavaFX handset, make their rounds throughout the campus. The handsets are GPS-enabled, and the app on the handset invokes the Java Location API (JSR 179) to determine its location, and broadcasts this back up to the desktop application over http (using javafx.io.http.HttpRequest), with the physical location of the phone encoded in the URL string.

Like the console, the handsets cycle through each video feed, and also display a map showing the location of each feed.

A map on the desktop shows the entire campus, with icons representing each guard wandering around the campus corresponding to the guard movements.

That's the backround. Now the action begins. An operater monitoring the main console observes a suspicious-looking truck pulling into the loading dock, as shown on one of the camera feeds. Three thugs jump out of the truck, grab crowbars and sledge hammers, and within ten seconds are able to break into the loading bay and make their way into the building, and start stealing servers and monitors and loading them into the truck.

Seeing all this, the operator sounds the alarm by clicking an alarm button on the console. Immediately each handset changes state and displays a bright red background screen, plays an audio message ("INTRUDER ALERT AT LOADING DOCK D"), while the video feed from the loading dock camera is simultaneously streamed to the phone.

The phone also shows a map of the area where the breakin occurs with a flashing red camera icon at the loading dock. This map can be zoomed with a tap of the stylus.

With the guards notified, the main console map shows all four guards converging at the loading dock area. The precise moment the first guard arrives, the video feeds (on both the console and the handset) show a security truck arriving, followed by the guard jumping out and making the arrest.

At this time the operator at the console cancels the alarm, whereby the phone plays another audio alert ("SITUATION UNDER CONTROL") and returns to its previous state of cycling through camera feeds.

That's the demo scenario in a nutshell. Due to the nature of the demo and some constraints imposed by the conference environment, some aspects of the demo were simulated. But overall it was a good proof of concept showing a sophisticated media-rich JavaFX application running on both the desktop and the handsets.

JavaFX Video Surveillance System

Our group is building a project for JavaOne 2009 which is based on JavaFX and will showcase many capabilities of the platform. In order to achieve maximum leverage of the code we're writing, my manager encouraged me to submit the same project as a demo proposal for the Mobile World Congress conference which was held in Barcelona last week.

The proposal was mostly accepted, but the marketing folks asked that we considerably change it so as to highlight the video streaming capabilities of JavaFX.

It turned out that modifying the original scenario to support video didn't make alot of sense. Instead we came up with a completely new scenario based on a video surveillance system.

The basic scenario is a corporate security force which has multiple cameras situated throughout an office complex. A centralized console displays the streams coming from each camera, and several security guards patrol the campus, each carrying a JavaFX-enabled handset.

We were able to implement a proof of concept of this demo in well under a month, with no prior experience with JavaFX.

In the next few postings I'll describe the demo in detail and discuss some of the issues we encountered while building it.

Overall I'm extremely pleased with the JavaFX platform, and I also was pleasantly surprised by the warm reception the demo received at the show.

Friday Nov 02, 2007

Vote for Java 6 on Leopard

Lack of Java 6 on my MacBook Pro is preventing me from coding on it. So here's my vote for Java 6 on Leopard:
  13949712720901ForOSX
I've been doing much of my development on a Solaris instance under Parallels, but it would be nice to test the apps on the host OS.

Once Leopard supports Java 6 I'll upgrade.

See Henry Story's blog for the meaning behind the above string, then cast your own vote.

Thursday Apr 05, 2007

Comparing Java 3D with jMonkeyEngine

I'm working on a JavaOne project that makes use of the jMonkeyEngine 3D scene graph API commonly referred to as jME.

So far I've found jME to be a pleasure to work with, and am particularly impressed by the founders and community who seem friendly, knowledgeable, and responsive.

But developing a project in jME naturally leads to the question: how does it compare with Java 3D?

Here's my take, based on a couple of months working with jME, and a few discussions with Java 3D folks here.

jME pros:

  • quick to get up to speed
  • great infrastructure for games
  • wonderful community
  • lots of industry support

Jadestone's Hockey Challenge completely written in jME

Java 3D pros:

  • Compatible with both OpenGL and Direct3D (whereas jME supports only OGL)
  • multi-screen support, great for immersive environments, etc. See the Java 3D-enabled CAVE project for an example.
  • much more sophisticated threading model (one thread per display, one thread per behavior)
  • runs on Solaris
  • supports and takes advantage of 64 bit architectures

University of Calgary's Java 3D CAVE Immersive Environment

Java 3D is the basis of some extremely interesting and exciting projects coming out of Sun including Project Wonderland and MPK20. It'll be interesting seeing how both technologies evolve.

Thursday Mar 29, 2007

Java Obfuscator

I needed to obfuscate some code for a project I'm working on. A quick search came up with yGUARD which is surprisingly well-suited for my purposes.

For one thing you can specify the granularity of obfuscation, right down to the method and field level. So for example you can tell it to obfuscate a single field in a single class (and all references to it, obviously), up to every field and method in every class in a jarfile, or anything in between.

Another nice feature is that it operates seamlessly with ant, and therefore, with NetBeans. Add a new target to build.xml, then invoke it with with the -post-jar target provided by NetBeans, and the generated jar is now obfuscated automatically at every build. Very slick.

yGuard's method of obfuscation is to rename methods and variables with obscure, sometimes unprintable, names. It also has a code shrinking option which according to their specs removes code entities that can not be reached from a set of given code entry points.

Two thumbs up.

Thursday Mar 22, 2007

Boeing 747 Supertanker

I recently visited the Hiller Aviation Museum in San Carlos and bumped into a pilot who used to fly for United but now has a new, and much more interesting, job flying 747s to extinguish forest fires.

I couldn't believe it. As a kid I spent two summers fighting fires for the Alberta Forest Service and was frequently awed when a DC3 would come hurling out of nowhere just a few dozen feet above the tops of the trees around me.

But that was a DC3. This guy was talking about 747s.

A 747 has some big advantages over a DC3. It has much longer range, and can travel to longer distances in shorter times, resulting in improved response times. And of course a 747 holds more fire retardant. Seven times as much in fact.

The pilot (Buddy) told me that holding tank is 24000 gallons, which can be filled in 30 minutes using a special pumper truck. But get this, they can dispense those 24000 gallons in just ten seconds. And they can do so flying 200 feet above the tree tops.

Just don't ask how many acres of forest go up in flames if one of these puppies fails to negotiate a turn.

Monday Mar 19, 2007

The Flying Ashtray

In preparation for my upcoming Java One Session I was reading over some speaker guidelines and came across two hints that reminded me of an embarrassing (and potentially dangerous) incident.

Many years ago I played in a country band, "White Lightning," that toured the small towns of northern Alberta. Many of these towns' main business was cattle ranching, so frequently the entire audience was comprised of beefy cattle ranchers and their cohorts.

One such night we played a song by KD Lang, a moderately popular singer hailing from Edmonton. Unfortunately, and unbeknownst to us, she was also an animal activist and had recently released a another song, Meat Stinks, in support of the animal rights movement. The song was clearly and rather graphically opposed to the cattle industry.

We were a few bars into the song when a heavy ceramic ashtray came whizzing through the air and slammed into the wall a couple of feet from the drummer's head. Turns out someone had taken exception to us playing a song by a performer who publicly denounced their entire livelihood.

Back to my preparation for the JavaOne session: the two hints I read were "know your audience" and "know your material." We were clearly in violation of both these rules.

Friday Mar 16, 2007

Ramona: world's first live virtual rock star

Speaking of virtual reality, and speaking of Ray Kurzweil, check out Ramona.

A couple of years ago Ray constructed a 3D virtual alter ego, in the form of a 25 year old female rock singer, who looks nothing like him but talks his talk and walks his walk, literally.

Frankly I found it a mildly unsettling to watch the superimposition of Ray (not, IMO, overly cute) with the virtually attractive Ramona.

But it just goes to show that on the Internet, it's really true that nobody knows you're a dog. (No offense Ray, I love your stuff!)

The Ultimate Computer

I'm a long-time fan of Ray Kurzweil. Several years ago I bought one of his keyboards, a PC88, which he built based on his pioneering work on audio synthesis. At the time it was by far the most realistic sounding electric keyboard on the market.

Since then I've followed his work in speech recognition, OCR, music synthesis, and lots more.

I'm now reading his book "The Singularity is Near" to which my reaction keeps oscillating between powerful optimism for the future of humanity, and "What is this guy smoking?"

He dedicates several chapters to an analysis of Moore's Law and the exponential increase of the capabilities of technology that has been going on for years. He then extrapolates to the future with some extremely off-the-wall ideas.

For example, he states that by 2080, for $1000, you will be able to get a 2 pound "ultimate portable computer" that would "be able to perform the equivalent of all human thought over the last ten thousand years (assumed at ten billion human brains for ten thousand years) in ten microseconds."

I'll definitely want to get one of these so I can run emacs on it.

Of course, it's easy to make far-flung predictions for the distant future when there's no chance of anyone we know being around then. But wait, he plans on being alive at that time.

Wow, that's amazing. Or should I say, "I want some of what he's smoking?"

Thursday Mar 15, 2007

Sun's Virtual Workspace

I saw a demo last week at the Game Developers Conference that inspired me so much I was pushed to finally get off my butt and leave the "non blogging heathen" ranks (as John Clingan likes to refer to us) and write about it.

The demo in question, MPK20, is Sun's Virtual Workspace, a project out of Sun Labs based on Project DarkStar and the Wonderland scene manager plugin for Project Looking Glass, which is ultimately built on top of Java 3D.

Even though I saw MPK20 at a conference dedicated to gaming, I see it potentially affecting the future of the Internet As We Know It, or more, the future of computer interaction.

As I was watching the demo, I kept having flashes of the future, envisioning how technology like this could impact education, entertainment, commerce, sex, sports, shopping, you name it.

One thing is clear: with technologies like MPK20 and Second Life looming, the days of the web browser are numbered.

About

john

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today