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

ASF GitHub Bot commented on NIFI-1976:
--------------------------------------

Github user JPercivall commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/525#discussion_r67525744
  
    --- Diff: 
nifi-nar-bundles/nifi-windows-event-log-bundle/nifi-windows-event-log-processors/src/main/java/org/apache/nifi/processors/windows/event/log/jna/EventSubscribeXmlRenderingCallback.java
 ---
    @@ -0,0 +1,100 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.nifi.processors.windows.event.log.jna;
    +
    +import com.google.common.annotations.VisibleForTesting;
    +import com.sun.jna.Memory;
    +import com.sun.jna.platform.win32.Kernel32;
    +import com.sun.jna.platform.win32.W32Errors;
    +import com.sun.jna.platform.win32.WinDef;
    +import com.sun.jna.platform.win32.WinNT;
    +import org.apache.commons.io.Charsets;
    +import org.apache.nifi.logging.ComponentLog;
    +
    +import java.util.function.Consumer;
    +
    +/**
    + * Callback that will render the XML representation of the event using 
native Windows API
    + */
    +public class EventSubscribeXmlRenderingCallback implements 
WEvtApi.EVT_SUBSCRIBE_CALLBACK {
    +    public static final String RECEIVED_THE_FOLLOWING_WIN32_ERROR = 
"Received the following Win32 error: ";
    +    public static final int INITIAL_BUFFER_SIZE = 1024;
    +
    +    private final ComponentLog logger;
    +    private final Consumer<String> consumer;
    +    private final int maxBufferSize;
    +    private final WEvtApi wEvtApi;
    +    private final Kernel32 kernel32;
    +
    +    private int size;
    +    private Memory buffer;
    +    private Memory used;
    +    private Memory propertyCount;
    +
    +    public EventSubscribeXmlRenderingCallback(ComponentLog logger, 
Consumer<String> consumer, int maxBufferSize, WEvtApi wEvtApi, Kernel32 
kernel32) {
    +        this.logger = logger;
    +        this.consumer = consumer;
    +        this.maxBufferSize = maxBufferSize;
    +        this.wEvtApi = wEvtApi;
    +        this.kernel32 = kernel32;
    +        this.size = Math.min(maxBufferSize, INITIAL_BUFFER_SIZE);
    +        this.buffer = new Memory(size);
    +        this.used = new Memory(4);
    +        this.propertyCount = new Memory(4);
    +    }
    +
    +    @Override
    +    public synchronized int onEvent(int evtSubscribeNotifyAction, 
WinDef.PVOID userContext, WinNT.HANDLE eventHandle) {
    --- End diff --
    
    Whelp can't really do anything about bad api's. At the very least a comment 
should be added explaining it for future maintainers 


> JNA-Based Event Log Subscription Processor
> ------------------------------------------
>
>                 Key: NIFI-1976
>                 URL: https://issues.apache.org/jira/browse/NIFI-1976
>             Project: Apache NiFi
>          Issue Type: Sub-task
>            Reporter: Bryan Rosander
>
> Using JNA, we should be able to leverage existing Windows APIs to natively 
> consume events as they happen.  Will look into subscribing to events 
> (https://msdn.microsoft.com/en-us/library/windows/desktop/aa385771(v=vs.85).aspx)
>  in order to reduce latency.



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

Reply via email to