pull AllocInfo out of RecordManager template
enable debugging support in the generated code in the POM
better error handling in the maven plugin
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/Generator.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/Generator.java
index 1973584..3925e02 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/Generator.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/Generator.java
@@ -93,6 +93,9 @@
                 if (line.contains("@E@")) {
                     line = line.replace("@E@", resource.name);
                 }
+                if (line.contains("@DEBUG@")) {
+                    line = line.replace("@DEBUG@", Boolean.toString(debug));
+                }
                 if (line.contains("@CONSTS@")) {
                     resource.appendConstants(sb, indent, 1);
                     sb.append('\n');
@@ -143,6 +146,9 @@
                 if (line.contains("@E@")) {
                     line = line.replace("@E@", resource.name);
                 }
+                if (line.contains("@DEBUG@")) {
+                    line = line.replace("@DEBUG@", Boolean.toString(debug));
+                }
                 if (line.contains("@METHODS@")) {
                     for (int i = 0; i < resource.size(); ++i) {
                         final Field field = resource.fields.get(i);
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java
index 8a7965a..577d871 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java
@@ -17,13 +17,13 @@
 
 import java.io.File;
 import java.io.FileWriter;
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 
 /**
  * @goal generate-record-manager
@@ -32,7 +32,12 @@
  */
 public class RecordManagerGeneratorMojo extends AbstractMojo {
     
-    private static final boolean DEBUG = true;
+    /**
+     * parameter injected from pom.xml
+     * 
+     * @parameter
+     */
+    private boolean debug;
     /**
      * parameter injected from pom.xml
      * 
@@ -62,7 +67,14 @@
 
     private Map<String, RecordType> typeMap;
 
-    public RecordManagerGeneratorMojo() {
+    public RecordManagerGeneratorMojo() {        
+    }
+
+    private void defineRecordTypes() {
+        if (debug) {
+            getLog().info("generating debug code");
+        }
+
         typeMap = new HashMap<String, RecordType>();
 
         RecordType resource = new RecordType("Resource");
@@ -73,7 +85,7 @@
         resource.addField("max mode", RecordType.Type.INT, "LockMode.NL");
         resource.addField("dataset id", RecordType.Type.INT, null);
         resource.addField("pk hash val", RecordType.Type.INT, null);
-        if (DEBUG) resource.addField("alloc id", RecordType.Type.SHORT, null, true);
+        resource.addField("alloc id", RecordType.Type.SHORT, null, true);
 
         typeMap.put(resource.name, resource);
 
@@ -84,7 +96,7 @@
         request.addField("next job request", RecordType.Type.GLOBAL, null);
         request.addField("next request", RecordType.Type.GLOBAL, null);
         request.addField("lock mode", RecordType.Type.INT, null);
-        if (DEBUG) request.addField("alloc id", RecordType.Type.SHORT, null, true);
+        request.addField("alloc id", RecordType.Type.SHORT, null, true);
 
         typeMap.put(request.name, request);
 
@@ -93,16 +105,18 @@
         job.addField("last waiter", RecordType.Type.GLOBAL, "-1");
         job.addField("last upgrader", RecordType.Type.GLOBAL, "-1");
         job.addField("job id", RecordType.Type.INT, null);
-        if (DEBUG) job.addField("alloc id", RecordType.Type.SHORT, null, true);
+        job.addField("alloc id", RecordType.Type.SHORT, null, true);
 
         typeMap.put(job.name, job);
     }
 
-    public void execute() throws MojoExecutionException {
+    public void execute() throws MojoExecutionException, MojoFailureException {
         if (!outputDir.exists()) {
             outputDir.mkdirs();
         }
 
+        defineRecordTypes();
+
         for (int i = 0; i < recordTypes.length; ++i) {
             final String recordType = recordTypes[i];
 
@@ -116,26 +130,27 @@
         }
     }
 
-    private void generateSource(Generator.Manager mgrType, String template, String recordType) {
+    private void generateSource(Generator.Manager mgrType, String template, String recordType) throws MojoFailureException {
+        InputStream is = getClass().getClassLoader().getResourceAsStream(template);
+        if (is == null) {
+            throw new MojoFailureException("template '" + template + "' not found in classpath");
+        }
+
+        StringBuilder sb = new StringBuilder();
+        File outputFile = new File(outputDir, recordType + template);
+
         try {
-            InputStream is = getClass().getClassLoader().getResourceAsStream(template);
-            if (is == null) {
-                throw new IllegalStateException();
-            }
-
-            StringBuilder sb = new StringBuilder();
-            Generator.generateSource(mgrType, typeMap.get(recordType), is, sb, DEBUG);
-
-            is.close();
-
-            File outputFile = new File(outputDir, recordType + template);
             getLog().info("generating " + outputFile.toString());
 
+            Generator.generateSource(mgrType, typeMap.get(recordType), is, sb, debug);
+            is.close();
+
             FileWriter outWriter = new FileWriter(outputFile);
             outWriter.write(sb.toString());
             outWriter.close();
-        } catch (IOException ioe) {
-            ioe.printStackTrace();
+        } catch (Exception ex) {
+            getLog().error(ex);
+            throw new MojoFailureException("failed to generate " + outputFile.toString());
         }
     }
 }
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/ArenaManager.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/ArenaManager.java
index 9a6492c..e7d5590 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/ArenaManager.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/ArenaManager.java
@@ -17,11 +17,11 @@
 
 import java.util.ArrayList;
 
-import edu.uci.ics.asterix.transaction.management.service.locking.@E@RecordManager.Buffer.Alloc;
+import edu.uci.ics.asterix.transaction.management.service.locking.AllocInfo;
 
 public class @E@ArenaManager {
     
-    public static final boolean TRACK_ALLOC = true;
+    public static final boolean TRACK_ALLOC = @DEBUG@;
 
     private final int noArenas;
     private ArrayList<@E@RecordManager> arenas;
@@ -103,12 +103,11 @@
         final int refAllocId = allocId(slotNum);
         final short curAllocId = getAllocId(slotNum);
         if (refAllocId != curAllocId) {
-            System.err.println("checkSlot(" + slotNum + "): " + refAllocId);
             String msg = "reference to slot " + slotNum
                 + " of arena " + arenaId(slotNum) + " refers to version " 
                 + Integer.toHexString(refAllocId) + " current version is "
                 + Integer.toHexString(curAllocId);
-            Alloc a = getAlloc(slotNum);
+            AllocInfo a = getAllocInfo(slotNum);
             if (a != null) {
                 msg += "\n" + a.toString();
             }
@@ -116,9 +115,9 @@
         }
     }
     
-    public Alloc getAlloc(long slotNum) {
+    public AllocInfo getAllocInfo(long slotNum) {
         final int arenaId = arenaId(slotNum);
-        return get(arenaId).getAlloc(localId(slotNum));
+        return get(arenaId).getAllocInfo(localId(slotNum));
     }
     
     static class LocalManager {
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/RecordManager.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/RecordManager.java
index 7fa3ed7..54a9844 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/RecordManager.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/RecordManager.java
@@ -20,13 +20,13 @@
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 
-import edu.uci.ics.asterix.transaction.management.service.locking.@E@RecordManager.Buffer.Alloc;
+import edu.uci.ics.asterix.transaction.management.service.locking.AllocInfo;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionManagementConstants.LockManagerConstants.LockMode;
 
 public class @E@RecordManager {
 
     public static final int SHRINK_TIMER_THRESHOLD = 120000; //2min
-    public static final boolean TRACK_ALLOC = false;
+    public static final boolean TRACK_ALLOC = @DEBUG@;
     
     static final int NO_SLOTS = 10;
     static final int NEXT_FREE_SLOT_OFFSET = 0;
@@ -166,7 +166,7 @@
 
     @METHODS@
     
-    public Alloc getAlloc(int slotNum) {
+    public AllocInfo getAllocInfo(int slotNum) {
         final Buffer buf = buffers.get(slotNum / NO_SLOTS);
         if (buf.allocList == null) {
             return null;
@@ -199,7 +199,7 @@
         private int freeSlotNum;
         private int occupiedSlots = -1; //-1 represents 'deinitialized' state.
         
-        ArrayList<Alloc> allocList;
+        ArrayList<AllocInfo> allocList;
         
         Buffer() {
             initialize();
@@ -216,9 +216,9 @@
             setNextFreeSlot(NO_SLOTS - 1, -1); //-1 represents EOL(end of link)
             
             if (TRACK_ALLOC) {
-                allocList = new ArrayList<Alloc>(NO_SLOTS);
+                allocList = new ArrayList<AllocInfo>(NO_SLOTS);
                 for (int i = 0; i < NO_SLOTS; ++i) {
-                    allocList.add(new Alloc());
+                    allocList.add(new AllocInfo());
                 }
             }
         }
@@ -288,37 +288,6 @@
             final int itemOffset = (slotNum % NO_SLOTS) * ITEM_SIZE;
             // @CHECK_SLOT@
         }
-        
-        static class Alloc {
-            String alloc;
-            String free;
-            
-            void alloc() {
-                alloc = getStackTrace();
-            }
-            
-            void free() {
-                free = getStackTrace();
-            }
-
-            private String getStackTrace() {
-                StringWriter sw = new StringWriter();
-                PrintWriter pw = new PrintWriter(sw);
-                new Exception().printStackTrace(pw);
-                pw.close();
-                String res = sw.toString();
-                // remove first 3 lines
-                int nlPos = 0;
-                for (int i = 0; i < 3; ++i) {
-                    nlPos = res.indexOf('\n', nlPos) + 1; 
-                }
-                return res.substring(nlPos);
-            }
-            
-            public String toString() {
-                return "allocation stack:\n" + alloc + "\nfree stack\n" + free;
-            }
-        }
     }
     
 }
diff --git a/asterix-transactions/pom.xml b/asterix-transactions/pom.xml
index 8b2eb06..13a01a6 100644
--- a/asterix-transactions/pom.xml
+++ b/asterix-transactions/pom.xml
@@ -38,6 +38,7 @@
                 <artifactId>record-manager-generator-maven-plugin</artifactId>
                 <version>0.8.1-SNAPSHOT</version>
                 <configuration>
+                    <debug>false</debug>
                     <arenaManagerTemplate>ArenaManager.java</arenaManagerTemplate>
                     <recordManagerTemplate>RecordManager.java</recordManagerTemplate>
                     <recordTypes>
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/AllocInfo.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/AllocInfo.java
new file mode 100644
index 0000000..dfba774
--- /dev/null
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/AllocInfo.java
@@ -0,0 +1,35 @@
+package edu.uci.ics.asterix.transaction.management.service.locking;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+public class AllocInfo {
+    String alloc;
+    String free;
+    
+    void alloc() {
+        alloc = getStackTrace();
+    }
+    
+    void free() {
+        free = getStackTrace();
+    }
+
+    private String getStackTrace() {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        new Exception().printStackTrace(pw);
+        pw.close();
+        String res = sw.toString();
+        // remove first 3 lines
+        int nlPos = 0;
+        for (int i = 0; i < 3; ++i) {
+            nlPos = res.indexOf('\n', nlPos) + 1; 
+        }
+        return res.substring(nlPos);
+    }
+    
+    public String toString() {
+        return "allocation stack:\n" + alloc + "\nfree stack\n" + free;
+    }
+}