When Disabling DNS Caching Doesn’t

If you’re going to fiddle with networkaddress.cache.ttl, do it before you touch the network.

I was using the java.net.InetAddress class to resolve IP addresses from DNS names the other day.

I wanted to test my code by manipulating my local system’s ‘hosts’ file, to quickly simulate moving IP addresses around behind a DNS name, so I also set disabled caching the resolved addresses from one call to the next by programmatically setting the networkaddress.cache.ttl Security property to ‘0’. According to the javadocs,

The value [assigned to networkaddress.cache.ttl] is specified as as integer to indicate the number of seconds to cache the successful lookup.

which is true, and everything was peachy – my hosts file changes were immediately picked up.

At first.

I continued to build my code and all of a sudden, the caching came back and the changes I was making in my hosts file were ignored.

By backtracking my changes, I worked out that the breaking change happened when I executed a network call which involved name resolution BEFORE I disabled the cache.

I moved the setting of the property to happen before I touched the network et voila – everything peachy again.

This (feature|problem|bug) is documented in a couple of places when you know what you’re looking for, like here.

And here’s a simple code demo of it in action:

public static void main(String[] args) throws Exception {
  String name = "google.com";

  //lookup(name);

  Security.setProperty("networkaddress.cache.ttl", "0");
  while (true) {
    lookup("google.com");
    Thread.sleep(1000);
  }

  public static void lookup(String name) throws Exception {
    System.out.println(name + ":" + InetAddress.getByName(name).getHostAddress());
  }
}

Running the sample above as-is:
google.com:74.125.127.100
google.com:74.125.67.100
google.com:74.125.127.100
google.com:74.125.67.100
google.com:74.125.127.100

But uncomment the first call to lookup(), and
google.com:74.125.45.100
google.com:74.125.45.100
google.com:74.125.45.100
google.com:74.125.45.100
google.com:74.125.45.100

Cheers,

E-Mail on Android with K-9 Mail

I found a new email client called K-9 Mail the other day, following a little Googling – and it’s great.

My HTC Magic came with an email client installed. It ticked all the style boxes, but over the past couple of months I’ve learned that it ticks none of the usability boxes.

It has trouble keeping synchronized with my email accounts.
There’s no easy access to next or previous emails.
There’s no one-touch delete.

Yuk.
So, I had a look around and found a couple of endorsements of K-9 Mail, and I looked it up in the Market.

Compared to the pre-installed client, it’s the mutt’s nuts – a much more pleasant experience – so if you’re struggling with email on Android, give it a whirl.

Cheers,

Feed Troubles

I’ve been having some problems with my feeds, in that the news items were getting truncated after only a few words with […]

I’ve sorted this out today, but either my upgrade or my faffing with the feeds has reset the feed on my reader, so that the posts I’d already read appeared as unread again.

Not sure why that happened, and sorrysorrysorry if it’s caused anyone any inconvenience.

Sorry!

Living with Android – Review of my HTC Magic

HTC Magic

So I bought a new phone, an HTC Magic, two or three of months ago. I think it’s fair to say that so some small degree, it’s changed my life.

Not in any kind of deep and meaningful way, of course – it’s just a phone. But definitely made a difference.

It’s an Android phone, which means it’s based on Google’s Android operating system. But I don’t want to talk about that, as there’s a whole bunch of info out there on Android and how cool/not cool it is (delete as appropriate). I wanted to share a few observations on how it’s enhanced some aspects of my life.


First up, I feel I should admit (for context) that I’ve never owned a smartphone before. I mean, come on. Window$ Mobile? What kind of self-respecting Linux user would lower themselves to having one of those? Ditto for iPhone. I only own one Apple product, and I won that in a raffle.*

And what other options were out there that didn’t cost the Earth and had some kind of serious userbase?** So I was coming to the smartphone scene from a phone that made phone calls, sent text messages and had a camera. That’s it.

So what’s the Magic done to change things for me?

First up, transparent syncing.

I’ve synced my contacts with my Google Mail account and my calendar with Google Calendar. As I was already a user of both these services, it was a pretty obvious step.

It was a bit of a pain when I first got the thing, copying all my contacts from my old phone. I couldn’t find a better way, so I just typed them over from my old phone into gmail. You need to tell your phone about your gmail account, but from there on in, your phone sees contacts you add to gmail, and gmail sees new contacts in your phone. Doesn’t sound that impressive, but I tried to get the same thing with my old Nokia phone – it cost me money and would only sync when I commanded it to be so. Sometimes, not even then. The Android sync stuff is all free, too.

Calendar works much the same way, the difference being that the only calendaring service I use is GCal anyway, so that bit was… well, it was magic.

Next, the Market.

The Market. It’s where you go to get applications. Some of those applications really suck – I’m not going to shout anything by name, but I’m loving the optimism of the author who’s trying to sell a calculator for $4.99 – I wish him/her the very best of luck!

