Month: August 2010

Persistent State Machine with Apache SCXML

The source code for this blog article can be downloaded here. I'm bored of reinventing the wheel. Everytime I need a state machine to ensure my states traverse only valid transitions, I find myself either not bothering, because I trust my coding (and write all the necessary unit tests of course), or writing very similar code over again. So I started wondering if there was a configurable state machine out there somewhere, and in no time at all Google gave me a link to SCXML from Apache. Apache SCXML is an implementation of a configurable state machine based on the SCXML working draft from W3C. I started by taking a look at what it does and how it works, always keeping in mind my requirements based on previous projects. The main question was how I could use a state machine in a persistent entity so that when an attempt is made to change the state, the state machine validated the attempt, ensuring only valid transitions are carried out. That meant two things: The state machine had to be able to have its current state set to any state. If I load an object with state out of the database, I need to be able to set that state in the state machine so that it checks any attempts to change state, based on this starting state. The state machine had to fit into a JPA entity class so that I could persist and load the state. Apache SCXML doesn't come…

Read more

Waffle Theorem

Eating a waffle, I just developed a new theorem.  First assume the waffle is square and made up of little squares.  If, like me, you eat around two edges, one square deep, so that the waffle stays square, you ALWAYS eat an odd number of squares.  Eg. 6x6, you eat 6 mini squares, follwed by 5, making 11 (odd number), so that the waffle itself stays square, now only 5x5.  My theorem hypothesises that this is true for all waffle sizes.  In fact it's called the "Waffle Theorem", and here is the mathematical proof: y = x^2 - (x-1)^2 -> y = x^2 - (x^2 - 2x + 1) -> y = 2x-1. QED, because 2 times anything ("2x") is always even, and subtracting one ("-1") always makes an even number odd.  Hence my hypothesis holds true, regardless of waffle size. Not bad for a Sunday night, all I wanted to do was eat the damn waffle...  I have to say though, it's this kind of thing that I love about maths.   ----------------- (c) 2010 Ant Kutschera

Read more