Search in sources :

Example 6 with MessageSchemaDynamic

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));
    }
}
Also used : MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) FieldReferenceOffsetManager(com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager)

Example 7 with MessageSchemaDynamic

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");
}
Also used : MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) FieldReferenceOffsetManager(com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager)

Example 8 with MessageSchemaDynamic

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);
}
Also used : PrintStream(java.io.PrintStream) StreamingWriteVisitorGenerator(com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator) StreamingVisitorWriter(com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter) Pipe(com.ociweb.pronghorn.pipe.Pipe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamingReadVisitorToJSON(com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON) Random(java.util.Random) StreamingReadVisitor(com.ociweb.pronghorn.pipe.stream.StreamingReadVisitor) StreamingVisitorReader(com.ociweb.pronghorn.pipe.stream.StreamingVisitorReader) MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) Test(org.junit.Test)

Example 9 with MessageSchemaDynamic

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();
        }
    }
}
Also used : MessageSchema(com.ociweb.pronghorn.pipe.MessageSchema) TemplateProcessGeneratorLowLevelWriter(com.ociweb.pronghorn.pipe.util.build.TemplateProcessGeneratorLowLevelWriter) MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) FieldReferenceOffsetManager(com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Aggregations

MessageSchemaDynamic (com.ociweb.pronghorn.pipe.MessageSchemaDynamic)9 Test (org.junit.Test)7 FieldReferenceOffsetManager (com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager)5 Pipe (com.ociweb.pronghorn.pipe.Pipe)5 StreamingVisitorReader (com.ociweb.pronghorn.pipe.stream.StreamingVisitorReader)4 StreamingVisitorWriter (com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter)3 StreamingWriteVisitorGenerator (com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator)3 Random (java.util.Random)3 MessageSchema (com.ociweb.pronghorn.pipe.MessageSchema)2 StreamingReadVisitor (com.ociweb.pronghorn.pipe.stream.StreamingReadVisitor)2 StreamingReadVisitorMatcher (com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorMatcher)2 StreamingReadVisitorToJSON (com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 PipeConfig (com.ociweb.pronghorn.pipe.PipeConfig)1 TemplateProcessGeneratorLowLevelReader (com.ociweb.pronghorn.pipe.util.build.TemplateProcessGeneratorLowLevelReader)1 TemplateProcessGeneratorLowLevelWriter (com.ociweb.pronghorn.pipe.util.build.TemplateProcessGeneratorLowLevelWriter)1