Screaming Coder


July 23, 2009

Scheduling Portable Extension for Weld / Seam 3

Filed under: frameworks, general, it, open source, seam, software development — Pete @ 3:24 pm

Introducing Weld  Scheduling – the best way to run scheduled events in JBoss Weld, Seam 3 and possibly any JSR-299 implementation. It makes use of CDI’s typesafe event model for tying business logic to schedules. That is, you define your schedules using the provided qualifiers, which you apply to observer methods containing the business logic that you wish to be run at those times. In other words:

    public void onSchedule(@Observes @Scheduled("20 */2 * ? * *") Event e) {
        // do something every 2 minutes, at 20 seconds past the minute.
    }

The CDI container will fire the @Scheduled(“20 */2 * ? * *”) Event at 20 seconds past every second minute, causing the onSchedule method to be executed each time. When CDI starts up with this module on the classpath, all observers of the Event class are detected by the module using standard CDI APIs. The module then inspects each associated @Scheduled binding annotation and sets up a schedule to fire an Event with that binding at the schedule found. Currently Quartz is used as the underlying scheduler.

One obvious shortcoming of this is that we’ve managed to hard-code scheduling information in our Java code. The answer to this is to define the schedule as a property in the scheduler.properties file at the root of your classpath, for example:

# This schedule is named "test.one" and runs every 2 minutes
test.one=20 */2 * ? * *
# This schedule is named "after.hours" and runs in the wee hours every day
after.hours=0 0 2 ? * *

You can then observe that schedule like this:

    public void onNamedSchedule(@Observes @Scheduled("test.one") Event event) {
        // the schedule is defined in scheduler.properties
    }

This is getting better, but that “test.one” String is still setting off some refactoring alarm bells. No worries, we can deal with this pretty easily using meta-annotations. We just create a custom qualifier like so:

@Scheduled("after.hours")
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE })
public @interface AfterHours {}

And now we can observe the event in a typesafe manner, in as many places as we want throughout our codebase with all the benefits of code-completion and none of the refactoring headaches:

    public void onTypesafeSchedule(@Observes @AfterHours Event e) {
        // do something after hours
    }

There are also some built-in convenience events for regular schedules:

    public void everySecond(@Observes @Every Second second) {
        // this gets executed every second
    }

    public void everyMinute(@Observes @Every Minute minute) {
        // this gets executed every minute
    }

    public void everyHour(@Observes @Every Hour hour) {
        // this gets executed every hour
    }

Note though that none of these built-in events will be scheduled, let alone fired, unless the module finds an observer for them on startup.

This project has been submitted to the Seam 3 sandbox (find it in seam/sandbox/modules). An early release of the Weld Scheduling module and Memory Grapher example app can be downloaded from here: WeldScheduling.tgz. They’re both built with Maven 2.0.10+. To run the example app, ‘mvn clean install‘ both projects (’scheduling’ first, then ‘MemoryGrapher’) and then run ‘mvn -Drun install’ from inside MemoryGrapher. It uses the Weld SE extension to run it without an app server (it’s a Swing app).

MNA542C29VE6

March 9, 2008

I Know Shoes

Filed under: Ruby, general, it, open source, software development — Pete @ 8:18 pm

Finally! My copy of Nobody Knows Shoes arrived in the mail this week. As an adoring fan of Why’s Poignant Guide I had perhaps unfairly high expectations of NKS. As can be seen in the downloadable PDF version it’s not as long nor as entertaining as the Guide, seems targeted at a slightly younger crowd and is decidedly less poignant. Unlike the Guide, the comic strips in NKS make no sense whatsoever and have abs(zero) relevance to the actual subject matter. There’s not even any mention of Chunky Bacon. But this is not to say that NKS is somehow inferior compared to WPG, more that I really had no business comparing the two in the first place. After all, Shoes is just a tiny toolkit by it’s own admission, designed with new programmers in mind. For those with a passing interest I recommend simply downloading the on-line PDF version (it is printed at cost anyway so you’ll just be saving _why the effort). But I would recommend it to any teacher-types with a class full of wanna-be programmers. Just hand them each a copy and let _why’s deranged cosmo-babble do the rest.

June 10, 2007

Brick Lane

Filed under: Published, general — Pete @ 8:39 pm

