Monday, June 29, 2009

littleware on Google Code

I just setup my littleware code as a project on Google code: http://code.google.com/p/littleware/ .

What a great site! It was easy to setup the project, but here are a few tricks for interacting with the Mercurial repository.

  • To initialize the Google repository from an existing repository on your local machine:
    • hg clone googlerepo
    • hg bundle localrepo
    • cd googlerepo; hg unbundle localrepo.bundle
    Something like that.
  • Took me a while to realize that googlecode autogenerates a custom password for Mercurial push. You need to track down that custom password under the googlecode admin console to 'hg push' up to Google's repository.

Sunday, June 14, 2009

Guice, Read only POJO, and Builders

I often design java interfaces with methods that return POJOs with read-only properties like the following.


public interface Manager {
      public Info lookupInfo( String sKey );
}

public interface Info {
    public String getA();
    public int    getB();
}

I prefer to decouple Manager's implementation from Info's implementation via Guice injection like this:

public class SimpleManager implements Manager {
    ...
    @Inject
    public SimpleManager( Provider<Info> provideInfo ) { ...
}

The problem with injecting the Info provider is that provideInfo supplies read-only objects which SimpleManager cannot assign property values to. One fix to this problem is to introduce an Info builder interface, and inject that, and a nice way to implement the Builder is to nest the Builder interface within the Info interface, then nest the Info implementation within the Builder implementation. We wind up with something like this:

public interface Info {
    ...
    @ImplementedBy( SimpleInfoBuilder.class )
    public Interface Builder {
        public Builder putA( String val );
        public Builder putB( int val );
        public Info build();
    }
}

public class SimpleInfoBuilder implements Info.Builder {
    private static class SimpleInfo implements Info {
           ...
    }
    ...

    public Info build() { return new SimpleInfo( ... ); }
}


public class SimpleManager implements Manager {
    ...
    @Inject
    public SimpleManager( Provider<Info.Builder> provideInfo ) { ...
}


Tuesday, February 24, 2009

Design for Everything

The more code I write the complexity of what I want to do increases, and the number of design variables increase.  I find that I have to design for ...
  • testing - code to interfaces that lend themselves to unit testing
  • remote procedure call - remote APIs must be call by value
  • security - keep JAAS in mind for authentication and access control
  • user interaction - design APIs to provide hooks for user feedback, support user cancel requests, or implement the observable pattern to allow UI listeners for view changing events
  • monitoring - logging, JMX, timers
  • extensibility - OSGi implements a nice plugin architecture
  • transactions - ability to rollback multipart operations on failure after partial processing
  • cacheing - ability of client to cache data from server in a consistent way
  • injection and late binding - I like GUICE for dependency injection, but am lately struggling with marrying the GUICE's preference for data binding at application startup with a UI design that allows runtime definition of injectable parameters.

Saturday, January 10, 2009

Solaris X11 emulate 3 button mouse

Happy 2009!
I've almost got the OSGi+Guice based bootstrap of  my code running in a glassfish server - testing now to work through a few last issues.  I'm pretty happy with this setup - Guice injects dependencies, and OSGi manages module startup and shutdown.  We'll see how it works out over time.
The Glassfish J2EE server runs on an Open Solaris install which a VirtualBox virtual machine hosts on my Dell (Windows Vista) laptop.  Works great.  I've wanted to check out OpenSolaris for a while, and it's pretty slick, but  I'd be surprised if Solaris recovers the market it has lost to Linux.
Anyway - the Solaris X-server was not configured to emulate a 3 button mouse by default.  Fortunately, Google found the following easy 3-button emulation fix, so I can now happily cut and paste in the Solaris VM on my laptop.  The fix just adds an 'Emulate3Button' line to the mouse InputDevice block in /etc/X11/xorg.conf file:
Section "InputDevice"
        Identifier      "Mouse0"
    Driver      "vboxmouse"
    Option      "CorePointer"
    Option      "Device" "/dev/kdmouse"
        Option          "Protocol"              "auto"
        Option          "ZAxisMapping"          "4 5"
    Option      "Emulate3Buttons"   "true" 
EndSection

Wednesday, November 19, 2008

Building a Dev Box

Although I am the sole developer on most of the software projects I currently work on, I often haven in the back of my mind the steps that another developer would have to go through to contribute to a project. I think this is usually a good consideration as this line of thought forces me to at least try to establish a simple development and test environment, and to try to write clear and easy to work with code. Before a fellow developer even looks at a line of code for the littleware project he or she has to install a series of software packages on his machine to build up a base development environment. Here is a quick rundown of several of the packages I install on a box that I expect to develop on. This list is not comprehensive, but it has the big pieces.

Saturday, November 15, 2008

Guice and OSGi

I've been working on and off for the past couple years on a client-server data tracking framework I call "littleware", and over the last month I began revamping the dependency injection bootstrap code on the server side. I've already converted the client side to use Guice, and that has worked out great. A Guice trick that has worked very well for me on the client is to setup a Properties file that defines static user preferences .ini style, then have a Guice module pull Guice @Named constant values for injection.

On the server side I plan to try a two phase bootstrap process using both Guice and OSGi. The second OSGi phase will allow each bundle that contributes to the application to run through the OSGi startup/shutdown life cycle. Leveraging OSGi will also allow each module's code to take advantage of OSGi's service publish and discovery infrastructure. Here is what I have in mind.

  • First an application bootstrap method run by a configuration servlet will load a bootstrap.properties file to pull a list of Guice module classes and a list of OSGi BundleActivator classes.
  • Next the bootstrap method will allocate each Guice module via java reflection invocation of each module's no-argument constructor, and give the list of modules to Guice to create an injector.
  • Third the bootstrap method will use the Guice injector to allocate each OSGi bundle activator.
  • Finally, the bootstrap method will startup an embedded OSGi environment (probably Apache Felix), and seed the OSGi environment with the list of bundle activators.

This will be my first experience using OSGi, but I've read good things about it, and I know several prominent projects take advantage of it. I know OSGi has some support for dependency injection, but I've had greate experience with Guice, and Guice seems much better suited to that task. If all goes well, then I may extend the client to leverage OSGi in the same way. I'd like to extend the current client framework to embed several server-side technologies like javadb so that multiple clients running on the same machine can share services - especially cacheing.

Hopefully I'll be back in a month or so with a status update. I played around with maintaining a blog of XML files on my own server, but services like blogger are obviously a much simpler and better solution that I plan to take advantage of for now.

Friday, September 21, 2007

RSS test

Let's see how this shows up in RSS. Does this show up too ? -Reuben

Wednesday, August 15, 2007

Easy web site

Hello! Sites like this one (www.blogger.com) make it easy to post information to your own web site. If you just want a quick and easy place to post your contact information occasional news items, then give this a try. - Reuben

Saturday, September 09, 2006