Archive for June, 2007

Loopy with Groovy

There’s been a lot of people asking for a Java loop syntax in groovy. A lot if not almost all usages however are cleaner without it, once you know some idiomatic groovy.

Here are just some of the examples of looping constructs available in groovy:

def results = []
10.times { results << it }
assert results == [0,1,2,3,4,5,6,7,8,9]

results = []
0.step(10, 2) { results << it }
assert results == [0,2,4,6,8]

results = []
(1..10).each { results << it }
assert results == [1,2,3,4,5,6,7,8,9,10]

results = []
(1..10).step(2) { results << it }
assert results == [1,3,5,7,9]

def items = [‘one’, ‘two’, ‘three’, ‘four’]
results = []
items.eachWithIndex { item, idx ->
      results << idx
}
assert results == [0,1,2,3]

There are a whole range of Groovy features at work here, from inline lists to ranges, GDK methods added to JDK classes such as step() on numeric types and of course closures.

  • Twitter
  • Slashdot
  • Delicious
  • Evernote
  • Share/Bookmark

07

06 2007

Tomcat deployment fun

Well we’re on the verge of deploying our first Grails 0.5.x project. The hosting company installed Tomcat for us from JPackage and my lord what a royal pain that was. They’re ripping it off the box now and putting a more regular tomcat distro on there. The JPackage one was setup to copy jars from /usr/share/java into Tomcat’s common/lib dir -every- time at startup.

That kind of think makes "NoTransportException: smtp" in JavaMail rather odd to debug when you delete the common/lib jars and – bang – they reappear later.

I don’t get this seemingly neverending JavaMail/tomcat problem anyway, I’ve seen it happening for years on different projects. I’ve never met somebody who understood this properly. I understand classloader problems, but I don’t understand why having JavaMail with SMTP in common/lib AND in an app’s WEB-INF/lib should cause it to say there is no SMTP transport. If anything it’s got TWO!

Having said all this, when we get there Grails 0.5 apps are deploying fine which is good to know. We’re also seeing some pretty sick performance on this 2x 2-core CPU HP rack. Ajax requests circa 450 per second (no db hits, just a bunch of groovy logic) using apache benchmark. GSP requests over 100 per second.

  • Twitter
  • Slashdot
  • Delicious
  • Evernote
  • Share/Bookmark

06

06 2007