    001/*
    002 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved.
    003 *
    004 * Project and contact information: http://www.cascading.org/
    005 *
    006 * This file is part of the Cascading project.
    007 *
    008 * Licensed under the Apache License, Version 2.0 (the "License");
    009 * you may not use this file except in compliance with the License.
    010 * You may obtain a copy of the License at
    011 *
    012 *     http://www.apache.org/licenses/LICENSE-2.0
    013 *
    014 * Unless required by applicable law or agreed to in writing, software
    015 * distributed under the License is distributed on an "AS IS" BASIS,
    016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    017 * See the License for the specific language governing permissions and
    018 * limitations under the License.
    019 */
    020
    021package cascading.flow;
    022
    023/**
    024 * Interface FlowListener provides hooks for receiving events on various stages of a {@link Flow} execution.
    025 * <p/>
    026 * Any {@link RuntimeException} thrown from any of the listener methods will force the given {@code flow} to
    027 * stop by calling {@link Flow#stop()}.
    028 */
    029public interface FlowListener
    030  {
    031  /**
    032   * The onStarting event is fired when a Flow instance receives the start() message.
    033   *
    034   * @param flow
    035   */
    036  void onStarting( Flow flow );
    037
    038  /**
    039   * The onStopping event is fired when a Flow instance receives the stop() message.
    040   *
    041   * @param flow
    042   */
    043  void onStopping( Flow flow );
    044
    045  /**
    046   * The onCompleted event is fired when a Flow instance has completed all work whether if was success or failed. If
    047   * there was a thrown exception, onThrowable will be fired before this event.
    048   *
    049   * @param flow
    050   */
    051  void onCompleted( Flow flow );
    052
    053  /**
    054   * The onThrowable event is fired if any child {@link cascading.flow.FlowStep} throws a Throwable type. This throwable is passed
    055   * as an argument to the event. This event method should return true if the given throwable was handled and should
    056   * not be rethrown from the {@link Flow#complete()} method.
    057   *
    058   * @param flow
    059   * @param throwable
    060   * @return returns true if this listener has handled the given throwable
    061   */
    062  boolean onThrowable( Flow flow, Throwable throwable );
    063  }