Search in sources :

Example 1 with RELPChannelResponse

use of org.apache.nifi.processors.standard.relp.response.RELPChannelResponse 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 2 with RELPChannelResponse

use of org.apache.nifi.processors.standard.relp.response.RELPChannelResponse 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)2 RELPChannelResponse (org.apache.nifi.processors.standard.relp.response.RELPChannelResponse)2 IOException (java.io.IOException)1 Map (java.util.Map)1 ChannelResponder (org.apache.nifi.processor.util.listen.response.ChannelResponder)1