Went to all the various markets in and around Brick lane yesterday. We started out around Wentworth Street which was crowded but otherwise a little underwhelming. We did buy some stuff that we needed – some sunnies for me and a double adapter – but everything else was a just a bit ordinary. Maybe if you put a lot of time into it you could find some half decent clothes buried in there somewhere, but there are easier ways.

As we made our way through Spittlefields towards Brick Lane things began to pick up. Just outside these markets we came across a furniture shop with probably the coolest furniture I’ve ever seen (Elemental on Brushfield Street). There was a low, iron coffee table with train wheels! And this massive office desk with iron draws which when you opened and closed them made a sound like a robot farting. In the actual markets were good clothes, food and artwork, and even bits of old circuit board made into cufflinks, lamps, clocks and coasters! Made me wish I hadn’t thrown away all my Pentium IIs. There was heaps of other stuff we didn’t get time to see, including the Museum of Mechanics or something, which looked interesting. We’ll have to pick it up next time.

We then met up again with our old friend who’s living in France and the two very nice people she’s staying with in London. We had some spectacular curries (my first vindaloo!) then took a strole down actual Brick Lane. This is more your strokes-of-retro-genius hidden amongst the neatly-stacked-piles-of-junk market. For instance there was an old Atari console with some cartridges (space-invaders, pong, pacman, all the classics). I don’t know if it was a 2600, 2800 or what but it was woodgrain (!!) with big toggle switches. I could have had it all for £30 but I don’t have the time nor the space to take proper care of it (playing with it every day etc).

April 17, 2007

London Update

Filed under: Published, general — Pete @ 12:48 pm

Welcome to my first entry in a long time. Everything’s been pretty hectic in the last few months. I guess I’ve got some gaps to fill in. We’re settled down now into a little flat. I’ve got a job that I’m pretty happy with. But lets start with the best bits first.

Our Contiki Tour

We left London not sure exactly what to expect on a bus full of randoms. As we crossed over the Thames we got our first real postcard view of London with a handful of world-class landmarks plus sunrise and fog. Pretty soon though the fog got so thick we could hardly make out the trees by the side of the road and everything else was just white. We caught a ferry from Dover, where we saw those famous white cliffs, to France (Calais I think). For the time being we were just passing through, bound for Amsterdam.

We arrived there at nightfall, just in time to take a cruise down the canals. This gave us a great view of all the beautiful architecture, complete with 4 storey houses literally leaning on each other. The tour then took us on an … err … enlightening strole through one of Amsterdam’s more famous districts. We also saw the Heineken brewery and the Van Gough museum and bunches of other cool stuff while we were there.

The next major stop was Switzerland. We jumped straight off the bus and onto the gondolas that took us up to the top of Mt Pilatus, 7000 ft, where our hotel awaited us. That ride was arguably the single most amazing part of the trip. As we passed through forests of snow-covered pines it looked just like Narnia. The view from the top was amazing, just a sea of clouds with large chunks of mountain jutting out. Unfortunately the gondolas stopped running much sooner than we expected so we didn’t get as much time in the snow as we would have liked. So most of our free day in Switzerland was spent exploring the city of Lucerne which was ok, but a bit of a snooze fest compared to the fun we could have been having in the snow. Anyway we plan on getting back there eventually to do it properly. Contiki’s good for that – getting a taste of a few different places so you know what you want to come back and spend time on. Oh and there was this Swissco thing which I would only recommend to those looking to spend a lot of money on alcohol and possibly pick up.

GondolasLucerne? Choose snow!!Gondola View

Well I guess that’s about enough about our tour for now. More on that later.

In other news: Woohoo!! We just scored free tickets to go see the filming of an episode of The IT Crowd :) We applied for them online a couple weeks ago. There’s apparently going to be another episode with Noel Fielding in it and we put him down as our favourite comedian so they may have chosen us for that one.

December 17, 2006

Holy Cow we’re in London!

Filed under: Published, general — Pete @ 10:06 am

Well we’re in London! And we’re absolutely loving it. All the little houses are so cute. Every street is like a little villiage of its own, just like you see in all the photos and movies. The shopping and fashion – something I’ve never given a rats about before – is pretty incredible. So much variety in everything. So much good stuff to wear. We went to Harrods yesterday but didn’t get far cos the place was packed (was a Saturday). Didn’t even get to try a Krispy Kream but will be doing so ASAP!

