Github user tflobbe commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/342#discussion_r176834024
--- Diff:
solr/core/src/java/org/apache/solr/security/AuditLoggerPlugin.java ---
@@ -0,0 +1,135 @@
+/*
+ * 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.solr.security;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.lang.invoke.MethodHandles;
+import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.SolrjNamedThreadFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Base class for Audit logger plugins
+ */
+public abstract class AuditLoggerPlugin implements Closeable, Runnable {
+ private static final Logger log =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ private static final String PARAM_BLOCKASYNC = "blockAsync";
+ private static final String PARAM_QUEUE_SIZE = "queueSize";
+ protected AuditEventFormatter formatter;
+ private BlockingQueue<AuditEvent> queue;
+ private boolean blockAsync;
+ private int blockingQueueSize;
+
+ /**
+ * Audits an event. The event should be a {@link AuditEvent} to be able
to pull context info.
+ * @param event
+ */
+ public final void auditAsync(AuditEvent event) {
+ if (blockAsync) {
+ try {
+ queue.put(event);
+ } catch (InterruptedException e) {
+ log.warn("Interrupted while waiting to insert AuditEvent into
blocking queue");
--- End diff --
I don't know about a JVM shutdown, but things like `Executor.shutdownNow()`
will interrupt all its threads and I'd think Jetty would do the same on a
graceful shutdown. The thing is that, whoever throws the `InterruptedException`
will likely clear the interrupted status, so if you catch the exception you
probably want to set it back (unless you know exactly what the thread is doing,
and you know you are exiting it right now). Since you don't know for sure who
is calling `auditAsync`, then you should either bubble up the
InterruptedException, or at least re-set the interrupted flag in the thread
(`Thread.currentThread().interrupt()`), so that if someone is checking it up in
the stack knows that there has been an interruption and should exit.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]