Longform
Olympian Achievements
Initial scepticism
Back in 2004, 2005 or so, when London was bidding to host the Olympics, I was against it. My concerns were the cost, the crowding, and the general disruption of it all. I was, I admit, cynical. I recall being annoyed by the fact that the people running the bid published a number to which you could text “yes”, to say you supported the bid; but there was no option to text “no” to say you opposed it.
Looking back to what I wrote at the time, I see that my biggest concern was the effect on the Lower Lee Valley. It turned out that the removal of wilderness didn’t stretch as far as my fears suggested; and of course much of the land that has been used was polluted, abandoned, brownfield industrial sites. Bob Stanley of St Etienne (the band) has an interesting piece in The Guardian about that.
Coming round
But then London won the bid, and I though, “OK, fine, it’ll be interesting at least.” I had enjoyed watching the previous ones, and there was the regeneration for East London that looked promising. And the fact that it would just be down the road for me added to the interest. After all, that would make it easier to get tickets, right? Obviously there would specific tickets made available to to locals.
Hindsight even makes me wonder whether the events of the very next day didn’t make me more supportive: blitz spirit, don’t let the bastards grind you down, “soft power”, and all that.
The intervening years
Worries
In the years since then I’ve gone through various thoughts about the whole thing. Obviously there were the concerns about how long we would be paying for it all. And more recently there were the worries about the security preparations and the expected madness of the precautions. Of course more recently we’ve had the G4S fiasco, and the drafting in of extra soldiers.
More bizarrely we’ve seen the growth of the Olympic “brand police”, the forbidding of certain words and combinations of words (including, ridiculously, things like “summer”, “bronze”, and “2012”).
Cycle-friendly or not?
But closer to home one of the things that has annoyed me is the way they’ve treated our towpath.
The main stadium sits between two branches of the River Lee (or Lea): the river itself, and the Lee Navigation or Cut, which is essentially a canal constructed as a tributary1 of the main river. The towpath of the Navigation is a popular cycling and walking route for us local types. As we watched the construction site form and the massive buildings grow (and in my case moaned about the ugly fencing round it), we were able to keep a close eye on it all by going along the towpath. And indeed, a minor, but pleasing, instance of regeneration has been the resurfacing of the towpath, making it much more pleasant to cycle on.2
Above all, it seemed obvious that we would use the towpath to actually get to the Olympic Park. How else?
Until a few months ago when it became clear that the towpath was going to be closed for the duration of the games. The reason given – of course – was “security”. But what exactly is the security risk of providing access via the towpath?
In all honesty, I had my doubts about its use during the games; but I wasn’t concerned about terrorism. Rather I feared for people’s safety. It’s a towpath, after all: relatively narrow, unfenced, and unlit. And, critically, next to a polluted canal. If thousands – or even only hundreds – of people were trying to leave the park that way all at once – after the opening ceremony, say – then I could see that it would be problematic.
So I begin to wonder whether the “security” excuse was brought out to hide the more mundane, but always-criticised-by-the-tabloids truth: health and safety.
Then we heard that bikes would be among the banned items in the park; but also that there would be cycle parking: it sounded like mixed messages, but we would have to wait and see.
Those pesky tickets and the getting thereof
Ah, the joys of Olympic ticketing. Even as I write, on the third full day of the Games, they don’t seem to have really sorted it all out.
It’s a massively complex task, to allocate and sell tickets for hundreds of events over dozens of venues, all taking place in such a concentrated time period. But it’s not like they’ve never done it before; it’s not even like they haven’t done it in the Internet Age. It should largely be a solved problem, it seems to me.
We had decided to treat the Olympics as our family holiday: we would take a couple of weeks off, buy a load of tickets, and that would be our main summer break. After all, it would be just down the road, a once-in-a-lifetime opportunity, etc. So we signed up for the ballot, spent time listing events we might like to see, and so on. When the time came we hit the website and listed a summer holiday’s worth of tickets (hampered slightly by me having a MasterCard, which of course is the black sheep of Olympic ticket-buying).
In the end my beloved was allocated tickets to three events, and I got none (had they detected that invalid-card possession?)
However, that was just the initial ballot; and because I had been unsuccessful there, I was entitled to try to buy tickets in the conventional way in the second round.
On the day I woke up early and grabbed my laptop. The site, inevitably, crumpled. I went back to sleep for a bit. Tried again later.
I don’t recall how long it took, but in the end I managed to get a further three events.
And that was that. Remember when I said up there, “it would just be down the road … that would make it easier to get tickets”? Yeah. Somehow that didn’t happen. The Olympics is clearly not meant for the people who live near it. Or not particularly. I’m not suggesting it should be only for locals; but how hard would it have been to allocate a percentage of tickets to residents of host boroughs – or the whole of London – in a first pass? If they didn’t get bought they would be offered on, of course. The answer is “not very”; the Hackney Weekend festival did exactly that, after all. Glastonbury gives free tickets to residents of the nearby village, I seem to recall.
Anyway, that’s where we are. We later added a Paralympic athletics day, which will finally get us into the main stadium; and a set of Olympic Park passes, so we can go and have a wander round and soak up the atmosphere on Wednesday. But as I write there are still tickets available, even for swimming, even for the main stadium.
If you’re made of money, at least. Hell, you can still go to the closing ceremony if you’ve got £995 or £1500 to spare.
But still…
But I don’t mean to turn all negative. I’m actually really excited about it all, and thoroughly enjoying everything I’ve seen on telly; especially, of course, Danny Boyle’s masterpiece of an opening ceremony. Much has been said about that elsewhere, so I won’t say a lot. Just that it was far better, and a far truer representation of Britain than we could have imagined, or even hoped for. Part of the fun was following along on Twitter, of course (when it wasn’t too distracting to do so). And my favourite comment of all was one that Mitch Benn retweeted from Simon Evans:
It's not that I'm proud to be British. It's that I'm grateful.
So true.
And I’ve been enjoying seeing the first few days worth of events on telly. Some thoughts:
- The tennis is just like Wimbledon, except with colour, and Omega timing instead of IBM. And "London 2012" logos, of course.
- I normally go from one Wimbledon to the next without watching any sport; now, suddenly, I'm almost fanatical about everything (except boxing and anything with horses; and archery is much more boring than you might expect).
- Seeing those cyclists in the road races made me want to get on my bike; not for those kind of distances, though.
- Similarly, badminton & table tennis; maybe there will be a knock-on effect on people doing sport after all.
I should write about legacy (and sustainability3), but I’ve gone on long enough, and anyway, it’s another whole discussion. But I cycled down that way on Saturday; along the part of the towpath that’s still open, across Hackney Marshes (by a new, temporary path) and to the bridge across the river where there is access via Eton Manor Gate. There is a vast cycle park there, and from the gate it’s only supposed to be a few minutes walk to, for example, the Basketball Arena. So it’s all good.4
We visit the park on Wednesday, and start seeing actual events from Friday. I may report back.5
-
Or really an inverted tributary, as it forks off the main river in a downstream direction. ↩︎
-
There are still a few spots of cobblestones, but we can cope with those. ↩︎
-
Yes, that’s a Twenty Twelve reference; if you haven’t watched it, you should. ↩︎
-
Yes, so was that. ↩︎
-
But under no circumstances will I post photos, OK? ↩︎
Google is Buying Sparrow, but not Updating the Apps
This is annoying. The only thing that was stopping me from making Sparrow my default mail client on my iPhone was the fact that it doesn’t do rotation to landscape mode yet. Now it looks like it never will.
It’s rarely good in the long run when big software companies hoover up small ones, it seems to me.
A British Court Bans a TV Broadcast
The most chilling thing about this is not so much banning the broadcast; there could conceivably be a legitimate reason for that, though it’s hard to imagine a good one. Rather it is this:
For legal reasons, the Guardian cannot name the judge who made the ruling, the court in which he is sitting or the case he is presiding over.
This meta-blocking smacks of the "superinjunctions" that we heard a lot about a few years back (but which strangely seem to have dropped out of sight recently).
Tip: using Pandoc to create truly standalone HTML files
If you’re using the excellent Pandoc to convert between different document formats, and you:
- want your final output to be in HTML;
- want the HTML to be styled with CSS;
- and want the HTML document to be truly standalone;
then read on.
The most common approach with Pandoc is, I think, to write in Markdown, and then convert the output to RTF, PDF or HTML. There are all sorts of more advanced options too; but here we are only concerned with HTML.
The pandoc command has an option which allows you to style the resulting HTML with CSS. Example 3 in the User’s Guide shows how you do this, with the -c option. The example also uses the -s option, which means that we are creating a standalone HTML document, as distinct from a fragment that is to be embedded in another document. The full command is:
pandoc -s -S --toc -c pandoc.css -A footer.html README -o example3.html
If you inspect the generated HTML file after running this, you will see it contains a line like this:
<link rel="stylesheet" href="pandoc.css" type="text/css">
That links to the CSS stylesheet, keeping the formatting information separate from the content. Very good practice if you’re publishing a document on the web.
But what about that “standalone” idea that you expressed with the -s option? What that does is make sure that the HTML is a complete document, beginning with a DOCTYPE tag, an tag, and so on. But if, for example, you have to email the document you just created, or upload it to your company’s document store, then things fall apart. When your reader opens it, they’ll see what you wrote, all right; but it won’t be styled the way you wanted it. Because that pandoc.css file with the styling is back on your machine, in the same directory as the original Markdown file.
What you really want is to use embedded CSS; you want the content of pandoc.css to be included along with the prose you wrote in your HTML file.
Luckily HTML supports that, and Pandoc provides a way to make it all happen: the -H option, or using its long form, –include-in-header=FILE
First you’ll have to make sure that your pandoc.css file1 starts and ends with HTML tags, so it should look something like this:
<style type="text/css">
body {
margin: auto;
padding-right: 1em;
padding-left: 1em;
max-width: 44em;
border-left: 1px solid black;
border-right: 1px solid black;
color: black;
font-family: Verdana, sans-serif;
font-size: 100%;
line-height: 140%;
color: #333;
}
</style>
Then run the pandoc command like this:
pandoc -s -S --toc -H pandoc.css -A footer.html README -o example3.html
and you’re done. A fully standalone HTML document.
- It doesn’t have to be called that, by the way.↩
Bash - how to recursively find the latest modified file in a directory
From the mighty Stack Overflow, some useful tips on using find with dates.
Weekend Warblers
The Radio 1 Hackney Weekend festival was fabulously well organised, loads of fun, and passed off with only three arrests.1 Booking the tickets a month or two ago had turned out to be easy (we sat with multiple browsers and phones as the SeeTickets site crumpled, but in fact it was no trouble at all after we left it for a while). Being local residents helped, as half the tickets were for Hackney households.
It was a free show, so there were restrictions; most notably that you could only book for one of the two days, and only two tickets per person. We were doing it for the kids; and the kids in this family (to say nothing of most of their friends) favoured the Sunday lineup; so that’s the one we went for.
The lineup leaned heavily to the various dance subgenres: (modern) R&B, dubstep, and so on. Not forgetting hip-hop, of course; not only did Jay-Z headline the first night, he guested with Rihanna on the second.
For me the highlight of the day was Jessie J; though I was mildly disappointed that she censored herself in my favourite of her songs, ‘Do it Like a Dude’.2
Tinie Tempah was also good, though since I’ve subsequently been listening to Enter Shikari, I’m slightly disappointed to have missed them as they clashed with Tinie.
There was great secrecy and much speculation over who the “Special Guest” was to be. They managed to keep it hidden until the day, which, while impressive in its way, had me worried. I thought that, depending on who it was, there could be a disaster. In particular, if it had been Justin Bieber, as some kids were speculating, there would have been a vast, simultaneous, two-way flow, from and to the stage (my kids would have been running away from the stage; there are no Beliebers at Devilgate Towers).
Not long before the guest’s time I heard on good authority that it was going to be Beyoncé. Believable, as her hubbie was there, and she was said to be “in the house”. But I doubted it: isn’t she a bigger name than Rihanna? And anyway, I get the sense that she’d be too much of a diva to go on second on the bill.
Anyway, in the end it was Dizzee Rascal, which with hindsight made total sense, what with him being a local boy and all.
As we wandered through the stages and the day, we heard snatches of Rihanna’s ‘We Found Love’ seven times (I started keeping count at the third) from various between-act DJs and stalls. So by the time it closed the night, I was thoroughly ready to hear it properly. And a damn fine ending it was, too (though the fireworks were a tad tame).
I was hugely impressed with the organisation of the thing. We got there nice and early, and there was hardly any queueing, despite the airport-style security. The staff were all lovely and friendly, and – get this – there was hardly ever a queue for the toilets!
I would strongly support any moves to make it a regular thing. Radio 1’s event moves around the country, so it couldn’t stay free, but I could easily see it working as a commercial festival in the future.
A Line, a Loop, a Tangle of Timey-Wimeyness
This week, though, I’ve been to the presentation of the Clarke Award, which is held in association with the festival, and at its main venue; and last night, the whole family went to the BFI (or the NFT, I can’t quite work out what its official name is these days) to see a film.
Which was Dimensions, a low-budget British film about time travel – or maybe dimension-hopping – which doesn’t even have a distributor yet.
Which is a great shame, because despite some flaws it is a very enjoyable piece. We were still talking about it at lunchtime today.
It’s also something of a costume drama, being set in the 1920s and 30s. The Sci-Fi-London page about it likens it to Merchant-Ivory.
It did show its low-budget nature in one or two places, but nothing that destroys the overall effect. The couple who made it (Ant Neely wrote and composed the original music, and Sloane U’Ren directed and did much else) had to sell their house to fund it, so almost anything can be forgiven.
I won’t say too much more about it here, but if you ever get a chance to see it, you should take it.
There was a Q&A with writer, director, lead actor & editor after the screening, which was very interesting. I was geared up to ask a question, which would have gone something like this: “When you make a time-travel story, especially in Britain, you’re walking among some long shadows, especially Wells and Doctor Who; to what extent would you acknowledge those as influences?” I had my hand up to speak, when the interviewer asked a question touching on exactly those points. So I didn’t ask. Pity. I would also have mentioned the fact that they have a mysterious wise man know only as “the Professor”.
Anyway, lots of fun: highly recommended.
Voting Time Again
Time to hit the polling booths again. Doesn't seem that long since the last one. But it's a lot easier to decide this time. Brian Paddick's a decent guy, but the Lib Dems have shown they can't be trusted over the last two years.
Boris hasn’t been quite the disaster we feared four years ago, but he still cares more about the richer members of society than everyone else. Plus, he’s a Tory. But I repeat myself.
Ken seems kind of past his peak, but he’s still the one for the job. Though I might give Jenny Jones my first vote and Ken my second. I think that’s what I did last time, come to think o it.
For the Assembly it’s going to be Labour all the way. I’m not impressed with how they’re doing in opposition at Westminster: the Tories are down, but they don’t seem to be kicking. Kick harder, Milliband! But to run London? Obviously it’s got to be the (relatively) good guys.
What’s surprising and slightly scary is the number of extreme-right parties who have put candidates up. obviously there’s the BNP and UKIP: but who knew the National Front were still around? Then there’s ones with names like England First and Christians Against Marriage Equality. (Those names may not be exact, but I’m on the Tube at the time of writing, so I can’t check; but you get the gist.)
Anyway, that’s where we are today. Don’t forget to vote if you can, folks.
Weird Law-Enforcement Things
There were three slightly weird law-enforcement- or intelligence-related stories in the news today:
- Two jailed in Northern Ireland over police officer's murder.
I heard the policeman’s wife on the radio. She spoke calmly about how getting the murderers off the streets was good for the community, and positively about the people who had bravely given evidence (at least one had to be given protection).
The odd, disturbing, and intelligence-community-related thing is that army intelligence had a tracker device in the car of one of the murderers, and at first they refused to reveal its details to the police undertaking the investigation. The police had to threaten to get a warrant. Then when they did provide the data, it turned out to have sections mysteriously missing. You have to sympathise with the PSNI here: they had both the Continuity IRA bampots and the army working against them.
'Dark Arts' involved in MI6 officer's death.
So what, this GCHQ codebreaker on secondment locked himself inside a bag using magic? I’m surprised that they’re even considering that it might not be murder here; or at least that someone has covered something up. More importantly, there’s the fact that the DNA evidence got messed up by a typo. Surely there’s got to be a better way?
Police officers deleted records of crime gangs
And then there’s this business about the corruption in the Met. Evidence allegedly deleted on the orders of crime gangs? That’s some scary stuff. I’m pretty sure that when the Serious Organised Crime Agency was set up, it was meant to be anti-organised crime.
No real connection between these, I just heard about them all today.
A Drop of the Hard Stuff
...potential readers are still coming to the genre. Books aren't the entry drug any more. Books are the hard stuff, the crystal meth of genre.
Paul Weller in "Good Album" Shock!
Who would have thought, this many years after The Jam, that Paul Weller could still make a decent album? Yet that's exactly what he's done. You can listen to it at The Quietus, an online music magazine.
Penguin Pete's Blog - Using Bash To Solve A Brain Teaser
[Great use of Bash scripting to do a maths puzzle, but demonstrating lots of useful features.](http://penguinpetes.com/b2evo/index.php?title=using_bash_to_solve_a_brain_teaser&more=1&c=1&tb=1&pb=1)
Terror, or Not; and Bail
I’ve been meaning to write a post about the Abu Qatada situation. But Jack Deighton has said all I would have; most notably, “If we do not behave in a better way than those who are against what we stand for then we would be worse than them.”.
The BBC lists Qatada’s bail conditions. Why the emphasis on technology, you have to wonder? Is he going to terrorise us over the internet?
Pass-By-Reference Problem When Using Websphere Application Server
This has been kicking around, nearly finished, for months. It's not going to get any better, or shorter, so it's long past time I put it out there.
It’s also just long; and technical. So feel free to ignore. I won’t be offended.
I rarely write about programming or other technical issues here, but I probably should do so more often. Certainly in a case like this.
I often think about the many, many problems that I’ve had help with from strangers on the internet; people who have taken the time to write blog posts, answers to questions on forums, or technology tutorials. My job would barely be possible at times without the web. Of course, we didn’t have it back when I started in 1987; but we didn’t do such complex things, with so many different languages and technologies.
Anyway, all these kind strangers have helped me, and I rarely find myself in a position to give anything back to the community. So since I recently hit a problem that no-one else seems to have had, it’s really my duty to describe it, and my solution, in the hope that it might be of use to someone down the line.
If you’re looking for the solution to the problem with pass-by reference on WAS, and don’t want to read the story of how I got there, you can jump straight to The New Bug
Background
We develop our main app using a fairly standard n-tier architecture using JEE: web front end using JSPs and Struts; EJBs; a multiplicity of database platforms accessed using Spring. All fairly standard stuff, whose purpose is to move financial messages around.
A lot of this was originally developed when I wasn’t around (I was seconded to another department) and by contractors and others who are no longer with us. So I take no responsibility for the stupidities that exist in codebase. Or rather, I accept no blame. I do, in fact, have responsibility for it; for keeping it going and developing it onwards now.1
One of the bad choices that was made by the original developers of this version of the product, was that they should cache the results of database queries. The users can define various criteria by which they want to select a set of messages to view; those get translated into SQL, which our Java code executes using JDBC. Again, all standard stuff. JDBC was designed for exactly that kind of thing. Databases exist solely to do that kind of thing.
So the wise and sensible developers decided that performance would be a problem if a query returned many rows from the database. They decided that transferring the rows to the browser and allowing the user to scroll through them would be impossible. So they designed a caching mechanism.
Thing is, JDBC has that kind of caching built right in. And furthermore, they (our developers) included a limit: a maximum number of rows to return, which could be set to 50, 100, 500, or 1000. Pretty reasonable, since any query that returned over 200 or so rows is likely to be less than useful, anyway.
But they still built that caching mechanism.
The Mechanism
That’s all right, though, I hear you say. Cache the rows server-side in memory, return a subset to the user as they page through them. It sounds fine.
True enough. Except they didn’t cache them in memory. Oh no. That would have been too sensible. And might have caused performance problems (I’m sure they thought, if they even considered they matter). No, they cached them elsewhere. Where? In the database.
Yes, they introduced another table; a shadow table; an almost-identical duplicate of the Messages table, called MessageQueryResults. Executing a query then consisted of selecting the required rows and writing them into this table, keyed by the HTTP session ID; and then re-querying this results table to get a page worth of results.
So, to recap, then: to improve performance (without first determining that there was actually a problem), they replaced a simple database read with a read, a set of writes, and another set of reads.
That was bound to perform better, right?
The Failure
It wasn’t performance that brought this flimsy edifice crashing down, though.2 No, it actually ran quite successfully for several years. Three things brought about its end: Microsoft, multiplicity, and me.3
Microsoft’s part was through their database platform, SQL Server. Between one version and another they changed something about their storage mechanism, so that you could no longer rely on rows on a table being in the sequence in which they were written to the table. The thing is, you’re not supposed to be able to rely on that, according to DB theory. That was another flaw in the “design” above; it relied on the shadow table’s rows being returned in the same sequence they were written in. On Oracle and DB2 that worked; and it did on SQL Server too, until (if memory serves) the 2005 version. This meant that clients on that platform who had large queries couldn’t rely on them being displayed in the right order.
Oh dear.
Hacks were applied to sort this out. Pun intended: sorting is pretty much what they did. Not a fix, but a workaround at best.
The multiplicity part was that the same mechanism was used to query another table; and then a third. And there was a fourth on the horizon. Each new table meant a new shadow table which had to be maintained in parallel – and whose creation and upgrade scripts had to be maintained across three database platforms. A maintenance nightmare.
Then there was me. I had known about the problem for some time, of course – I had done an estimate for fixing it – but there was never time to fix it. It was a big task, quite intrusive, and showing no easily-provable customer benefit. Yes, I know ease of maintenance, by making life easier for developers, is an implicit customer benefit; but try selling that to management, when there are customers crying out for new features.
But in the project that was to introduce the fourth table (or seventh and eighth, you might say) I was in a position to say, “we fix this first, or it all goes to hell”.
The user story was written. I got my estimate out of hibernation (and increased it, of course). And then I did the fix. It was a great joy. That in-memory caching mechanism I mentioned above? I did that. If I’d been designing it from scratch I would almost certainly have relied on JDBC’s internal caching, at least until it proved problematic. But under the circumstances, when the code relied on there being a cache, it was going to be much less disruptive to retain one. I just replaced the stupid one with a more sensible one.
Inevitably, though, I introduced a new bug.
The New Bug
This is where I stop telling a story and start explaining the problem and solution.
Introducing the new message caching mechanism, which replaced the MessageQueryResults table, inadvertently caused a problem when we set a WAS server to pass-by-reference mode.
This mode is recommended when the different tiers of the application (web, EJB) are running in the same JVM. This is normally the case in our test environments, and frequently the case in client systems. Enabling this mode removes the need for objects to be copied as they are passed through the tiers, and can improve performance dramatically in such environments.
What Went Wrong
Changing the caching mechanism caused no problem as long as pass-by-reference was off. As soon as it was turned on, we noticed that taking certain actions, such as deleting a message, failed.
The failure was at a point in the code where the a value such as an amount was being retrieved from the Map that formed the new cache. The failure was that the retrieved Object was being cast to a Number, but what was in the Map entry was actually a String.
This Map comes, by a fairly complex set of steps, from the new cache, and before that from the database itself, of course.
Now, since the Amount column on the DB is numeric, and the Map in question is originally populated via Spring from the DB, obviously the value was a numeric one originally. This suggested that the value must have been changed, and that gave us the first clue to tracking down the cause of the problem, and coming up with a solution.
The Cause
It seemed likely – and running debug, it was shown to be so – that the numeric value that was retrieved from the database and stored in the Map was being replaced by the edited value which is built for displaying. In other words, the object now contained a String holding digits, a decimal point, and probably commas.
Why it Changed When We Switched on Pass-By-Reference
When the data was being passed by value, a new Map, complete with its contents, was being passed from the EJB layer to the webapp. The webapp then updated values in that Map, editing them for display purposes. But it was only changing its own copy; it had no effect on the version stored back in the EJB layer. So when the same Map was retrieved again, so that the action could be performed, a new copy was received by the webapp. No problem.
But when pass-by-reference is on, no copy is made. The webapp receives a reference to the actual Map that is stored in the cache back in the EJB layer. So when it updates an entry in that Map, it updates the very object that is stored in the cache (note that the put method of the Map interface will update the stored value if it receives a key that it already holds).
And then when the Map and its entry are retrieved again for the action to be performed, it is the updated (and now wrong) version that is retrieved.
Why it Changed When We Changed the Caching Mechanism
And yet both possible passing settings were available before we changed the caching mechanism. Why did we not get this problem when using pass-by-reference with the old caching mechanism?
The answer to that is that the old mechanism cached the query results in the database itself, in the MessageQueryResults table. Each time a set of results was requested by the webapp, the EJB layer went back to this temporary table and populated the Map that it returned to the webapp. So the amount value would always have been set up freshly from the numeric Amount column, which ensured that it was an object of type Number.
The Fix
I tried making copies of the Maps and Lists used, at various points in the process, including using ImmutableLists and ImmutableMaps from Google’s Guava library, in an attempt to prevent the value object of interest from being updated. However, it wasn’t possible to make them immutable deeply enough (and would probably have caused other problems if it had been). That was largely because the principal Map is created and populated by Spring, so we don’t have much control over it.
One solution – and probably the proper one – would have been to copy the entries from the Map at the point they are read and processed in the webapp. This would have meant that the edited, String, version of amount would be a different, new object, and would not have been updated in the Map that came from the cache.
However, the vast complexity of the class where this would have had to happen made this seem like a very difficult and dangerous approach, especially at this late point in the project.
An alternative solution was suggested by one of my colleagues. It was to accept the fact that the amount value might be a String containing a numeric value with commas and decimal point, and to parse the numeric value out of it.
This allowed us to cater for both numeric and string values, and it worked with either form of passing semantics. But it felt like a hack, and I was sure it would come back to bite us.
Fixing the Fix, a Little Later
It did. The trigger this time was paging through the list of results; when you returned to a page you had already seen, you ended up with an object of the wrong kind coming out of the Map. If memory serves it was a String where it should have been a Date.
It was clearly another result of the data being edited for display and updated in-place in the Map. There are too many possible places in in the relevant method to rely on finding them all, so I returned to the “probably the proper” solution mentioned above. I changed the relevant method such that it now returns a copy of the List containing the required subset of the query results. This is less straightforward than might be hoped, because copying a List, including by the clone method of the implementing class, for example, tends to do a “shallow copy”, which means that you get a new List instance, but containing references to the same objects.
I wrote a method called copyList, which iterates over a List and makes “deep” copies of a few expected types of object. We may have to extend this method to handle other types, but I don’t expect that at the moment.
Also Worth Noting
There is a warning about this on IBM’s Best Practice: Using pass by reference for EJBs and servlets if in same JVM page, but it’s one of those typical contrived kind of examples that probably wouldn’t really alert you to the possibility of something like my experience.
Notes
To set the pass-by-reference mode on or off, take the following steps in the WAS administrative console (this is WAS 6, it’s probably different at other releases).
Go to Servers -> Application servers -> <server -name>
Expand Container Services; click on ORB Service; check/uncheck “Pass by reference”
Your Friendly Olympic Park
This is the view from the banks of the Lea (or Lee) by the Olympic Park:
Let’s take a closer look at that attractive fence:
Lovely, eh?
I hope they take it all away and make it nice and open, but I suspect they won’t, at least until after the Games.
Cluttered by Google, Lost by Bing
I was reading The Clutter Didn’t Kill the Love by Brent Simmons, about how he was trying Microsoft's Bing search engine, instead of Google. His reason was the current worry that Google is becoming less than trustworthy.
Google losing trust would be a shame. But at least a Google search for “martin mccallion” (without the quotes) has this blog as the number one hit. Try that on Bing at the moment and you get a whole pile of other Martin McCallions.1 The worst part to me is that the first six are Facebook or LinkedIn profiles (the seventh is one of those annoying directory sites, then you get me).
I wouldn’t mind other people with the same name appearing above me, if it was their proper sites; but to me social-network profiles feel like distinctly second-class web entities.
Or is that snobbish?
-
As an experiment, and to ensure a like-for-like comparison, I signed out of Google, and went to the .com version (I normally use .co.uk by default). I was still at the top. ↩︎
The Felice Brothers
As if there weren’t enough reasons to love Outnumbered already, we recently saw an old Christmas special. It ended with the family watching the telly and singing along to a song. I didn’t know it, but liked the sound of it.
The internet knows all, and a bit of googling told me it was ‘Frankie’s Gun!’ by The Felice Brothers.
Emusic has the relevant album, and it’s great. Highly recommended.
Also their site tells me they’re playing London on the 20th of March. Hmmm…
