Ghost in the JVM

An adventure in the JVM land

DIY Java App Server on OpenShift: So Far So Good

I have been playing with RedHat OpenShift platform for several days. So far the experience has been very good. Several nuances encountered but I was able to get my java server application running in less than an hour. My application is not using any preconfigured OpenShift’s cartridge or application server as I know. My application is a simple Gomoku game with WebSocket support. I use DropWizard as the light-weight server to bootstrap an embedded version of Jetty. Most of the issues I encounter were just network interface permission, build, deploy and starting the app.

Java Proxy Chaining - Aspect on the Cheap

How many of you have written a caching solution for one of your expensive method calls? Or how about retry logic for your service calls? Living in such a connected world no single application is its own island. For every applications I have worked for, there always external dependencies, either other service APIs or databases that we need to rely upon. And we can’t make the assumption that they are reliable 100% either.

Some service calls are expensive and the underlying data don’t change so often. We tend to cache the results. A naive approach would be to find such methods and refactor them so that cache can be used before the call to the services are made. The better way is to use AOP where you intercept those calls with ‘aspects’. The in those aspects you can make the decision to whether get the results from the cache or to make the expensive service calls. Another common scenario is retry when you encounter exceptions in your service calls: transient network issues (latency, timed out, spillover in load balancer…) or database hiccups. Normally, you should at least retry the calls for several times before giving up. Like noted previously, a naive approach would be to go every methods and apply the retry logic. Or you could use AOP.

In this post, I’m going to talk about how to use aspect oriented way to ease the refactoring effort. I will not talk about the full blown bytecode level AOP solution which uses AspectJ with bytecode weaving. Instead, I will talk about a lighter weight of aspect programming using the Java’s dynamic proxy and its reflection mechanism. I think it’s pretty similar to the way Spring AOP works. The only difference is that my code will assume every method calls implement interfaces. Thus, it will not have to use cglib to generate the proxies. Also, I think programming to interface is a much cleaner and prefer way for your service calls Data access objects (DAO).

At the end you could decorate your method with annotations/aspects like this:

Example
1
2
3
4
5
6
7
@Timeit
@Retry(times=3)
@Cache(timeToLiveInSeconds=3600)
public void goGetMyData(String someParam, int anotherOne)
{
    // do something
}

Building Database Full Text Index With Lucene

I have this client table in Oracle having more than 3 million rows. One of the column is the client name in which our users want to have full text search support. Originally, Oracle context search feature was choosen by a group of consultants. May be we were maintaining the domain index correctly but its performance sucks.

Asynchronous Calls in C#

Last December I started leading a team develop a Outlook addin for the firm. I admit that I am no C# developer. The last time I used C# was when I attended college years ago. But the group of consultants were let go and we have to jump in and take ownership of the project.

I also have to admit that C# has a lot of language features that I really wish Java does too. Among them is the concept of delegate and function pointer used for asynchronous method calls. I know I can get the same thing with Groovy or Scala.

Concurrent AMF Request for BlazeDS

Requirement: AMF data service comes with BlazeDS servlet is asynchronous. One of the services provided is RemoteObject. RemoteObject calls are faster than WebServices and HTTPServices because the information is exchanged in binary. But RemoteObject itself has a not-too-well-known behavior. While it is true that RemoteObject services are asynchronous, they are not parallel.

Query Templating for Hibernate Native Query

I recently encounter this kind of problematic requirement: making a native SQL in hibernate dynamic. The query should be written as a template. And based on the user selection, a concrete SQl statement is derived. It’s pointless to have this conversation if we use HQL’s query criteria of course. But with native SQL code, I admit there is no easy/legitimate way around but hack.

RIA Portlet Made Possible With Flex Remoting

Even though portlet development standard has been in existence for a while its popularity and advanced functionality hasn’t got a lot of changes comparing to traditional web application development. Up until now, the only way to develop a portlet application is to use the dated (but obviously dominant) JSP technology. I know there have have been several attempts to bring advanced view engines into JSR-168/JSP-286 such as JSF prolet bridge or even the Wicket Portlet bridge the lanscape overall is pretty naive and dificult to comprehense. I can refer to this artical when it comes to the reasons why portlet has not become dominant as if it should be by now.

DBUnit FlatXmlDataSet Export Using Groovy Builder

Recently I have been using [DBUnit][1] to run my DAOs unit test with Spring and HSQL in memory database. One of the biggest challenge in testing the DAO layer is generating data to test with. Of course you could export data in your development database in style of insert statement files and import them into the test database before executing the test. But I think doing so still requires a lot of manual work for a busy developer. One nice thing about DbUnit is that you can export your test data into a single XML file and while setting up the unit test, you tell DbUnit to execute the import based on the XML data file.

State of WSRP Development: OpenPortal Verus Apache Wsrp4j

with wsrp4j project has become more and more dormant, I am seeking for another wsrp framework. To the best of my knowledge, beside the commercial framework out there from BEA Portal and IBM Websphere, Apache’s wsrp4j used to be the only open source solution until Sun steps in and sponsors java.net’s OpenPortal. My intention is to only replace the wsrp producer, but it is not a trivial task to just simply swap one producer and use it with the existing portlet container implementation. So go with OpenPortal container and its wsrp I am right now.

Autonomous Game Agent

I am always interested in game AI programming, specially autonomous game agents which move around and act on their own will but based on a set of pre-defined rules of course. After reading the first chapter of Programming Game AI by Example by Matt Buckland, I can understand the magic behind those intelligent behaviors. I am very impressed to know how simple it is to create those behaviors. But it’s definitely not simple if one is not familiar with trigonometry and geometric algebra.

The code presented in this book is all C++. And I have a hard time to make those code built in Visual C++ 2008. It is guaranteed to work with Visual C++ 2005 only! So I rolled up my sleeves and wrote my own code in Java. And I think this is the best way to test how much I understand the book.