However – there are plenty that are just plain awesome. The market has a rating and user comment system built in, which I’ve found to be a pretty good litmus test for whether an app is worth looking at. Choose your poison (in my humble opinion, as always)…

  • You want a comprehensively featured mobile reader for the Atom/RSS feeds in your Google reader? Try Newsrob.
  • For those times you just gotta tell the world what you’re having for lunch? You won’t go far wrong with Twidroid.
  • How about one of those task managers that reminds you to feed your cat? Astrid‘s pretty good.
  • Need something to drown out the voices? There’s a neat little last.fm app.
  • You want to show off to your friends? Wikitude, Google’s Sky Map, the Barcode Scanner, even the compass app have all raised sighs of appreciation, perhaps even mild envy, in my (admittedly geeky) circles.
  • Games? There’s plenty. I’m not really a mobile gaming person, but I wanted to see what it could do when I first got it, so I had a little fun with the Archipelago demo, Amageddon (Missile Attack clone), Labyrinth (one of those tilty silver ball maze things) and Robo Defence Free. I also tried the Chess app, which confirmed that yes, I still suck at Chess, only now so bad that even my phone can kick my ass. Dammit.

There’s loads more videos of Android apps in action here.

So how much did this little lot, plus the various other apps I’ve downloaded cost me? Nothing at all. Gratis. There’s plenty of paid-for apps on there but to be honest, I’ve yet to find a reason to let the moths out of my wallet.

The browser

is awesome, for a mobile device. Sure, it has some limitations. I don’t think it supports Flash yet and there’s some types of data it doesn’t recognise that it maybe should (News feeds being one), but it renders pretty much everything I’ve thrown it at, and does a pretty good job with most stuff in both portrait and landscape modes. It’s fast, too.

D. I. Y.

You can download some bits and pieces and write your own apps in Java*** for free. Which probably explains those apps that suck.

Whilst I’ve heard good things, I must admit that I haven’t done this yet myself, but one day I will find a few hours when I genuinely have nothing better to do than play with mobile development and have a go. Being able to just have a go if you feel like it is worth plus points in my book.

And finally, the keyboard.

That’s right, the touch screen keyboard thing. (I know that’s a G1 in the vid, but you get the idea.) To be fair, we’ve had a love-hate relationship, but as time goes on, I’m getting pretty good at tapping away in a reasonably error-free fashion.

The keyboard also has some neat features, like the way it switches to landscape when you turn the phone horizontally (if you have big fat fingers like me, the landscape mode with its slightly larger keys is your friend), and the way the layout changes depending on which app you happen to be in. Well, actually on this last point, although the layout clearly does change depending on the app, sometimes the app developers perhaps haven’t really thought it through.

For example, the number of times I’ve been caught out by the ‘return’ key (a. k. a. the Send My Tweet button) being present on the Twidroid app just under the ‘delete’ key (a. k. a. the Remove My Stupid Tweet button). This in spite of the fact that there’s a button to send your message just under to the text input box, safely out of the way. Add my big lumps of thumbs into the mix…

Oh, how we laughed.

Some stuff sucks.

Of course it does – everybody falls the first time.

First up – the camera. Utterly horrible, to the point of unusable in anything other than the bright outdoors. Not really surprising, the lens on the thing is about the size of a pinhead. Seems to me that it doesn’t matter how many megapixels you got if you can only get three photons at a time onto the damn sensor. And no, that’s not an excuse to ridicule me for my lack of understanding of optics, the nature of time or wave-particle duality, OK?

Next, I’ve not found an easy way to subscribe to RSS/Atom feeds in the browser. Really annoying. The browser just prints the text content of the XML document.

Finally, the battery life isn’t great – I put mine on charge every night, as I can’t get through 48 hours without completely running out of power. That said, with the WiFi, GPS and processing that’s going on, I personally think it’s no mean feat to get that much longevity out of such a tiny little rechargeable battery.

So how did it change my life?

Well, that syncing stuff gives me a tiny bit less work to do every time I want to use the stuff that’s on my phone on my computer and vice versa. Those tiny bits add up though and I’m getting very used to it very quickly.

The apps, browser and keyboard actually give me a lot of the power I have on my computer on the move. I’m finding that on rare occasions when I don’t have my phone with me (that’d be because I forgot to charge it the night before…), I miss it – I can’t use that short time when the other guy’s heading to the bar to see what’s up on twitter, read a news item or two, that kind of thing. Sad, I know, but don’t tell me you’ve never done it.

The D. I. Y. thing – OK, you got me, I just think it’s cool that you can have a go if you want to.

Would I recommend it to a friend?

Hell yes.

I’ve got plenty of friends who have iPhones, and my take on the differences is this. Sure, the iPhone’s got a few extra pinches of pixie dust that make it that little bit nicer to use (spotting phone numbers and giving you a ‘dial’ button works better, the swishy sliding photo gallery is neat and the transitions are slightly nicer)… but it also costs more – at time of writing, Carphone Warehouse says £34.95/month for 24 months, plus at least £87.11 for a 3GS.

