use of org.apache.nifi.processors.windows.event.log.jna.EventSubscribeXmlRenderingCallback in project nifi by apache.
the class ConsumeWindowsEventLog method subscribe.
/**
* Register subscriber via native call
*
* @param context the process context
*/
private String subscribe(ProcessContext context) throws URISyntaxException {
String channel = context.getProperty(CHANNEL).getValue();
String query = context.getProperty(QUERY).getValue();
renderedXMLs = new LinkedBlockingQueue<>(context.getProperty(MAX_EVENT_QUEUE_SIZE).asInteger());
provenanceUri = new URI("winlog", name, "/" + channel, query, null).toASCIIString();
evtSubscribeCallback = new EventSubscribeXmlRenderingCallback(getLogger(), s -> {
try {
renderedXMLs.put(s);
} catch (InterruptedException e) {
throw new IllegalStateException("Got interrupted while waiting to add to queue.", e);
}
}, context.getProperty(MAX_BUFFER_SIZE).asInteger(), wEvtApi, kernel32, errorLookup);
subscriptionHandle = wEvtApi.EvtSubscribe(null, null, channel, query, null, null, evtSubscribeCallback, WEvtApi.EvtSubscribeFlags.SUBSCRIBE_TO_FUTURE | WEvtApi.EvtSubscribeFlags.EVT_SUBSCRIBE_STRICT);
if (!isSubscribed()) {
return UNABLE_TO_SUBSCRIBE + errorLookup.getLastError();
}
return null;
}
use of org.apache.nifi.processors.windows.event.log.jna.EventSubscribeXmlRenderingCallback in project nifi by apache.
the class ConsumeWindowsEventLogTest method testProcessesBlockedEvents.
@Test(timeout = 10 * 1000)
public void testProcessesBlockedEvents() throws UnsupportedEncodingException {
testRunner.setProperty(ConsumeWindowsEventLog.MAX_EVENT_QUEUE_SIZE, "1");
testRunner.run(1, false, true);
EventSubscribeXmlRenderingCallback renderingCallback = getRenderingCallback();
List<String> eventXmls = Arrays.asList("one", "two", "three", "four", "five", "six");
List<WinNT.HANDLE> eventHandles = mockEventHandles(wEvtApi, kernel32, eventXmls);
AtomicBoolean done = new AtomicBoolean(false);
new Thread(() -> {
for (WinNT.HANDLE eventHandle : eventHandles) {
renderingCallback.onEvent(WEvtApi.EvtSubscribeNotifyAction.DELIVER, null, eventHandle);
}
done.set(true);
}).start();
// Wait until the thread has really started
while (testRunner.getFlowFilesForRelationship(ConsumeWindowsEventLog.REL_SUCCESS).size() == 0) {
testRunner.run(1, false, false);
}
// Process rest of events
while (!done.get()) {
testRunner.run(1, false, false);
}
testRunner.run(1, true, false);
List<MockFlowFile> flowFilesForRelationship = testRunner.getFlowFilesForRelationship(ConsumeWindowsEventLog.REL_SUCCESS);
assertEquals(eventXmls.size(), flowFilesForRelationship.size());
for (int i = 0; i < eventXmls.size(); i++) {
flowFilesForRelationship.get(i).assertContentEquals(eventXmls.get(i));
}
}
use of org.apache.nifi.processors.windows.event.log.jna.EventSubscribeXmlRenderingCallback in project nifi by apache.
the class ConsumeWindowsEventLogTest method testScheduleErrorThenTriggerSubscribe.
@Test
public void testScheduleErrorThenTriggerSubscribe() throws InvocationTargetException, IllegalAccessException {
evtSubscribe = new ConsumeWindowsEventLog(wEvtApi, kernel32);
when(subscriptionHandle.getPointer()).thenReturn(subscriptionPointer);
when(wEvtApi.EvtSubscribe(isNull(WinNT.HANDLE.class), isNull(WinNT.HANDLE.class), eq(ConsumeWindowsEventLog.DEFAULT_CHANNEL), eq(ConsumeWindowsEventLog.DEFAULT_XPATH), isNull(WinNT.HANDLE.class), isNull(WinDef.PVOID.class), isA(EventSubscribeXmlRenderingCallback.class), eq(WEvtApi.EvtSubscribeFlags.SUBSCRIBE_TO_FUTURE | WEvtApi.EvtSubscribeFlags.EVT_SUBSCRIBE_STRICT))).thenReturn(null).thenReturn(subscriptionHandle);
testRunner = TestRunners.newTestRunner(evtSubscribe);
testRunner.run(1, false, true);
WinNT.HANDLE handle = mockEventHandles(wEvtApi, kernel32, Arrays.asList("test")).get(0);
List<EventSubscribeXmlRenderingCallback> renderingCallbacks = getRenderingCallbacks(2);
EventSubscribeXmlRenderingCallback subscribeRenderingCallback = renderingCallbacks.get(0);
EventSubscribeXmlRenderingCallback renderingCallback = renderingCallbacks.get(1);
renderingCallback.onEvent(WEvtApi.EvtSubscribeNotifyAction.DELIVER, null, handle);
testRunner.run(1, true, false);
assertNotEquals(subscribeRenderingCallback, renderingCallback);
verify(wEvtApi).EvtClose(subscriptionHandle);
}
Aggregations