the templates are now a fixed part of the maven plugin
the package for the generated code is a parameter to the 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 31c4855..14d8a7e 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
@@ -24,120 +24,138 @@
public class Generator {
- public enum Manager {
- RECORD,
- ARENA
+ public enum TemplateType {
+ RECORD_MANAGER,
+ ARENA_MANAGER,
+ SUPPORT
}
public static void generateSource(
- Manager mgr,
+ TemplateType tmplType,
+ String packageName,
RecordType rec,
InputStream is,
StringBuilder sb,
boolean debug) {
- switch (mgr) {
- case RECORD:
- generateMemoryManagerSource(rec, is, sb, debug);
- break;
- case ARENA:
- generateArenaManagerSource(rec, is, sb, debug);
- break;
- default:
- throw new IllegalArgumentException();
- }
+ try {
+ BufferedReader in = new BufferedReader(new InputStreamReader(is));
+
+ switch (tmplType) {
+ case RECORD_MANAGER:
+ generateMemoryManagerSource(packageName, rec, in, sb, debug);
+ break;
+ case ARENA_MANAGER:
+ generateArenaManagerSource(packageName, rec, in, sb, debug);
+ break;
+ case SUPPORT:
+ generateSupportFileSource(packageName, in, sb, debug);
+ break;
+ default:
+ throw new IllegalArgumentException();
+ }
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+
}
private static void generateMemoryManagerSource(
+ String packageName,
RecordType resource,
- InputStream is,
+ BufferedReader in,
StringBuilder sb,
- boolean debug) {
- BufferedReader in = new BufferedReader(new InputStreamReader(is));
+ boolean debug) throws IOException {
String line = null;
+ String indent = " ";
- try {
-
- String indent = " ";
-
- while((line = in.readLine()) != null) {
- 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');
- } else if (line.contains("@METHODS@")) {
- for (int i = 0; i < resource.size(); ++i) {
- final Field field = resource.fields.get(i);
- if (field.accessible) {
- field.appendMemoryManagerGetMethod(sb, indent, 1);
- sb.append('\n');
- field.appendMemoryManagerSetMethod(sb, indent, 1);
- sb.append('\n');
- }
- }
- } else if (line.contains("@INIT_SLOT@")) {
- for (int i = 0; i < resource.size(); ++i) {
- final Field field = resource.fields.get(i);
- field.appendInitializers(sb, indent, 3);
- }
- } else if (line.contains("@CHECK_SLOT@")) {
- for (int i = 0; i < resource.size(); ++i) {
- final Field field = resource.fields.get(i);
- field.appendChecks(sb, indent, 3);
- }
- } else if (line.contains("@PRINT_BUFFER@")) {
- resource.appendBufferPrinter(sb, indent, 3);
- sb.append('\n');
- } else {
- sb.append(line).append('\n');
- }
+ while((line = in.readLine()) != null) {
+ if (line.contains("@PACKAGE@")) {
+ line = line.replace("@PACKAGE@", packageName);
}
-
- } catch (IOException ioe) {
- ioe.printStackTrace();
+ 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');
+ } else if (line.contains("@METHODS@")) {
+ for (int i = 0; i < resource.size(); ++i) {
+ final Field field = resource.fields.get(i);
+ if (field.accessible) {
+ field.appendMemoryManagerGetMethod(sb, indent, 1);
+ sb.append('\n');
+ field.appendMemoryManagerSetMethod(sb, indent, 1);
+ sb.append('\n');
+ }
+ }
+ } else if (line.contains("@INIT_SLOT@")) {
+ for (int i = 0; i < resource.size(); ++i) {
+ final Field field = resource.fields.get(i);
+ field.appendInitializers(sb, indent, 3);
+ }
+ } else if (line.contains("@CHECK_SLOT@")) {
+ for (int i = 0; i < resource.size(); ++i) {
+ final Field field = resource.fields.get(i);
+ field.appendChecks(sb, indent, 3);
+ }
+ } else if (line.contains("@PRINT_BUFFER@")) {
+ resource.appendBufferPrinter(sb, indent, 3);
+ sb.append('\n');
+ } else {
+ sb.append(line).append('\n');
+ }
}
}
private static void generateArenaManagerSource(
+ String packageName,
RecordType resource,
- InputStream is,
+ BufferedReader in,
StringBuilder sb,
- boolean debug) {
- BufferedReader in = new BufferedReader(new InputStreamReader(is));
+ boolean debug) throws IOException {
String line = null;
+ String indent = " ";
- try {
-
- String indent = " ";
-
- while((line = in.readLine()) != null) {
- 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);
- if (field.accessible) {
- field.appendArenaManagerGetMethod(sb, indent, 1);
- sb.append('\n');
- field.appendArenaManagerSetMethod(sb, indent, 1);
- sb.append('\n');
- }
- }
- } else {
- sb.append(line).append('\n');
- }
+ while((line = in.readLine()) != null) {
+ if (line.contains("@PACKAGE@")) {
+ line = line.replace("@PACKAGE@", packageName);
}
+ 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);
+ if (field.accessible) {
+ field.appendArenaManagerGetMethod(sb, indent, 1);
+ sb.append('\n');
+ field.appendArenaManagerSetMethod(sb, indent, 1);
+ sb.append('\n');
+ }
+ }
+ } else {
+ sb.append(line).append('\n');
+ }
+ }
+ }
- } catch (IOException ioe) {
- ioe.printStackTrace();
+ private static void generateSupportFileSource(
+ String packageName,
+ BufferedReader in,
+ StringBuilder sb,
+ boolean debug) throws IOException {
+ String line = null;
+ while((line = in.readLine()) != null) {
+ if (line.contains("@PACKAGE@")) {
+ line = line.replace("@PACKAGE@", packageName);
+ }
+ sb.append(line).append('\n');
}
}
}
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 dc7fe19..79221c1 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
@@ -23,7 +23,6 @@
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -48,14 +47,9 @@
* parameter injected from pom.xml
*
* @parameter
+ * @required
*/
- private String arenaManagerTemplate;
- /**
- * parameter injected from pom.xml
- *
- * @parameter
- */
- private String recordManagerTemplate;
+ private String packageName;
/**
* parameter injected from pom.xml
*
@@ -64,19 +58,17 @@
*/
private File[] inputFiles;
/**
- * parameter injected from pom.xml
- *
- * @parameter
- * @required
- */
- private String outputDir;
- /**
* @parameter default-value="${project}"
* @required
* @readonly
*/
MavenProject project;
+
+ String recordManagerTemplate = "RecordManager.java";
+ String arenaManagerTemplate = "ArenaManager.java";
+ String[] supportTemplates = { "Stats.java", "AllocInfo.java", "TypeUtil.java" };
+
private Map<String, RecordType> typeMap;
public RecordManagerGeneratorMojo() {
@@ -106,8 +98,10 @@
}
public void execute() throws MojoExecutionException, MojoFailureException {
- String buildDir = project.getBuild().getDirectory();
- String outputPath = buildDir + File.separator + outputDir;
+ String outputPath = project.getBuild().getDirectory() + File.separator
+ + "generated-sources" + File.separator
+ + "java" + File.separator
+ + packageName.replace('.', File.separatorChar);
File dir = new File(outputPath);
if (!dir.exists()) {
dir.mkdirs();
@@ -116,17 +110,16 @@
readRecordTypes();
for (String recordType : typeMap.keySet()) {
- if (recordManagerTemplate != null) {
- generateSource(Generator.Manager.RECORD, recordManagerTemplate, recordType, outputPath);
- }
-
- if (arenaManagerTemplate != null) {
- generateSource(Generator.Manager.ARENA, arenaManagerTemplate, recordType, outputPath);
- }
+ generateSource(Generator.TemplateType.RECORD_MANAGER, recordManagerTemplate, recordType, outputPath);
+ generateSource(Generator.TemplateType.ARENA_MANAGER, arenaManagerTemplate, recordType, outputPath);
+ }
+
+ for (int i = 0; i < supportTemplates.length; ++i) {
+ generateSource(Generator.TemplateType.SUPPORT, supportTemplates[i], "", outputPath);
}
}
- private void generateSource(Generator.Manager mgrType, String template, String recordType, String outputPath) throws MojoFailureException {
+ private void generateSource(Generator.TemplateType mgrType, String template, String recordType, String outputPath) throws MojoFailureException {
InputStream is = getClass().getClassLoader().getResourceAsStream(template);
if (is == null) {
throw new MojoFailureException("template '" + template + "' not found in classpath");
@@ -138,7 +131,7 @@
try {
getLog().info("generating " + outputFile.toString());
- Generator.generateSource(mgrType, typeMap.get(recordType), is, sb, debug);
+ Generator.generateSource(mgrType, packageName, typeMap.get(recordType), is, sb, debug);
is.close();
FileWriter outWriter = new FileWriter(outputFile);
diff --git a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordType.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordType.java
index 3cab3bd..a0f6c61 100644
--- a/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordType.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/recordmanagergenerator/RecordType.java
@@ -29,10 +29,10 @@
public class RecordType {
enum Type {
- BYTE (1, "byte", "get", "put", "(byte)0xde", "RecordManagerTypes.Byte.append"),
- SHORT (2, "short", "getShort", "putShort", "(short)0xdead", "RecordManagerTypes.Short.append"),
- INT (4, "int", "getInt", "putInt", "0xdeadbeef", "RecordManagerTypes.Int.append"),
- GLOBAL(8, "long", "getLong", "putLong", "0xdeadbeefdeadbeefl", "RecordManagerTypes.Global.append");
+ BYTE (1, "byte", "get", "put", "(byte)0xde", "TypeUtil.Byte.append"),
+ SHORT (2, "short", "getShort", "putShort", "(short)0xdead", "TypeUtil.Short.append"),
+ INT (4, "int", "getInt", "putInt", "0xdeadbeef", "TypeUtil.Int.append"),
+ GLOBAL(8, "long", "getLong", "putLong", "0xdeadbeefdeadbeefl", "TypeUtil.Global.append");
Type(int size, String javaType, String bbGetter, String bbSetter, String deadMemInitializer, String appender) {
this.size = size;
@@ -156,9 +156,9 @@
sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n");
}
sb = indent(sb, indent, level + 1);
- sb.append("final int arenaId = RecordManagerTypes.Global.arenaId(slotNum);\n");
+ sb.append("final int arenaId = TypeUtil.Global.arenaId(slotNum);\n");
sb = indent(sb, indent, level + 1);
- sb.append("final int localId = RecordManagerTypes.Global.localId(slotNum);\n");
+ sb.append("final int localId = TypeUtil.Global.localId(slotNum);\n");
sb = indent(sb, indent, level + 1);
sb.append("return get(arenaId).")
.append(methodName("get"))
@@ -180,9 +180,9 @@
sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n");
}
sb = indent(sb, indent, level + 1);
- sb.append("final int arenaId = RecordManagerTypes.Global.arenaId(slotNum);\n");
+ sb.append("final int arenaId = TypeUtil.Global.arenaId(slotNum);\n");
sb = indent(sb, indent, level + 1);
- sb.append("final int localId = RecordManagerTypes.Global.localId(slotNum);\n");
+ sb.append("final int localId = TypeUtil.Global.localId(slotNum);\n");
sb = indent(sb, indent, level + 1);
sb.append("get(arenaId).")
.append(methodName("set"))
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/AllocInfo.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/AllocInfo.java
similarity index 91%
rename from asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/AllocInfo.java
rename to asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/AllocInfo.java
index dfba774..ef8415f 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/AllocInfo.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/AllocInfo.java
@@ -1,4 +1,4 @@
-package edu.uci.ics.asterix.transaction.management.service.locking;
+package @PACKAGE@;
import java.io.PrintWriter;
import java.io.StringWriter;
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 6d77b51..4abb3af 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
@@ -13,10 +13,7 @@
* limitations under the License.
*/
-package edu.uci.ics.asterix.transaction.management.service.locking;
-
-import edu.uci.ics.asterix.transaction.management.service.locking.AllocInfo;
-import edu.uci.ics.asterix.transaction.management.service.locking.RecordManagerTypes;
+package @PACKAGE@;
public class @E@ArenaManager {
@@ -58,20 +55,20 @@
final int allocId = TRACK_ALLOC_ID ? (++recMgr.allocCounter % 0x7fff) : 0;
final int localId = recMgr.allocate();
- long result = RecordManagerTypes.Global.build(localManager.arenaId, allocId, localId);
+ long result = TypeUtil.Global.build(localManager.arenaId, allocId, localId);
if (TRACK_ALLOC_ID) setAllocId(result, (short) allocId);
- assert RecordManagerTypes.Global.allocId(result) == allocId;
- assert RecordManagerTypes.Global.arenaId(result) == localManager.arenaId;
- assert RecordManagerTypes.Global.localId(result) == localId;
+ assert TypeUtil.Global.allocId(result) == allocId;
+ assert TypeUtil.Global.arenaId(result) == localManager.arenaId;
+ assert TypeUtil.Global.localId(result) == localId;
return result;
}
public void deallocate(long slotNum) {
if (TRACK_ALLOC_ID) checkAllocId(slotNum);
- final int arenaId = RecordManagerTypes.Global.arenaId(slotNum);
- get(arenaId).deallocate(RecordManagerTypes.Global.localId(slotNum));
+ final int arenaId = TypeUtil.Global.arenaId(slotNum);
+ get(arenaId).deallocate(TypeUtil.Global.localId(slotNum));
}
public @E@RecordManager get(int i) {
@@ -85,11 +82,11 @@
@METHODS@
private void checkAllocId(long slotNum) {
- final int refAllocId = RecordManagerTypes.Global.allocId(slotNum);
+ final int refAllocId = TypeUtil.Global.allocId(slotNum);
final short curAllocId = getAllocId(slotNum);
if (refAllocId != curAllocId) {
String msg = "reference to slot " + slotNum
- + " of arena " + RecordManagerTypes.Global.arenaId(slotNum)
+ + " of arena " + TypeUtil.Global.arenaId(slotNum)
+ " refers to version " + Integer.toHexString(refAllocId)
+ " current version is " + Integer.toHexString(curAllocId);
AllocInfo a = getAllocInfo(slotNum);
@@ -101,8 +98,8 @@
}
public AllocInfo getAllocInfo(long slotNum) {
- final int arenaId = RecordManagerTypes.Global.arenaId(slotNum);
- return get(arenaId).getAllocInfo(RecordManagerTypes.Global.localId(slotNum));
+ final int arenaId = TypeUtil.Global.arenaId(slotNum);
+ return get(arenaId).getAllocInfo(TypeUtil.Global.localId(slotNum));
}
public StringBuilder append(StringBuilder sb) {
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 6aa26f4..84a650a 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
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-package edu.uci.ics.asterix.transaction.management.service.locking;
+package @PACKAGE@;
import java.nio.ByteBuffer;
import java.util.ArrayList;
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/Stats.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/Stats.java
similarity index 87%
rename from asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/Stats.java
rename to asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/Stats.java
index ff2c92a..c136101 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/Stats.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/Stats.java
@@ -1,4 +1,4 @@
-package edu.uci.ics.asterix.transaction.management.service.locking;
+package @PACKAGE@;
public class Stats {
int arenas = 0;
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/RecordManagerTypes.java b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/TypeUtil.java
similarity index 79%
rename from asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/RecordManagerTypes.java
rename to asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/TypeUtil.java
index 27f2981..9571156 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/RecordManagerTypes.java
+++ b/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/resources/TypeUtil.java
@@ -1,6 +1,6 @@
-package edu.uci.ics.asterix.transaction.management.service.locking;
+package @PACKAGE@;
-public class RecordManagerTypes {
+public class TypeUtil {
public static class Byte {
public static StringBuilder append(StringBuilder sb, byte b) {
@@ -43,11 +43,11 @@
}
public static StringBuilder append(StringBuilder sb, long l) {
- sb.append(String.format("%1$4x", RecordManagerTypes.Global.arenaId(l)));
+ sb.append(String.format("%1$4x", TypeUtil.Global.arenaId(l)));
sb.append(':');
- sb.append(String.format("%1$4x", RecordManagerTypes.Global.allocId(l)));
+ sb.append(String.format("%1$4x", TypeUtil.Global.allocId(l)));
sb.append(':');
- sb.append(String.format("%1$8x", RecordManagerTypes.Global.localId(l)));
+ sb.append(String.format("%1$8x", TypeUtil.Global.localId(l)));
return sb;
}
diff --git a/asterix-transactions/pom.xml b/asterix-transactions/pom.xml
index bb3647e..ef06acc 100644
--- a/asterix-transactions/pom.xml
+++ b/asterix-transactions/pom.xml
@@ -39,14 +39,12 @@
<version>0.8.1-SNAPSHOT</version>
<configuration>
<debug>false</debug>
- <arenaManagerTemplate>ArenaManager.java</arenaManagerTemplate>
- <recordManagerTemplate>RecordManager.java</recordManagerTemplate>
<inputFiles>
<param>src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/Job.json</param>
<param>src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/Resource.json</param>
<param>src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/Request.json</param>
</inputFiles>
- <outputDir>generated-sources/java/edu/uci/ics/asterix/transaction/management/service/locking</outputDir>
+ <packageName>edu.uci.ics.asterix.transaction.management.service.locking</packageName>
</configuration>
<executions>
<execution>
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java
index 8a8194a..f748255 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java
@@ -693,7 +693,7 @@
sb.append(">>dump_begin\t>>----- [jobIdSlotMap] -----\n");
for(Integer i : jobIdSlotMap.keySet()) {
sb.append(i).append(" : ");
- RecordManagerTypes.Global.append(sb, jobIdSlotMap.get(i));
+ TypeUtil.Global.append(sb, jobIdSlotMap.get(i));
sb.append("\n");
}
sb.append(">>dump_end\t>>----- [jobIdSlotMap] -----\n");