/*
 * Copyright 2016-2020 Chronicle Software
 *
 * https://chronicle.software
 *
 * Licensed 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 net.openhft.chronicle.core.threads;

import org.jetbrains.annotations.NotNull;

import java.io.Closeable;

@FunctionalInterface
public interface EventHandler extends VanillaEventHandler {
    default void eventLoop(EventLoop eventLoop) {
    }

    /**
     * Notify handler that the event the handler's action method
     * will not be called again. Should be called once only. Should be called from the event
     * loop's execution thread.
     * <p>This is called either when the event loop is terminating, or if this EventHandler s being
     * removed from the event loop.
     * <p>If this implements {@link Closeable} then the event loop will close this after
     * loopFinished has been called. close should be called once only.
     * <p>Exceptions thrown by loopFinished or close are caught and logged (at debug level)
     * and cleanup continues
     */
    // TODO Replace this with close() only.
    default void loopFinished() {
    }

    @NotNull
    default HandlerPriority priority() {
        return HandlerPriority.MEDIUM;
    }
}


@@ -997,35 +997,63 @@
 in. 
-Should be called once only.
+This is an appropriate place to perform cleanup.%0A     *
  Sho
@@ -1065,16 +1065,27 @@
 e called
+ once only,
  from th
@@ -1091,23 +1091,16 @@
 he event
-%0A     *
  loop's 
@@ -1209,16 +1209,17 @@
 Handler 
+i
 s being%0A
@@ -1327,20 +1327,40 @@
 p will c
-lose
+all close (once only) on
  this af
@@ -1403,41 +1403,487 @@
 led.
- close should be called once only
+%0A     * %3Cp%3EIf this implements %7B@link Closeable%7D and something other than the event loop%0A     * calls close then it is expected that this will throw %7B@link InvalidEventHandlerException%7D next time%0A     * %7B@link #action()%7D is called. This will then allow the event loop to call loopFinished (and close) on this.%0A     * If this use case is required it is strongly recommend that this event handler guards against close%0A     * being called more than once, and ignores subsequent calls
 .%0A  
@@ -2000,16 +2000,17 @@
 ontinues
+.
 %0A     */
@@ -2014,52 +2014,8 @@
  */%0A
-    // TODO Replace this with close() only.%0A
     

improve doco