View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  
18  package org.apache.logging.log4j.core.async;
19  
20  import org.apache.logging.log4j.core.LogEvent;
21  import org.apache.logging.log4j.core.jmx.RingBufferAdmin;
22  
23  /**
24   * Encapsulates the mechanism used to log asynchronously. There is one delegate per configuration, which is shared by
25   * all AsyncLoggerConfig objects in the configuration.
26   */
27  public interface AsyncLoggerConfigDelegate {
28  
29      /**
30       * If possible, delegates the invocation of {@code callAppenders} to the background thread and returns {@code true}.
31       * If this is not possible (if it detects that delegating to the background thread would cause deadlock because the
32       * current call to Logger.log() originated from the background thread and the ringbuffer is full) then this method
33       * does nothing and returns {@code false}. It is the responsibility of the caller to process the event when this
34       * method returns {@code false}.
35       * 
36       * @param event the event to delegate to the background thread
37       * @param asyncLoggerConfig the logger config to call from the background thread
38       * @return {@code true} if delegation was successful, {@code false} if the calling thread needs to process the event
39       *         itself
40       */
41      boolean tryCallAppendersInBackground(LogEvent event, AsyncLoggerConfig asyncLoggerConfig);
42  
43      /**
44       * Creates and returns a new {@code RingBufferAdmin} that instruments the ringbuffer of this
45       * {@code AsyncLoggerConfig}.
46       * 
47       * @param contextName name of the {@code LoggerContext}
48       * @param loggerConfigName name of the logger config
49       * @return the RingBufferAdmin that instruments the ringbuffer
50       */
51      RingBufferAdmin createRingBufferAdmin(String contextName, String loggerConfigName);
52  }