/**
 * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net)
 *
 * 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 teetime.framework;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

abstract class AbstractRunnableStage implements Runnable {

	private final Stage stage;
	@SuppressWarnings("PMD.LoggerIsNotStaticFinal")
	protected final Logger logger;

	public AbstractRunnableStage(final Stage stage) {
		this.stage = stage;
		this.logger = LoggerFactory.getLogger(stage.getClass());
	}

	@Override
	public final void run() {
		this.logger.debug("Executing runnable stage...");
		final Stage stage = this.stage;

		try {
			beforeStageExecution(stage);

			do {
				executeStage(stage);
			} while (!stage.shouldBeTerminated());

			afterStageExecution(stage);

		} catch (Error e) {
			this.logger.error("Terminating thread due to the following exception: ", e);
			throw e;
		} catch (RuntimeException e) {
			this.logger.error("Terminating thread due to the following exception: ", e);
			throw e;
		} catch (InterruptedException e) {
			this.logger.error("Terminating thread due to the following exception: ", e);
		}

		this.logger.debug("Finished runnable stage. (" + stage.getId() + ")");
	}

	protected abstract void beforeStageExecution(Stage stage) throws InterruptedException;

	protected abstract void executeStage(Stage stage);

	protected abstract void afterStageExecution(Stage stage);
}

@@ -772,16 +772,153 @@
 able %7B%0A%0A
+%09private static final String TERMINATING_THREAD_DUE_TO_THE_FOLLOWING_EXCEPTION = %22Terminating thread due to the following exception: %22;%0A%0A
 %09private
@@ -1444,218 +1444,100 @@
 ch (
-Error e) %7B%0A%09%09%09this.logger.error(%22Terminating thread due to the following exception: %22, e);%0A%09%09%09throw e;%0A%09%09%7D catch (RuntimeException e) %7B%0A%09%09%09this.logger.error(%22Terminating thread due to the following exception: %22
+RuntimeException e) %7B%0A%09%09%09this.logger.error(TERMINATING_THREAD_DUE_TO_THE_FOLLOWING_EXCEPTION
 , e)
@@ -1612,61 +1612,57 @@
 ror(
-%22Terminating thread due to the following exception: %22
+TERMINATING_THREAD_DUE_TO_THE_FOLLOWING_EXCEPTION
 , e)

refactored strings to constant