use of com.ociweb.pronghorn.pipe.MessageSchemaDynamic in project PronghornPipes by oci-pronghorn.
the class TemplateProcessGeneratorLowLevelReader method appendMessageIdentifier.
private void appendMessageIdentifier(int cursor, MessageSchema schema) throws IOException {
FieldReferenceOffsetManager from = MessageSchema.from(schema);
bodyTarget.append("/*");
appendInternalMethodName(cursor);
bodyTarget.append("*/");
if (schema instanceof MessageSchemaDynamic || null == from.fieldNameScript[cursor]) {
bodyTarget.append(Integer.toString(cursor));
} else {
bodyTarget.append(schema.getClass().getSimpleName()).append(".");
bodyTarget.append(FieldReferenceOffsetManager.buildMsgConstName(from, cursor));
}
}
use of com.ociweb.pronghorn.pipe.MessageSchemaDynamic in project PronghornPipes by oci-pronghorn.
the class TemplateProcessGeneratorLowLevelWriter method footerConstruction.
@Override
protected void footerConstruction() throws IOException {
final FieldReferenceOffsetManager from = MessageSchema.from(schema);
if (!from.hasSimpleMessagesOnly) {
if (!baseText.contains("Runnable")) {
bodyTarget.append("@Override\n");
}
bodyTarget.append("public void startup() {\n");
bodyTarget.append(tab).append("navState").append(" = new ");
bodyTarget.append(LowLevelStateManager.class.getSimpleName()).append("(");
if (buildFullStageWritingToPipe()) {
bodyTarget.append(pipeClass.getSimpleName()).append(".from(").append(pipeVarName).append(")");
} else {
if (!(schema instanceof MessageSchemaDynamic)) {
bodyTarget.append(schema.getClass().getSimpleName()).append(".");
}
bodyTarget.append("FROM");
}
bodyTarget.append(");\n");
bodyTarget.append("}\n");
}
additionalMethods(bodyTarget);
bodyTarget.append("};\n");
}
use of com.ociweb.pronghorn.pipe.MessageSchemaDynamic in project PronghornPipes by oci-pronghorn.
the class StreamingConsumerTest method generatorTest.
@Test
public void generatorTest() {
final int seed = 2;
// hard coded value that comes from this seed 2
final long aLongValue = 2945688134060370505l;
// hard coded value that comes from this seed 2
final int aNegIntValue = -29;
Pipe<MessageSchemaDynamic> ring = new Pipe<MessageSchemaDynamic>(new PipeConfig<MessageSchemaDynamic>(new MessageSchemaDynamic(FROM), 50, 30));
ring.initBuffers();
StreamingWriteVisitorGenerator swvg = new StreamingWriteVisitorGenerator(FROM, new Random(seed), 30, 30);
StreamingVisitorWriter svw = new StreamingVisitorWriter(ring, swvg);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
// PrintStream ps = System.out;
StreamingReadVisitor visitor = new StreamingReadVisitorToJSON(ps);
// , new StreamingReadVisitorDebugDelegate(visitor) );
StreamingVisitorReader reader = new StreamingVisitorReader(ring, visitor);
svw.startup();
reader.startup();
do {
svw.run();
} while (!svw.isAtBreakPoint());
reader.run();
svw.shutdown();
reader.shutdown();
byte[] byteArray = baos.toByteArray();
assertTrue("No JSON was produced", byteArray.length > 0);
String results = new String(byteArray);
// spot check the produced JSON
assertTrue(results, results.indexOf("\"Trucks\":") > 0);
assertTrue(results, results.indexOf("{\"Squad\":") > 0);
assertTrue(results, results.indexOf(Long.toString(aLongValue)) > 0);
assertTrue(results, results.indexOf(Integer.toString(aNegIntValue)) > 0);
}
use of com.ociweb.pronghorn.pipe.MessageSchemaDynamic in project PronghornPipes by oci-pronghorn.
the class TemplateProcessGeneratorTest method testGenerateLowLevelWriterCleanCompile.
@Test
public void testGenerateLowLevelWriterCleanCompile() {
if ("arm".equals(System.getProperty("os.arch"))) {
assertTrue(true);
} else {
try {
FieldReferenceOffsetManager from = TemplateHandler.loadFrom("/template/smallExample.xml");
MessageSchema schema = new MessageSchemaDynamic(from);
String className = "LowLevelWriter";
StringBuilder target = new StringBuilder();
TemplateProcessGeneratorLowLevelWriter simple = new TemplateProcessGeneratorLowLevelWriter(schema, target, true, "com.ociweb.pronghorn.pipe.build");
simple.processSchema();
// System.out.println(target);
validateCleanCompile(className, target);
} catch (ParserConfigurationException e) {
e.printStackTrace();
fail();
} catch (SAXException e) {
e.printStackTrace();
fail();
} catch (IOException e) {
e.printStackTrace();
fail();
}
}
}
Aggregations