Search in sources :

Example 1 with ChannelWriter

use of com.ociweb.pronghorn.pipe.ChannelWriter in project PronghornPipes by oci-pronghorn.

the class TrieParserTest method testblobQuery.

@Test
public void testblobQuery() throws IOException {
    TrieParserReader reader = new TrieParserReader(3);
    TrieParser map = new TrieParser(16);
    map.setUTF8Value("12%b12", 33);
    // TrieParserReader reader, TrieParser trie,
    // byte[] source, int sourcePos, long sourceLength, int sourceMask,
    // final long unfoundResult) {
    long no_val = TrieParserReader.query(reader, map, "NoMatchonlong".getBytes(), 0, "No Match on long test.".length(), 15, -1);
    CharSequence test = "12abcd12";
    long val = reader.query(map, test);
    // below is testing cs.length()> reader.workingPipe.maxVarLen in Query()
    // mthod
    StringBuilder maxlengthtest = new StringBuilder();
    for (int i = 0; i < 2000; i++) {
        maxlengthtest.append(i);
    }
    long val1 = reader.query(map, maxlengthtest.toString());
    // Pipe<RawDataSchema> pipe = RawDataSchema.instance.newPipe(2, 64);
    // pipe.initBuffers();
    // 
    // int size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1);
    // DataOutputBlobWriter x =Pipe.outputStream(pipe);
    // DataOutputBlobWriter.openField(x);
    // 
    // reader.parseGather(reader, x,(byte) 'd'); // so will give 5. 5 bytes
    // until d is hit. if i put 'c' will return length of 4.
    ChannelWriter x = reader.blobQueryPrep(reader);
    x.append(test);
    long yy = reader.blobQuery(reader, map);
    x.close();
    // blobquery will return the mapping of the
    assertEquals(yy, 33);
// charsequence in the map
}
Also used : ChannelWriter(com.ociweb.pronghorn.pipe.ChannelWriter) Test(org.junit.Test)

Example 2 with ChannelWriter

use of com.ociweb.pronghorn.pipe.ChannelWriter in project GreenLightning by oci-pronghorn.

the class JSONServerBehavior method restRequest.

@Override
public boolean restRequest(HTTPRequestReader request) {
    int f = request.structured().readInt(flagsFieldId);
    request.openPayloadData(reader -> {
        jsonRequest.reset();
        jsonRequest.readFromJSON(jsonReader, reader);
    });
    System.out.println("Server: " + f + " " + jsonRequest);
    if (f == 42)
        assertEquals(42, jsonRequest.getValue());
    if (f == -6)
        assertEquals(43, jsonRequest.getValue());
    channel.publishHTTPResponse(request.getConnectionId(), request.getSequenceCode(), 200, false, HTTPContentTypeDefaults.JSON, new Writable() {

        @Override
        public void write(ChannelWriter writer) {
            // System.err.println("pre "+writer.length());
            response.writeToJSON(writer);
        // System.err.println("post "+writer.length());
        }
    });
    // runtime.shutdownRuntime();
    return true;
}
Also used : Writable(com.ociweb.gl.api.Writable) ChannelWriter(com.ociweb.pronghorn.pipe.ChannelWriter)

Example 3 with ChannelWriter

use of com.ociweb.pronghorn.pipe.ChannelWriter in project GreenLightning by oci-pronghorn.

the class MQTTApp method declareBehavior.

@Override
public void declareBehavior(final GreenRuntime runtime) {
    // optional 2 topics, optional transform lambda
    runtime.bridgeSubscription("topic/ingress", mqttConfig);
    // optional 2 topics, optional transform lambda
    runtime.bridgeTransmission("topic/egress", mqttConfig);
    final MsgCommandChannel cmdChnl = runtime.newCommandChannel(DYNAMIC_MESSAGING);
    TimeListener timeListener = new TimeListener() {

        @Override
        public void timeEvent(long time, int iteration) {
            Writable writable = new Writable() {

                @Override
                public void write(ChannelWriter writer) {
                    Date d = new Date(System.currentTimeMillis());
                    System.err.println("sent " + d);
                    writer.writeUTF8Text("egress body " + d);
                }
            };
            cmdChnl.publishTopic("topic/egress", writable);
        }
    };
    runtime.addTimePulseListener(timeListener);
    final MsgCommandChannel cmd = runtime.newCommandChannel(DYNAMIC_MESSAGING);
    PubSubListener listener = new PubSubListener() {

        @Override
        public boolean message(CharSequence topic, ChannelReader payload) {
            System.out.print("\ningress body: ");
            payload.readUTFOfLength(payload.available(), System.out);
            System.out.println();
            Writable writable = new Writable() {

                @Override
                public void write(ChannelWriter writer) {
                    writer.writeUTF("second step test message");
                }
            };
            cmd.publishTopic("localtest", writable);
            return true;
        }
    };
    runtime.addPubSubListener(listener).addSubscription("topic/ingress");
    PubSubListener localTest = new PubSubListener() {

        @Override
        public boolean message(CharSequence topic, ChannelReader payload) {
            System.out.println("got topic " + topic + " payload " + payload.readUTF());
            return true;
        }
    };
    runtime.addPubSubListener(localTest).addSubscription("localtest");
}
Also used : ChannelReader(com.ociweb.pronghorn.pipe.ChannelReader) Date(java.util.Date) ChannelWriter(com.ociweb.pronghorn.pipe.ChannelWriter)

Aggregations

ChannelWriter (com.ociweb.pronghorn.pipe.ChannelWriter)3 Writable (com.ociweb.gl.api.Writable)1 ChannelReader (com.ociweb.pronghorn.pipe.ChannelReader)1 Date (java.util.Date)1 Test (org.junit.Test)1