Mangle-wheel and pinion

"36. Mangle-wheel and pinion -- so called from their application to mangles -- converts continous rotary motion of pinion into reciprocating rotary motion of wheel." Found in Five hundred and seven mechanical movements. I wonder what proportion of technical people in the past were expected to know this stuff cold compared with those today? Then again, they didn't know about mathematical programming either.

A Congressman was seated next to a little girl on the airplane...

Today's email contained this:

A Congressman was seated next to a little girl on the airplane. He turned to her and said, 'Let's talk. I've heard that flights go quicker if you strike up a conversation with a fellow passenger.'

The little girl, who had just opened her book, closed it slowly and said to the total stranger, 'What would you like to talk about?'

'Oh, I don't know,' said the congressman. 'How about global warming or universal health care?' and he smiles smugly.

'OK,' she said. 'Those could be interesting topics. But let me ask you a question first. A horse, a cow, and a deer all eat the same stuff - grass. Yet a deer excretes little pellets, while a cow turns out a flat patty, and a horse produces clumps of dried grass. Why do you suppose that is?'

The California legislator, visibly surprised by the little girl's intelligence, thinks about it for a minute and says, 'Hmmm, I have no idea.'

To which the little girl replies, 'Do you really feel qualified to discuss global warming or universal health care when you don't know shit?'

Witch and showing minimized windows

A friend tweeted some time ago about being able to open any Macintosh's application's minimized main window using a consistent command key. Since I started using Witch I have been able to do this. Since Cmd-Tab is grabbed by Apple, I assigned Cmd-1 to invoke Witch. I have configured Witch to place its cursor in the list of application windows on the current application's first window -- which has always been, in my experience, the main window. The result of this is that I type Cmd-Tab and then Cmd-1 I effectually am able to bring the application to the foreground and have it's main window presented foremost even if it is minimized.

Note that I could just use Witch with Cmd-Tab but I find that my mind-fingers connection for "move to another application" to be too tightly bound to Cmd-Tab. Anyone know of a patch that will allow me to bind Witch to Cmd-Tab for OS X 10.6?

Advocates need to simplify their awareness emails

I get too many emails from advocacy organizations attempting to keep me aware of them and their work. They need to find a way to to do this without sending me pretty but functionally unhelpful email or expecting me to watch a video to get more detail. Repower America is especially bad. An itemized list of short statements of accomplishments and/or actions with links is all I need.

Read Better Scientific and Technical Writing by Morris Bolsky for some sound advice.

A few days with Spring.

I have been learning Spring 2.5 for the last few days. My usual method of learning a new tool is to
  1. buy a book
  2. skim the book in chapter order
  3. study specific chapters as I need to know their contents
  4. disregard the chapter's examples because they suck either because they are too simple or inelegant
  5. unsuccessfully google for better examples
  6. successfully google for clues
  7. piece together a simple and elegant example
Now, I understand that beauty is in the eye of the beholder and so my examples probably suck to others. However, my track record is that they suck less.

Spring is funky. I had wanted to use EJB3 for this project but Spring won out. The reasons have little to do with technical merit. From a larger software engineering perspective EJB3 is just too unknown among the in-flight-magazine readers. Ok, that was a dig and childish. Sorry.

For Spring to work on this project I need for it to handle REST, JMS, and RMI simply and elegantly. To this end I have been working on JMS and RMI stuff mostly.

Spring's "JMS template" stuff is very old-school Java. A better approach is to use generics for clean coding and have the configuration done in XML. After some effort I can now code a JMS listener as simply as
public class HelloMessageListener extends MessageListener<String> {

@Override
public void receive( String message ) {
// handle string message
}
}

And, if your message is more complex the listener's complexity does not change. The generic MessageListener is where the hard stuff is and, to be honest, it is not very hard
public abstract class MessageListener<T> implements javax.jms.MessageListener {

private MessageConverter<T> messageConverter;

@Required
public void setMessageConverter( MessageConverter<T> messageConverter ) {
this.messageConverter = messageConverter;
}

@Override
public void onMessage( Message jmsMessage ) {
T message = messageConverter.fromJMS(jmsMessage);
receive( message );
}

abstract public void receive( T message );
}

MessageConverter also needs to be defined for all the machinery to work. The XML configuration is messy but mostly due to Spring's need for factories everywhere. In the end, the JMS listener is declared simply as
<bean class="org.springframework.jms.listener.SimpleMessageListenerContainer">
...
<property name="messageListener" ref="helloMessageListener" />
</bean>

...

<bean name="helloMessageConverter" class="example.HelloMessageConverter" />

<bean name="helloMessageListener" class="example.HelloMessageListener">
<property name="messageConverter" ref="helloMessageConverter" />
</bean>

For RMI Spring has good POJO support out of the box. What I could not find, however, was support for exporting a POJO as an RMI service that could be called by a non-Spring client. For example, the following client can be run using the standard JDK
import java.rmi.Naming;

public class HelloServiceCaller {

static public void main( String[] args ) throws Exception {
String helloServiceUrl = "rmi://localhost:1199/HelloService";
HelloRemoteService helloService = (HelloRemoteService) Naming.lookup(helloServiceUrl);
for ( String input : args ) {
String output = helloService.sayHello( input );
System.out.println( input + " -> " + output );
}
}
}

But if you try to use this against an RMI service exported via Spring's org.springframework.remoting.rmi.RmiServiceExporter it does not work. You get a java.lang.ClassCastException regards org.springframework.remoting.rmi.RmiInvocationWrapper_Stub. Yuck.

However, with a little effort I was able to create an exporter that could export a POJO as a remote service as long as the POJO had methods that correspond to a valid remote interface. For example,
public interface HelloRemoteService extends Remote {
public String sayHello( String name ) throws RemoteException;
}
...
public class HelloService {
public String sayHello( String name ) { return "Hello " + name; }
}

To remote HelloService I wrote RemoteProxyExporter which is a mixture of Spring, RMI, Proxying, and Reflection.

Now RemoteProxyExporter (and friends) was tricky to write but it took less than a day's effort. As did MessageListener (and its friends). Spring might have a means of achieving the same ends as my code but so far I have not found it. There are two reasons for this. The first is that Spring is highly abstract and data-driven and so this richness just requires lots more exposure than I have yet had. The second is that Spring is old, really old.

During Spring's life Java has had many changes of course as to how common problems are solved. For example, how to augment and/or configure a Java object. First we used reflection. When this didn't solve all our needs reflection was augmented with "information" classes (such as BeanInfo). When this was seen as too static for a dynamic world the information classes where replaced/augmented with external declarations encoded in XML. When XML was seem as cumbersome Java 5 added annotations. Spring uses all of this but not consistently. And so often times just understanding how to connect A with B is a nightmare. And googling does not help because the definitive answer for some questions was given in 2009 while others where given in 2004 when Spring 1.0 was released.

The upshot of all this effort is that I will be able to do what I need to do and do it in a way that works for all staff skill levels. And do it simply and elegantly.

I can't wait to dig into pooling!