Browsed by
Category: Uncategorized

Spring JMX and Tomcat 7 Parallel Deployments

Spring JMX and Tomcat 7 Parallel Deployments

Spring JMX

The Spring framework makes it really easy to expose attributes and operations on your beans via JMX by the use of a couple of really simple annotaions.

First, you need some boilerplate config in your Spring context XML, like this:




And then you just need to sprinkle some @ManagedResource, @ManagedAttribute and @ManagedOperation annotations around your class, like this:

@ManagedResource(
    objectName = "bean:name=MyServiceImpl",
    description = "MyService JMX Stuff")
public class MyServiceImpl implements MyService {

    @ManagedAttribute(description = "Counter attribute.")
    public long getCounter() {
        return counter.get();
    }
  
}

When deployed to Tomcat, you should be able to look at your attributes and exercise your operations via any old JMX client (e.g. jconsole or VisualVM).

Tomcat 7 Parallel Deployments

Parallel Deployment” is a new-ish feature in Tomcat 7 which allows different versions of a webapp to be deployed side-by-side. It’s very simple in operation. You deploy a war file with a name like my-funky-webapp##001.war, and then another with a name like my-funky-webapp#002.war, and existing sessions get routed to version 001, whilst new sessions get bumped over to version 002. The version string can be any String; Tomcat decides which is the newer version by just sorting them as Strings, so xxx#9.war is newer than xxx#10.war.

Add them together and…

…parallel deployments stop working.

Specifically, newer versions of the webapp never start taking sessions.

This is probably really obvious to a lot of people, but it stumped me for a little while. The problem is that the Spring JMX annotations try to register an MBean according to the @ManagedResource annotations. The previous version’s MBean is still there (the old version stays deployed until any existing sessions expire). By default, the Spring JMX behaviour is to fail fast on deployment, which prevents the whole of the new version of the webapp from deploying.

The fix is simple. Just add a registration attribute to the <mbean-export> to get the new MBeans to replace the old ones, like this:




Using Flot to generate a barchart against a time-based x-axis

Using Flot to generate a barchart against a time-based x-axis

Wow – there’s a title to excite the hoards, eh?  This might read as a kind of ‘note-to-self’, because that’s pretty much what it is – sorry about that. It might be useful to someone though, I suppose.

Flot is a jQuery-based charting library, as previously used by the StackExchange family of sites for things like their reputation chart before Jeff et al decided that pretty graphs of your rep weren’t actually that useful.

My particular requirement was to chart a count of ‘stuff’ against hours of the day, so pretty graphs would be very useful. Here are some notes on how to do that.

Let’s start with a screenshot.  Here’s what I ended up with:

Flot relies on jQuery, so first of all we need to include that in our page, like so:

Then a link to the Flot library itself:

Flot works by replacing the contents of a ‘placeholder’ div, so stick one of those on the page, wherever you want the chart to appear. It needs an id so that Flot can find it, and a height and width, so that Flot can scale the chart appropriately:

Finally, we need to kick the chart into life, which I did like this:

1

Lines 4-9 are setting up the data to plot. This is just proving the chart library works, so I’ll be generating this with from the view’s model at some point, but you get the idea. When plotting against a time axis with Flot, you need to generate a Javascript timestamp, hence the new Date(...).getTime() stuff.

Line 11 calls the Flot function to generate the chart, selecting the placeholder div, and passing in the d array of values.

Line 12 tells Flot that we want a barchart. barWidth: 1000*60*60*0.5 stipulates that the bars should be ‘half-an-hour’ wide. Since we’re charting in milliseconds (that’s what Javascript timestamps are based on), we need to tell Flot how many of them each of our bars should take up. Without this, the barchart would be generated with 1 pixel wide bars – not very pleasing on the eye.

Line 13 tells Flot to interpret the x values of our data as Timestamp values, so we get a useful ‘8:00’ instead of a not-so-useful ‘1342314544452’.

