Housewives, germs and multicasting

So today I learned that the current state of the art in reliable scalable peer-to-peer network communications owes a lot to neighbours gossiping over the garden fence and the study of disease epidemics. Cool. There’s an obvious similarity to the way computer virii spread as well. Each message ‘infects’ the receiving node, which then spreads it to surrounding nodes. Once a node is infected with a message it becomes ‘dead’ to that message, thus preventing endless retransmission. The gossip part comes in when you need to pick up on missed messages. Each node chats to its neighbours along the lines of ‘Have you heard the latest news about Mabel down the road? No? Let me tell you…’

Just goes to show that whatever wondrous things humans imagine themselves inventing, nature got there first.

ASM gains ground

CGLib now uses ASM instead of BCEL.

CGLib really is pretty cool. One of my colleagues, Chris, had a go at writing an enhancing classloader using CGLib, but ran into difficulties with final classes and classloader recursion. It ought to be possible, and that seems to me to be the most logical place to inject the enhanced bytecode. The rest of the application would then be completely unaware of the enhancement and could just instantiate classes in the usual way.

Thanks for reminding me

From the BileBlog:

The major flaw with dynamic mocks is that the return values are for all intents and purposes static. So for example, you can specify something like myMock.expectAndReturn(“getBlah”, “blah”); but cannot express something where the return value is not static. Why might you want to do that, you might wonder. Well, lets say you want to create a mock object for ServletContext, you’d want to be able to specify a Map that methods like getInitParameter and get/setAttribute work off of. Alas, this is impossible without much arm twisting and ugly hackery. You basically have to implement your own CallFactory which has all the extra magic in it. Maybe I’m missing something, but a less braindead solution to me would be to have the possibility of return values implementing some kind of interface, and in that special case, use a callback to determine what the actual return should be.

I have done exactly this, for the the purposes of erecting a fake servlet engine around some code that needed a more dynamic interaction with its environment than a straight mock object could provide. I’ve even been given permission to open source it, I just haven’t gotten around to it yet. I’ll see what I can do about getting it out there.