We’ll probably go on a bus tour today and see all the touresty stuff like the Bridge, the Eye, the Palace, maybe do the Monopoly tour. The weather’s been kind too – sunny both yesterday and today. I’d heard that you can’t feel the warmth of the sun on your face in England, which thankfully isn’t true. We’re not finding the cold too bad yet either. It is kind of a novelty though, so time will tell. Anyway there’s only one internet access point in our hotel and I’m hogging it. More to come later.

August 23, 2006

Wrap this stiff in a tablecloth, we’re gonna bury him at sea

Filed under: Published, friends, general — Pete @ 9:46 pm

Went to Rob and Viv’s combined birthday party on the weekend. It was a fancy dress do with a “Heroes and Villians” theme. I went as Steve Zissou from The Life Aquatic, which some mistook to be Papa Smurf. That’s a fair call. Since you could go as your own hero (and because the similarities were too convenient to pass up), Aimes went as the very beautiful Meg White. Rob also made a pretty convincing Bernard from Black Books.

May 15, 2006

Senorita wont you take me to the drug store?

Filed under: Published, general, it, music — Pete @ 7:52 pm

Went out last night to see Gerling play at the Zoo. It was unbelievably awesome! They played a good mix of new and old stuff, the absolute highlight being the encore – Ghost Patrol!! Anyone who’s never seen them or doesn’t know who they are should get out and see them next time they’re in town. They’re a mad live show, doesn’t realy matter what you’re into. They were supported by Dappled Cities Fly whose insane dynamics and accents earned them instant respect in my books.

We met up with a couple from the Goldcoast. They were realy friendly and we ended up all staying out till the 3am lockout, just talking and experiencing the wierdness of other people in general. We swapped numbers and stuff so hopefully we’ll see them again.

The only regret of the night was that I left without getting one of those wicked Gerling benies.

Also discovered a new band a couple of weeks ago. A friend of a friend described them as “cooky pop”. That got me interested, and as soon as I hit their website I fell in love with their artwork. One of their album covers features one robot handing love to another on floppy disk! And the track listing takes me back to the good old days of BASICA on the TRaSh-80.

Musically they sound a bit like Grandaddy but with one major difference: Whereas Grandaddy will throw in shameless pop-candy to relieve the otherwise brooding nature of their songs, Sekiden tend to feature it more as a main ingredient. This makes for some pretty catchy songs, you just have to be in the right head-space to appreciate them.

They were supported by the Zoobombs, a nutzoid Japanese “funk hardcore” band. Nuff said.

May 8, 2006

Poetry: It’s All About Delivery

Filed under: friends, general — Pete @ 5:31 pm

A very funny thing happened today. I was tracing through my network traffic, debugging a WebDav application. I clicked on the first packet and opened up the stream. Since not much else was going on on my machine (network wise) typicaly the first packet would be the start of the WebDav conversation I was looking to debug. So imagine my surprise as this little number appeared:

<< Picture long lost in the move to the UK :( >>

I got this moments before messenger announced that elPoncho had sent it to me as an MSN message, so the whole experience was very random indeed.

Also, I never realy thought I’d plug The Cat Empire, but how good is The Wine Song?!!

April 6, 2006

WTF is this thing?…

Filed under: general — Pete @ 8:21 pm
Alien 1 Alien 2  

…and is it likely to eat me while I’m sleeping?

March 9, 2006

elPoncho and Viv’s Wedding

Filed under: friends, general — Pete @ 8:43 am

Two good friends, elPoncho and Vivienna got married last Saturday in what was probably the best wedding I’ve been to where I didn’t actualy get married myself. The ceremony was in a charming little chappel at the college of St Francis. Everyone had a great time at the reception and it was excellent to catch up with some friends from out of town.

Being in charge of the music at the ceremony was scary. It’s a simple enough job, but the stakes are high. When I wasn’t pressing play/pause it was hard to take a photo cos my hands were shaking. I was so scared of stuffing anything up. It didn’t ruin my enjoyment of the ceremony though, and when it was all over I was happy to have helped in some way. I can’t remember what the aisle song was called, but the registry song was Muskrat Love (America) and they walked away to Love Cats (The Cure) :) . How cool is that?

As far as I know the whole day went very well and I hope (and suspect) that the happy couple had as much fun as everyone else.

Some of the better photos we took are up on my Flickr site.