And that’s about it. Some things to remember:

  • Flot doesn’t do axis labels. If you want one, you’ll need to put it on your page yourself, which is a bit sucky.
  • I got mixed results when experimenting with the barWidth parameter. Too narrow, and the x-axis scale started to get screwed up. A 50/50 ratio between bar and ‘gap’ seemed to look ok and not cause other problems.
  • There’s a whole bunch of other parameters that I didn’t use. Here’s the full Flot API documentation.
  • If you’re using Eclipse and including Flot in your project, then you’ll probably end up with a couple of Javascript errors and metric shedload of Javascript warnings. I’m not in the business of fixing other people’s code (especially when it seems to work just fine, thankyouverymuch), so I just stopped Eclipse whinging by excluding the Flot (and jQuery) files from the Eclipse Javascript source. See this StackOverflow answer for details.
When 2 Screens Just Aren’t Enough…

When 2 Screens Just Aren’t Enough…

At work I generally use a laptop with an external monitor. This is usually fine; email / specs / documentation on the laptop screen and my dev tool on the external monitor. Sometimes, though, that just won’t do.

To get round this, I snaffled a spare monitor from a recently departed contractor’s desk, and got myself a USB-to-SVGA adapter from Amazon – this one, actually:

Max Value High Resolution USB 2.0 to Widescreen SVGA Adapter (MV42432)

Whilst it’s never going to be mistaken for a ‘real’ graphics card, it does an OK kind of job on largely static things. You can definitely tell it’s a little plastic box though – updates are a bit jumpy, and if you’re a quick enough typist you’ll actually ‘feel’ the delay. But, it does the job I got it for perfectly; I can look at big complex specs on one monitor, and make them into real breathing code on the other.

7/10. Or maybe 8 if you really don’t want what you’re displaying to move, ever. 2 if you want it for watching videos (tip: you don’t).

Tree Top Drop

Tree Top Drop

Just in case anyone has managed to avoid seeing this all over Facebook, here’s a little video clip of Mary throwing herself off the vertical drop slide thingie at Wildwood, our local wildlife park.

The slide is good fun, though you wouldn’t know it listening to the shriek of fear in this clip…

The video is from my HTC Desire HD, which does a half decent job when I stop waving it around like an idiot.

Neglected++

Neglected++

I’m getting fed up with this.  Every so often I come and have a look at my site to make sure it’s still there and hasn’t been hacked again, and I see the same old front page, with the same post that’s been sat there for 160 days.  I think it’s made worse by the fact that, essentially, it’s a post stating that the previous post was a load of rubbish.

Oh well.  I’m here again now, and feeling like I should be doing more.

The first step is quite obvious; I need to start posting again.  Blogs are being squeezed out thanks to the likes of Facebook and Twitter.  140 characters is, apparently, enough room to get most ideas across, so what’s the point of writing out a whole blog?  Well, for me, it’s about writing.  I like writing – I like getting points across and I like the idea of expanding on an idea and bringing it to a conclusion.  I like the idea, but I’m not very practised at actually doing it.

That’s where this old blog comes in.

I have a few ideas for things I’d like to write about.  I’m not sure how many of them will actually be of any interest to anyone, but I think – and hope – that the act of writing them and publishing them here will both inspire me and lend them some kind of importance.  It’s easy to dismiss things as ‘good enough’ when no-one is going to read what you write.

So, if I’ve popped into your RSS reader for the first time in the best part of 5 and a half months, or you do actually visit the actual site once in a while (and laugh at the rubbish post that’s greeted you for all that time), stay tuned.  There should be an actual, content-laden update soon.  I just need to reach a few conclusions for my half-cocked ideas, and convince myself that they’re ideas worth sharing…

Formula 1 2010

Formula 1 2010

Well, I got that a bit wrong, didn’t I?

I’ve really enjoyed the 2010 F1 season so far, and it’s shaping up nicely for an exciting showdown. Whilst Mr Schumacher hasn’t quite lived up to expectations (apart from that move against Barrichello in Hungary), the rest of the protagonists have all played their part, and with 5 races left the top 5 drivers are within one race win of each other. Fantastic stuff.

