Skip to content

A Simple Bit of GPars

I recently had a rather dull task to undertake: each time a (third-party) application bug manifested itself, I had to retrieve all the relevant logs from the supporting JBoss instance so that they could be mailed to the developer.

The logs were often quite large, which argued for using parallel download, rather than grabbing each file sequentially (the good ole’ space-time tradeoff in yet another guise).

I wanted to make everything as easy as possible for the support team that would come after me. This meant no mucking around with libraries, classpaths, etc.

My first thought was “this looks like a job for GPars.”
(My second thought was probably “time for a cuppa“, but that’s not strictly relevant here…)


// avoid all the command-line classpath munging; add GPARS
def GPARS_HOME='file:///C:/BIN/Groovy/gpars-all-0.12-beta-1-SNAPSHOT/'
['jcsp-1.1-rc5.jar', 'netty-3.1.5.GA.jar', 'gpars-0.12-beta-1-SNAPSHOT.jar'].each {
  this.class.classLoader.rootLoader.addURL(new URL("${GPARS_HOME}/${it}"))

def retrieve = {file ->
  println "(${Thread.currentThread().name}); Downloading $file"
  new File(file) << "http://server/download?dir=log&file=${file}".toURL().text

groovyx.gpars.GParsPool.withPool {
  ['Main.log', 'MainError.log', 'error.log', 'Subsystem.log',
   'SubsystemError.log', 'boot.log', 'server.log'].eachParallel {
    retrieve it

It’s not rocket-science, this, but I hope it shows just how damnned easy Groovy and GPars make life…

Tags: , ,

C, Java Enterprise Edition, JEE, J2EE, JBoss, Application Server, Glassfish, JavaServer Pages, JSP, Tag Libraries, Servlets, Enterprise Java Beans, EJB, Java Messaging Service JMS, BEA Weblogic, JBoss, Application Servers, Spring Framework, Groovy, Grails, Griffon, GPars, GAnt, Spock, Gradle, Seam, Open Source, Service Oriented Architectures, SOA, Java 2 Standard Edition, J2SE, Eclipse, Intellij, Oracle Service Bus, OSB