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);
}
}
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);
}
}
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));
}
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);
}
}
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);
}
}
Aggregations