Search in sources :

Example 1 with ChannelResponder

use of org.apache.nifi.processor.util.listen.response.ChannelResponder in project nifi by apache.

the class ListenBeats method respond.

protected void respond(final BeatsEvent event, final BeatsResponse beatsResponse) {
    final ChannelResponse response = new BeatsChannelResponse(beatsEncoder, beatsResponse);
    final ChannelResponder responder = event.getResponder();
    responder.addResponse(response);
    try {
        responder.respond();
    } catch (IOException e) {
        getLogger().error("Error sending response for transaction {} due to {}", new Object[] { event.getSeqNumber(), e.getMessage() }, e);
    }
}
Also used : BeatsChannelResponse(org.apache.nifi.processors.beats.response.BeatsChannelResponse) ChannelResponder(org.apache.nifi.processor.util.listen.response.ChannelResponder) ChannelResponse(org.apache.nifi.processor.util.listen.response.ChannelResponse) BeatsChannelResponse(org.apache.nifi.processors.beats.response.BeatsChannelResponse) IOException(java.io.IOException)

Example 2 with ChannelResponder

use of org.apache.nifi.processor.util.listen.response.ChannelResponder in project nifi by apache.

the class ListenRELP method respond.

protected void respond(final RELPEvent event, final RELPResponse relpResponse) {
    final ChannelResponse response = new RELPChannelResponse(relpEncoder, relpResponse);
    final ChannelResponder responder = event.getResponder();
    responder.addResponse(response);
    try {
        responder.respond();
    } catch (IOException e) {
        getLogger().error("Error sending response for transaction {} due to {}", new Object[] { event.getTxnr(), e.getMessage() }, e);
    }
}
Also used : ChannelResponder(org.apache.nifi.processor.util.listen.response.ChannelResponder) RELPChannelResponse(org.apache.nifi.processors.standard.relp.response.RELPChannelResponse) ChannelResponse(org.apache.nifi.processor.util.listen.response.ChannelResponse) RELPChannelResponse(org.apache.nifi.processors.standard.relp.response.RELPChannelResponse) IOException(java.io.IOException)

Example 3 with ChannelResponder

use of org.apache.nifi.processor.util.listen.response.ChannelResponder in project nifi by apache.

the class ListenLumberjack method respond.

protected void respond(final LumberjackEvent event, final LumberjackResponse lumberjackResponse) {
    final ChannelResponse response = new LumberjackChannelResponse(lumberjackEncoder, lumberjackResponse);
    final ChannelResponder responder = event.getResponder();
    responder.addResponse(response);
    try {
        responder.respond();
    } catch (IOException e) {
        getLogger().error("Error sending response for transaction {} due to {}", new Object[] { event.getSeqNumber(), e.getMessage() }, e);
    }
}
Also used : ChannelResponder(org.apache.nifi.processor.util.listen.response.ChannelResponder) LumberjackChannelResponse(org.apache.nifi.processors.lumberjack.response.LumberjackChannelResponse) ChannelResponse(org.apache.nifi.processor.util.listen.response.ChannelResponse) LumberjackChannelResponse(org.apache.nifi.processors.lumberjack.response.LumberjackChannelResponse) IOException(java.io.IOException)

Example 4 with ChannelResponder

use of org.apache.nifi.processor.util.listen.response.ChannelResponder in project nifi by apache.

the class TestLumberjackEventFactory method testCreateLumberJackEvent.

@Test
public void testCreateLumberJackEvent() {
    final String sender = "testsender1";
    final byte[] data = "this is a test line".getBytes();
    final long seqNumber = 1;
    final String fields = "{\"file\":\"test\"}";
    final Map<String, String> metadata = new HashMap<>();
    metadata.put(EventFactory.SENDER_KEY, sender);
    metadata.put(LumberjackMetadata.SEQNUMBER_KEY, String.valueOf(seqNumber));
    metadata.put(LumberjackMetadata.FIELDS_KEY, String.valueOf(fields));
    final ChannelResponder responder = new SocketChannelResponder(null);
    final EventFactory<LumberjackEvent> factory = new LumberjackEventFactory();
    final LumberjackEvent event = factory.create(data, metadata, responder);
    Assert.assertEquals(sender, event.getSender());
    Assert.assertEquals(seqNumber, event.getSeqNumber());
    Assert.assertEquals(fields, event.getFields());
    Assert.assertEquals(data, event.getData());
}
Also used : SocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder) ChannelResponder(org.apache.nifi.processor.util.listen.response.ChannelResponder) SocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with ChannelResponder

use of org.apache.nifi.processor.util.listen.response.ChannelResponder in project nifi by apache.

the class TestRELPEventFactory method testCreateRELPEvent.

@Test
public void testCreateRELPEvent() {
    final byte[] data = "this is an event".getBytes(StandardCharsets.UTF_8);
    final String sender = "sender1";
    final long txnr = 1;
    final String command = "syslog";
    final Map<String, String> metadata = new HashMap<>();
    metadata.put(EventFactory.SENDER_KEY, sender);
    metadata.put(RELPMetadata.TXNR_KEY, String.valueOf(txnr));
    metadata.put(RELPMetadata.COMMAND_KEY, command);
    final ChannelResponder responder = new SocketChannelResponder(null);
    final EventFactory<RELPEvent> factory = new RELPEventFactory();
    final RELPEvent event = factory.create(data, metadata, responder);
    Assert.assertEquals(data, event.getData());
    Assert.assertEquals(sender, event.getSender());
    Assert.assertEquals(txnr, event.getTxnr());
    Assert.assertEquals(command, event.getCommand());
    Assert.assertEquals(responder, event.getResponder());
}
Also used : SocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder) ChannelResponder(org.apache.nifi.processor.util.listen.response.ChannelResponder) SocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ChannelResponder (org.apache.nifi.processor.util.listen.response.ChannelResponder)7 Test (org.junit.Test)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 ChannelResponse (org.apache.nifi.processor.util.listen.response.ChannelResponse)3 SocketChannelResponder (org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder)3 ArrayList (java.util.ArrayList)1 StandardEvent (org.apache.nifi.processor.util.listen.event.StandardEvent)1 BeatsChannelResponse (org.apache.nifi.processors.beats.response.BeatsChannelResponse)1 LumberjackChannelResponse (org.apache.nifi.processors.lumberjack.response.LumberjackChannelResponse)1 RELPChannelResponse (org.apache.nifi.processors.standard.relp.response.RELPChannelResponse)1