    001//  Copyright 2008, 2009, 2013 The Apache Software Foundation
    002//
    003// Licensed under the Apache License, Version 2.0 (the "License");
    004// you may not use this file except in compliance with the License.
    005// You may obtain a copy of the License at
    006//
    007//     http://www.apache.org/licenses/LICENSE-2.0
    008//
    009// Unless required by applicable law or agreed to in writing, software
    010// distributed under the License is distributed on an "AS IS" BASIS,
    011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012// See the License for the specific language governing permissions and
    013// limitations under the License.
    014
    015package org.apache.tapestry5.ioc;
    016
    017import java.io.IOException;
    018import java.lang.annotation.ElementType;
    019import java.lang.annotation.Retention;
    020import java.lang.annotation.RetentionPolicy;
    021import java.lang.annotation.Target;
    022
    023/**
    024 * Used to track some set of operations in such a way that a failure (a thrown RuntimeException) will be logged along
    025 * with a trace of the stack of operations.
    026 */
    027public interface OperationTracker
    028{
    029    /**
    030     * Executes the operation.  If the operation throws a {@link RuntimeException} it will be logged and rethrown
    031     * wrapped as a {@link org.apache.tapestry5.ioc.internal.OperationException}.
    032     *
    033     * @param description
    034     *         used if there is an exception
    035     * @param operation
    036     *         to execute
    037     */
    038    void run(String description, Runnable operation);
    039
    040    /**
    041     * As with {@link #run(String, Runnable)}, but the operation may return a value.
    042     *
    043     * @param description
    044     *         used if there is an exception
    045     * @param operation
    046     *         to invoke
    047     * @return result of operation
    048     */
    049    <T> T invoke(String description, Invokable<T> operation);
    050
    051    /**
    052     * As with {@link #invoke(String, Invokable)}, but the operation may throw an {@link java.io.IOException}.
    053     *
    054     * @param description
    055     *         used if there is an exception (outside of IOException)
    056     * @param operation
    057     *         to perform
    058     * @return result of operation
    059     * @since 5.4
    060     */
    061    <T> T perform(String description, IOOperation<T> operation) throws IOException;
    062
    063    /**
    064     * Annotation to be be used in exception classes whose instances are not meant to be
    065     * logged in  {@linkplain OperationTracker}.
    066     * @since 5.8.3
    067     */
    068    @Retention(RetentionPolicy.RUNTIME)
    069    @Target(ElementType.TYPE)
    070    public static @interface NonLoggableException
    071    {
    072    }
    073
    074}