View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.execute;
17  
18  import java.util.Date;
19  import java.util.List;
20  
21  import org.kuali.common.util.CollectionUtils;
22  import org.kuali.common.util.FormatUtils;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  /**
27   * Execute the list of <code>executables</code> supplied to this bean
28   */
29  public class ExecutablesExecutable implements Executable {
30  
31  	private static final Logger logger = LoggerFactory.getLogger(ExecutablesExecutable.class);
32  
33  	public ExecutablesExecutable() {
34  		this(null);
35  	}
36  
37  	public ExecutablesExecutable(List<Executable> executables) {
38  		super();
39  		this.executables = executables;
40  	}
41  
42  	List<Executable> executables;
43  	boolean skip;
44  	boolean timed;
45  
46  	@Override
47  	public void execute() {
48  		if (skip) {
49  			logger.info("Skipping execution of {} executables", CollectionUtils.toEmptyList(executables).size());
50  			return;
51  		}
52  		long start = System.currentTimeMillis();
53  		for (Executable executable : executables) {
54  			executable.execute();
55  		}
56  		long stop = System.currentTimeMillis();
57  		if (timed) {
58  			String elapsed = FormatUtils.getTime(stop - start);
59  			logger.info("------------------------------------------------------------------------");
60  			logger.info("Total Time: {}", elapsed);
61  			logger.info("Finished at: {}", new Date(stop));
62  			logger.info("------------------------------------------------------------------------");
63  		}
64  	}
65  
66  	public List<Executable> getExecutables() {
67  		return executables;
68  	}
69  
70  	public void setExecutables(List<Executable> executables) {
71  		this.executables = executables;
72  	}
73  
74  	public boolean isSkip() {
75  		return skip;
76  	}
77  
78  	public void setSkip(boolean skip) {
79  		this.skip = skip;
80  	}
81  
82  	public boolean isTimed() {
83  		return timed;
84  	}
85  
86  	public void setTimed(boolean timed) {
87  		this.timed = timed;
88  	}
89  
90  }