[ 
https://issues.apache.org/jira/browse/NIFI-274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14977668#comment-14977668
 ] 

Tony Kurc commented on NIFI-274:
--------------------------------

[~bende] - quick example of what you may be able to do with DatagramChannel 
without the polling. I can throw some changes into a patch if you'd like.

{code:java}
...

            datagramChannel.socket().bind(new InetSocketAddress(port));
            selector = Selector.open();
            datagramChannel.register(selector, SelectionKey.OP_READ);
        }

        @Override
        public void run() {
            final ByteBuffer buffer = bufferPool.poll();
            try{
                while (!stopped) {
                    try {
                        int selected = selector.select();
                        if (selected > 0){
                            Iterator<SelectionKey> selectorKeys = 
selector.selectedKeys().iterator();
                            while(selectorKeys.hasNext()){
                                SelectionKey key = selectorKeys.next();
                                selectorKeys.remove();
                                if(key.isValid()){
                                    DatagramChannel channel = (DatagramChannel) 
key.channel();
                                    final SocketAddress sender = 
channel.receive(buffer);
                                    if (sender == null) {
                                        continue;
                                    }
                                    final SyslogEvent event = 
syslogParser.parseEvent(buffer);
                                    logger.trace(event.getFullMessage());
                                    syslogEvents.put(event); // block until 
space is available
                                }
                            }
                        }
                    } catch (InterruptedException e) {
                        stopped = true;
                    } catch (IOException e) {
                        logger.error("Error reading from DatagramChannel", e);
                    }
                }
            }
            finally{
                if (buffer != null) {
                    bufferPool.returnBuffer(buffer, 0);
                }
            }
        }

...


        @Override
        public void stop() {
            selector.wakeup();
            stopped = true;
        }
{code}

> Syslog processors
> -----------------
>
>                 Key: NIFI-274
>                 URL: https://issues.apache.org/jira/browse/NIFI-274
>             Project: Apache NiFi
>          Issue Type: New Feature
>          Components: Extensions
>    Affects Versions: 0.1.0
>         Environment: any
>            Reporter: Corey Flowers
>            Assignee: Tony Kurc
>            Priority: Minor
>              Labels: features, syslog
>             Fix For: 0.4.0
>
>         Attachments: NIFI-274-2.patch, NIFI-274-3.patch, NIFI-274-4.patch, 
> NIFI-274.patch, SyslogProcessorTesting.xml
>
>
> request to add syslog processors for direct interaction with syslog to 
> include pulls and pushes of log info.  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to