From 48af5e5b3257e99469871f1a8c77849870099ee0 Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Fri, 10 Feb 2017 14:16:11 -0600 Subject: [PATCH] Added TaskExecutionListenerSupport This commit adds the TaskExecutionListenerSupport, a no-op implementation of the TaskExecutionListner. This allows a user to extend the TaskExecutionListenerSupport and simply override what they need instead of implementing all of the methods. --- .../SimpleCommandLineArgsProvider.java | 19 ++++++++- .../TaskExecutionListenerSupport.java | 42 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListenerSupport.java diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProvider.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProvider.java index 98a1f32a..82a8711c 100644 --- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProvider.java +++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProvider.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.batch.item.ExecutionContext; +import org.springframework.cloud.task.listener.TaskExecutionListenerSupport; import org.springframework.cloud.task.repository.TaskExecution; import org.springframework.util.Assert; @@ -29,18 +30,32 @@ import org.springframework.util.Assert; * @author Michael Minella * @since 1.1.0 */ -public class SimpleCommandLineArgsProvider implements CommandLineArgsProvider { +public class SimpleCommandLineArgsProvider extends TaskExecutionListenerSupport implements CommandLineArgsProvider { - private final TaskExecution taskExecution; + private TaskExecution taskExecution; private List appendedArgs; + public SimpleCommandLineArgsProvider() { + } + + /** + * @param taskExecution task execution + * @deprecated use the {@link org.springframework.cloud.task.listener.TaskExecutionListener} + * functionality to obtain the {@link TaskExecution} + */ + @Deprecated public SimpleCommandLineArgsProvider(TaskExecution taskExecution) { Assert.notNull(taskExecution, "A taskExecution is required"); this.taskExecution = taskExecution; } + @Override + public void onTaskStartup(TaskExecution taskExecution) { + this.taskExecution = taskExecution; + } + /** * Additional command line args to be appended. * diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListenerSupport.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListenerSupport.java new file mode 100644 index 00000000..16dabcd1 --- /dev/null +++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListenerSupport.java @@ -0,0 +1,42 @@ +/* + * Copyright 2017 the original author or authors. + * + * 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 org.springframework.cloud.task.listener; + +import org.springframework.cloud.task.repository.TaskExecution; + +/** + * A no-op implementation of the {@link TaskExecutionListener} to allow for overriding + * only the methods of interest. + * + * @author Michael Minella + * @since 1.2 + */ +public class TaskExecutionListenerSupport implements TaskExecutionListener { + @Override + public void onTaskStartup(TaskExecution taskExecution) { + + } + + @Override + public void onTaskEnd(TaskExecution taskExecution) { + + } + + @Override + public void onTaskFailed(TaskExecution taskExecution, Throwable throwable) { + + } +}