Apache Commons reflectionHashCode builders

This was my response to this short post about using reflectionHashCode to implement your objects hashCode method dzone.com – overriding equals() and hashcode() ā€“ best practice

I’ve come to love the Apache commons builders over the last couple of years and use them where possible.  They avoid a lot of boilerplate.

Wanted to raise something with regard to the hashcode builder.  Today I watched a webinar, ‘Hash hash, away it goes’ (http://www.javaspecialists.eu/webinars/ and also described in text here: http://www.javaspecialists.eu/archive/Issue031.html) which was about writing hash code methods on your objects and using them as key objects in your HashMaps – and what happens when they arent written properly causing elements to not be retrieved from the map! 

One of the summary points of this article was that hashCode methods should be as fast as possible and one of the participants asked about the apache commons reflection hashcode builder.  Because the reflectionHashCode uses reflection it wont be the fastest possible implementation possible that you can write, so if you are concerned about performance, then you should consider using the other non-static implementation of HashCodeBuilder (granted not so dynamic).  The javadoc for HashCodeBuilder (http://commons.apache.org/lang/api/org/apache/commons/lang/builder/HashCodeBuilder.html) mentions reflection is slower than testing explicitly.

One thing you could do is if using dynamic fields though (say in a language like Groovy that allows fields added at runtime) is consider the fields which are immutable identity fields and have your hashcode builder just combine the hashcodes for those.  Presumably (and its a big presumption), your fields that are being added dynamically arent immutable and arent defining the identity of the object.  So the question is, do you really need to add those fields to your hashcode method in the first place?  You could then just define a hashcode builder on the immutable id fields that are in the base class and it shouldnt change how your HashSets and Maps behave regardless of dynamic fields added.  But if your new fields are added from subclasses to a parent domain, there is the appendSuper method on the HashCode builder

Over-reactor

This is Ezekial Oxā€™s new band.  Iā€™ve gotta admit to exercising some caution before jumping into following a new band he fronts given that Mammal and Full Scale both imploded or explodedā€¦ but like a partner in a bad relationship, still want to give this a shot, and any gig with Ezekial Ox is fricken great, as much as Iā€™d want to pretend thats not the case, it just is.

So Over-reactor is the new band site.  It contains a whole bunch of demos.  The first track off their demos, ā€œBest of Worstā€ has a killer intro, a sort of stoner rock/QUOTSA feel.  Speaking of which, the whole Over-Reactor does have that ā€˜Mondo Generatorā€™ feel to it, down to the name, and the sound.  Iā€™ve only heard 3 tracks so far though and their is the demo monkier to consider, but it was more than what I was expecting, and it is a big enough of a departure from the Full Scale / Mammal stuff to be refreshing enough.  Watch that space.

An introduction to jQuery

Everybody loves jQuery ā€“ well except for me, I wasn’t much of a web person myself until recently ā€“ but recent teaching in Grails have shown how jQuery can up the ante on interactive elements in your webapps.  Its been around for a while now and I admit Iā€™ve been late to the party here, but heres a great resource I found recently to get up to speed: http://www.ryanjeffords.com/blog/entry/jquery-a-crash-course-for-beginners-part-1-an-introduction-to-jquery

Groovy for Java Devs

http://live.eclipse.org/node/888

This presentation talks about Groovy in general and goes thru the general Groovy constructs.  It also talks about the Groovy plugin for STS / Eclipse (though Iā€™ll keep my IntelliJ thanks).  But its a great intro for anyone who wants a refresher of Groovy and also touches on the common frameworks (eg Grails) at the very end.

CouchDB

Much like Neo4J I blogged about recently, there is also CouchDB from Apache.  CouchDB is a document database which isnā€™t a graph database like Neo4J, but what that exactly means Iā€™m not sure yet ā€“ the purpose seem to overlap a fair bit. Both are aimed at the goal of no need to map objects to a relational schema and both claim to support the direct mapping of OO code to a DB entity.  Additionally both have REST apiā€™s.

At this early stage, I will probably say that the Graph DB (Neo4J) provides data about the relationships between nodes, whereas the document DB (CouchDB) is a collection of documents with an ID and named fields ā€“ ok that is not much different from Neo4J other than the associativity type, direction and properties arenā€™t specified and each record must have a unique ID in CouchDB)

Unlike Neo4J, CouchDB is licensed under Apache License V2 so uptake will probably be easier for a non-open source project to consider.

More info for CouchDB is available in their Intro and Overview pages on their site. 

There was a recent BerlinBuzzwords conference which got mentions for interesting CouchDB and Neo4J talks.  Many twitter peers who attended tweeted to the fact that the presentations were interesting though they arent yet up.  The intent is that slides and vids should be up shortly for these.  It also inspired the InfoQ article that suggested that Couch could be used as a Personal Database, something that SQLite prevoiusly gets top honours for.

If this is true, then CouchDB sounds like a suitable small database for development uses that can scale up quite easily to other types.  The most important thing for me right now is that there is a Grails plugin to allow me to try it out. šŸ™‚

Hyperic HQU Monitoring

As a software dev who worked with an ISP, I learnt monitoring is a big thing.  Customers have availability metrics we need to meet, and more importantly customers are paying for a service.  When it goes down, they shouldnt have to be the ones to call it up to let you know, and they should also find out about an outage as early as possible.  Well before their bosses come knocking on their door.  And regardless of size, monitoring is still a big deal for any sized company and support team, and glad to say of interest at the company I work for now.

In the last 12 months Iā€™ve been getting to know the Hyperic Monitoring Platform.  It has an open source community edition with an automatic free barrier to let small teams monitor what is important.  Additionally it is easily configurable via a web UI, which allows non-technical staff to add monitoring, setup alerts and that sort of thing.  Most importantly it is configurable via an api (or two).  There is the HQ API which is a REST api, and the Groovy API. 

I havenā€™t need to venture into the API at all to date but did recently get asked the question if HQ was able to export views and reports.  The good news after watching this vid is that you can.

The interview with Jon Travis reveals that the API is not only capable of exporting its information, but it also allows developers to add screens into their HQ installs. 

Go back to REST

I like REST.  It seemed to gel with me more than SOAP did.  I think the overall simplicity of it, reduced the barrier to entry.  Whilst I love well defined schemas and protocols, SOAP got some of my most respected and senior colleagues bewildered and frustrated, realising that the real SOAPy world that promised vendor neutral interoperability between OS and even XML framework level didnt materialise.  Too many times at my previous employer, we were stuck between a rock and a hard place when one supplier wanted to use one form of XML serialisation, but we already had another framework in our classpath do deal with another suppliers (competing supplier funnily enough) that clashed.

So if you want to spread the word of REST, these resources seem to be ok:

Addressing Doubts about REST from InfoQ Explores: REST

Stefan Tilkov Talks REST, Web Services and More

Edit: Good news, the Jersey JAX-RS (rest api for Java) implementation v1.2 was released recently.  Jersey 1.2 User Guide