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  	List<Executable> executables;
34  	boolean skip;
35  	boolean timed;
36  
37  	@Override
38  	public void execute() {
39  		if (skip) {
40  			logger.info("Skipping execution of {} executables", CollectionUtils.toEmptyList(executables).size());
41  			return;
42  		}
43  		long start = System.currentTimeMillis();
44  		for (Executable executable : executables) {
45  			executable.execute();
46  		}
47  		long stop = System.currentTimeMillis();
48  		if (timed) {
49  			String elapsed = FormatUtils.getTime(stop - start);
50  			logger.info("------------------------------------------------------------------------");
51  			logger.info("Total Time: {}", elapsed);
52  			logger.info("Finished at: {}", new Date(stop));
53  			logger.info("------------------------------------------------------------------------");
54  		}
55  	}
56  
57  	public List<Executable> getExecutables() {
58  		return executables;
59  	}
60  
61  	public void setExecutables(List<Executable> executables) {
62  		this.executables = executables;
63  	}
64  
65  	public boolean isSkip() {
66  		return skip;
67  	}
68  
69  	public void setSkip(boolean skip) {
70  		this.skip = skip;
71  	}
72  
73  	public boolean isTimed() {
74  		return timed;
75  	}
76  
77  	public void setTimed(boolean timed) {
78  		this.timed = timed;
79  	}
80  
81  }