Search in sources :

Example 1 with ChannelResponse

use of org.apache.nifi.processor.util.listen.response.ChannelResponse 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 ChannelResponse

use of org.apache.nifi.processor.util.listen.response.ChannelResponse 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 ChannelResponse

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

the class TestRELPFrameHandler method testOpen.

@Test
public void testOpen() throws IOException, InterruptedException {
    final String offer1 = "relp_version=0";
    final String offer2 = "relp_software=librelp,1.2.7,http://librelp.adiscon.com";
    final String offer3 = "commands=syslog";
    final String data = offer1 + "\n" + offer2 + "\n" + offer3;
    final RELPFrame openFrame = new RELPFrame.Builder().txnr(1).command("open").dataLength(data.length()).data(data.getBytes(charset)).build();
    final String sender = "sender1";
    final CapturingChannelResponder responder = new CapturingChannelResponder();
    // call the handler and verify respond() was called once with once response
    frameHandler.handle(openFrame, responder, sender);
    Assert.assertEquals(1, responder.responded);
    Assert.assertEquals(1, responder.responses.size());
    // verify the response sent back the offers that were received
    final ChannelResponse response = responder.responses.get(0);
    final String responseData = new String(response.toByteArray(), charset);
    Assert.assertTrue(responseData.contains(offer1));
    Assert.assertTrue(responseData.contains(offer2));
    Assert.assertTrue(responseData.contains(offer3));
}
Also used : ChannelResponse(org.apache.nifi.processor.util.listen.response.ChannelResponse) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Example 4 with ChannelResponse

use of org.apache.nifi.processor.util.listen.response.ChannelResponse 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 5 with ChannelResponse

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

the class RELPFrameHandler method handle.

public void handle(final RELPFrame frame, final ChannelResponder<SocketChannel> responder, final String sender) throws IOException, InterruptedException {
    // respond to open and close commands immediately, create and queue an event for everything else
    if (CMD_OPEN.equals(frame.getCommand())) {
        Map<String, String> offers = RELPResponse.parseOffers(frame.getData(), charset);
        ChannelResponse response = new RELPChannelResponse(encoder, RELPResponse.open(frame.getTxnr(), offers));
        responder.addResponse(response);
        responder.respond();
    } else if (CMD_CLOSE.equals(frame.getCommand())) {
        ChannelResponse response = new RELPChannelResponse(encoder, RELPResponse.ok(frame.getTxnr()));
        responder.addResponse(response);
        responder.respond();
        dispatcher.completeConnection(key);
    } else {
        final Map<String, String> metadata = EventFactoryUtil.createMapWithSender(sender.toString());
        metadata.put(RELPMetadata.TXNR_KEY, String.valueOf(frame.getTxnr()));
        metadata.put(RELPMetadata.COMMAND_KEY, frame.getCommand());
        final E event = eventFactory.create(frame.getData(), metadata, responder);
        events.offer(event);
    }
}
Also used : 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) Map(java.util.Map)

Aggregations

ChannelResponse (org.apache.nifi.processor.util.listen.response.ChannelResponse)6 IOException (java.io.IOException)3 ChannelResponder (org.apache.nifi.processor.util.listen.response.ChannelResponder)3 RELPFrame (org.apache.nifi.processors.standard.relp.frame.RELPFrame)2 RELPChannelResponse (org.apache.nifi.processors.standard.relp.response.RELPChannelResponse)2 Test (org.junit.Test)2 Map (java.util.Map)1 BeatsChannelResponse (org.apache.nifi.processors.beats.response.BeatsChannelResponse)1 LumberjackChannelResponse (org.apache.nifi.processors.lumberjack.response.LumberjackChannelResponse)1