My Vodafone HTC magic cost me £35/month for 18 months, plus zero, zilch, nada for the phone, 3 months or so ago. Oh, and my Magic is smaller than an iPhone, too. Which is nice.

I hear that Android is catching up in those pesky polish areas, too with the HTC Hero – I’m sure Mike over at walkingrandomly.com will be blogging extensively, as well as gloating at me about his new Hero – when it finally turns up.

If further evidence were needed, my other half is a little jealous of my phone and has her heart set on getting one when her contract is up. (Although I think she might have ulterior motives – to be able to put tasks on my to-do list from afar…)

The Google Connection

It’s perhaps worth noting that a lot of the stuff I’ve pointed out on here as good involves Google somehow. A lot of that involves pushing data into the Cloud – specifically Google’s. Personally, I don’t have a particular problem with that – after all, Google’s motto is Don’t Be Evil, right?

If you want to share data between your various devices, you need to put it somewhere. As far as I can tell, the phone works just fine without an internet connection, so it’s not like you’re out of luck if Google’s having technical problems… but… if pushing your personal data, your contacts, calendar info, etc. into Google’s infrastructure makes you feel uncomfortable, you might want to give it some thought. I don’t know whether there’s apps to sync with alternative sources, please feel free to drop me a comment if you’ve used any other options.

That’s all, folks!

Well, that went on a lot longer than I expected. I’ll just do a quick review. 5 minute job, I thought. If you made it this far without getting bored and moving on, thanks for sticking around!

Please do drop me a comment if you’ve found an awesome app I haven’t mentioned. Probably better if it’s not your own app… Even better if you can tell me how you subscribe to an RSS/Atom feed in the Android browser…

Cheers!

* I’m not actually fanatical about the free-as-in-speech stuff, companies are there to make money right? In all fairness, my iPod pico (or whatever it’s called) is a great little bit of kit for listening to podcasts on the move. [back to context]

** To be honest, there might have been other options out there. I wasn’t really paying a great deal of attention ’til Android came along. [back to context]

*** It’s Java source with special APIs which is what matters, but it’s actually compiled to a different bytecode for the Dalvic VM, a VM which is optimised for mobile devices. [back to D. I. Y.]

Upgrade Over

…and it looks like blog.crossedstreams.com survived!

The upgrade process described on the WordPress site is a bit manual and nervewracking, but (for me, at least) it went like a treat. And WordPress 2.8.3 sure beats 2.3.whateverIwasonbefore for look, feel and features.

Maybe now I can get that permalinks thing sorted. I also hope that the upgrade should resolve the issue where the blog is cut short in RSS feeds, but that remains to be seen.

WordPress Upgrade Time

Ok, I’ve been running on the version of WordPress that my web hosting provider provided when I signed up, which was already quite out of date at the time.

Hey, I’ve been busy!

But now, it’s time. Time to do the backups, time to upgrade to the latest version, and it’s a big jump. So if this blog is never heard from again, at least you’ll know why.

Au revoir…

Apache Axis 1.4 NoClassDefFoundError Woes

This one took me a while to figure out.

I’m a beginner with the Apache Axis web services platform on the Apache Tomcat 5.5.x container and I’m using version 1.4, so I was delighted when I found it to be so easy to get into. I used this tutorial – the second page is a step-by-step deployment for a simple service.

All was going well, even when I made updates to the classes behind the service. Redeploying the service behaved perfectly. Until… I deployed an update and everything broke.

I mean everything broke. I couldn’t even list the available services, nor view a WSDL.  Proper broken. Everything. In the Tomcat logs, all I could see was a NoClassDefFoundError (which means that the class you’re trying to use in your code isn’t available to the JVM).

Which made absolutely no sense. All the classes making up the service were clearly present. I had made a change to the internal logic of one of the classes, but nothing that introduced anything outside the classes present in any JRE.

So I reverted to the previous version and everything was fine again. Which was nice, but less than ideal.

So I went back to basics – what had I changed, as that must be the cause of the problem. In fact, I’d made a socket port number configurable… and in the process, I was trying open a connection to a port north of 65535, which would naturally cause an IllegalArgumentException to be thrown, and a large but silent explosion in my code. So I’m an idiot – I still deserve a half-decent exception. It was only a prototype anyway…

Anyway, having spotted that, I fixed the problem, redeployed and everything was peachy.

The moral of the story… if you’re getting a problem that looks like this, it might just be that your code isn’t able to start up properly – which is very much hidden by a NoClassDefFoundError.

I guess you get this kind of error because Axis relies on reflection for a lot of its magic, but I didn’t find it particularly helpful, and the zillion-call-deep stacktrace didn’t help much either. I still don’t know where the real root cause exception got squirrelled away to, if anywhere.

That said, I’m liking Axis in the main, so I’ll be persevering – as well and trying out other platforms for this brand of magic.