So, I unreservedly take back my somewhat scathing previous post, and admit that maybe, just this once, the clever people in charge of F1 might just have got it more right than I gave them credit for. Who’d a thunk it?

So, who reckons Jenson’s going to have a storming end to the season and make it back-to-back championships? It’d be nice, wouldn’t it?

Does the ‘F’ stand for ‘Fail’?

Does the ‘F’ stand for ‘Fail’?

Formula One. The pinnacle of motorsport. The best drivers, racing in the most advance racing cars in the world, on the best racetracks we have to offer. And this season, wow – what an exciting prospect. 4 former world champions; 2 of them racing for the same team! Michael Schumacher coming back after his short break. New teams, new rules. What more could a fan ask for?

Sigh.

3 and a bit years ago I bemoaned the lack of excitement in Formula One, and offered a few ideas to jazz things up a bit. Maybe someone read my blog back then afterall, as most of my ideas seem to have found their way into the rulebook (except the reverse grids… is that just BTCC?) Bernie even stole my ‘one point for a win’ idea and rebadged it ‘medals’, before he ran out of brave pills. And it got better. The racing did seem to improve. There were proper exciting races and tight championships going down to the last corner of the last lap of the last race of the season.

And now they’ve gone and broken it again. Just one race into the new season, Alonso says races are going to be decided in qualifying and on the first lap of the race. Schumacher says the first race was fun but dull, and he’s right about the dull part.  Apart from a couple of glimmers of overtaking from the new boys, Webber’s overfilled oil tank, and Vettel’s cracked exhaust, nothing happened. The Ferraris held together, Hamilton picked off the lame Vettel, and 49 laps of mediocrity passed in a little under 100 minutes.

So, what to do?  Well, I’m afraid I’m out of ideas (sorry Bernie).  I suppose things might get better in Australia – at least there might be some discernible crowd in attendance to give things a sense of occasion.  Maybe a shorter track will mean more racing opportunities.  Maybe Webber will put a show on for his fairdinkum mates.  Maybe Lewis and Schumacher will get to go at it hammer and tongs, wheel to wheel.

I remain hopeful, but can’t help feeling that we’re in for a pretty yawnful year on the track.  It’s a sad state of affairs when you find yourself hoping for some off-track scandals just to keep the interest levels up.

So, come on you clever F1 guys.  Please think of something to keep us watching.

Survival

Survival

It’s Sunday evening, which must mean we’ve managed to survive another weekend – yay for us 🙂

Saturday was the usual mix of swimming, shopping and a little housework. Oh, with a certain 9-year-old’s birthday party thrown in for good measure. I’m not particularly secretive about the fact that I dislike these events, but this one wasn’t really that bad. The kids all behaved themselves, and I actually managed to learn a few of their names and have something approaching conversations with them. Well, OK, it was food time and they told me what sandwich they wanted, but that’s progress for me.

Today was time for more shopping (for Mrs H anyway, I stayed home and marshalled our little darlings), a walk, and then (a delectable) Sunday Roast with the in-laws.

Oh yes – these walks. We’re surprising ourselves with this. Since our trip to the Lake District, we’ve been taking ourselves off for weekly walks. We’ve invested in 3 Landranger OS maps (178, 179 and 189, fact fans), and spend 5 minutes on Saturday evening deciding on a suitable spot, and then 2 or 3 hours on Sunday walking. Surprisingly, we’re enjoying it. More surprisingly, with the weather not looking too promising this morning, we still headed out, and we still had fun. Who’d a thunk it?

If you want to keep tabs on where we’ve been and what we’ve seen, there’s a new link over there on the right with the oh-so-imaginative title of ‘Walks‘. It takes you to a section of this site where I’m trying to record where we go along with any notes and comments and so on. The Google maps with overlays of our routes are nothing clever on my part – they come from Everytrail.com, a site that lets you upload GPS tracks from a variety of sources (I use my lovely phone).

Now… I’m being told I’m only typing here to avoid jumping on the Wii Fit thingie to be told how fat I am.  It’s true, but I can delay no longer…