Blogs

Java Dynamic Proxies

20 Jan 2012
Posted by cgp

Dynamic proxies are one of those topics along with Reflection (to a lesser extent) that seem like magic in Java. They exist outside of the safe, procedural oriented nature of the language and add useful complexity and color to an otherwise dull language.

What are Dynamic Proxies exactly? Dynamic Proxies allow you to run custom code before, after, (or before and after) other pieces of code. For example:

class Blah {
  public void myMethod() { System.out.println("I ran!"); }
}

Say I wanted the above method to run before every call to Math.cos(). So, I would extend a new class from the Proxy class and tell it to intercept calls to Math.cos(). The I could tell it that instead of calling Math.cos() call my code instead. In my Proxy class, I would have the option of calling the original function or not.

Buzzword Bingo

Essentially, we have created a "logger" for Math.cos. Logging is frequently referred to as a "cross cutting concern". I point this out now to perhaps trigger recognition that one of the chief reasons to use Dynamic Proxies is to insert code around methods in an independent fashion without affecting the original code. Dynamic Proxies are basically what AOP frameworks like SpringAOP and Guice use under the hood to provide their functionality. (psst!

Typical use cases for Dynamic Proxies:

Rules and Limitations, more to follow

There are rules and limitations to doing the above, but for today, we'll leave it at that.

Posted by cgp

I would like to document my experience installing and using GWT. Very quick background: I used GWT way back in 2007. I even reported a bug that I didn't follow up on Sad.

I'm using Eclipse 3.6. I first tried using the update site but it timed out on the spectacular number of .jar files that it tried to pull down. (after a solid two hours of downloading) Typical of Eclipse and java, seemingly uncomplicated simple things (downloading a set of files) is difficult and error prone.

I recommend using the "download method"for installation which comes in at a hefty 160mb zip file. (but the single file downloads in a browser in less than a couple minutes for those of you with decent connections)

Installation from the zip files seems like a breeze, but the designer fails to show. I'm able to do some things like kick off the "Google Development Mode" server. For a Eclipse noob like me, it's not clear why the designer fails to show. The FAQ provides a hint:

The most important piece missing from some Eclipse distributions is the Eclipse PDE (Plug-in Development Environment). You can correct this problem by launching Eclipse and selecting Help > Software Updates. Select The Eclipse Project updates from the list of sites and select the "Eclipse Plug-in Development Environment" to install.

So, why then isn't it one of the checked requirements? I found a description of how to install PDE but don't have any more time to check this out. (much time wasted in the original two attempts to install from the Eclipse Update site)

TIL launch4j

24 Jun 2011
Posted by cgp

I always wondered what people use to create windows executables for Java apps. Launch4j is a pretty good option. It's free for commercial use, and is open source itself. The interface is a little clunky and takes some getting used to, but it does the job and has plenty of options:

  1. Maven AND Ant integration
  2. Splash screens
  3. Set JVM options via a config file

For me I needed to identify the process name. I'm surprised I hadn't found this sooner.

Posted by cgp

Tasklist and Taskkill are built into Windows XP and Windows 7. I've used PS Tools for a number of years and this is the first I had heard of the built in tool. They do what you might expect a tool named as such do which is manage tasks via the command line.

For my purposes, one thing that the built in TaskKill did better than pskill -- kill children processes. For some reason, pskill wasn't killing children processes (even with -t specified) spawned by launch 4j so this is illuminating. Kudos to MS for putting this built in. Now if we can just get robocopy and powershell, we'll be all set.

Posted by cgp

Google voice disallows dialing into conferences and meetings? But there is a work around for Android. This definitely breaks the of least astonishment.

Google impresses me less and less.

Pocket Wars and Cores

09 Mar 2011
Posted by cgp

In Pocket Wars and Cores, Douglas Eadline makes a curious observation. The x86 CPU no longer dominates the world of computing. For the reasons mentioned in the article, this is a good thing.

Desktops haven't been the most influential disruptive platform for probably a solid 4-5 years, and articles are circulating that we have reached the post-pc era.

What does this mean for GPUs? Nvidia and others certainly make compelling computational devices. How will they fit into this new world of "processor instruction set" agnostic languages?

Coding Tapestry Forms

08 Mar 2011
Posted by cgp
I'm in the process of figuring out how tapestry forms work. So others may not trip where I have gone, I was getting the following error message:
Failure reading parameter 'translate' of component MyComponent:componentfield: java.lang.NullPointerException
Apparently... the following was wrong:
    <t:form >
      <t:input type="textField" t:id="componentfield" t:value="${componentfield}" />
      <input t:type="submit" value="${message:continue}" />
    </t:form>
This should be replaced with:
    <t:form >
      <t:input type="textField" t:id="componentfield" t:value="componentfield" />
      <input t:type="submit" value="${message:continue}" />
    </t:form>
The t:value attribute is expecting a property reference, not a value, which is what the first example is. Granted, the error message does very little to point in the right direction, but hey, maybe if you're getting this error, you'll run upon this page and be ok.