001 /**
002 * Copyright 2010-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.common.util.execute;
017
018 import java.util.Date;
019 import java.util.List;
020
021 import org.kuali.common.util.CollectionUtils;
022 import org.kuali.common.util.FormatUtils;
023 import org.slf4j.Logger;
024 import org.slf4j.LoggerFactory;
025
026 /**
027 * Execute the list of <code>executables</code> supplied to this bean
028 */
029 public class ExecutablesExecutable implements Executable {
030
031 private static final Logger logger = LoggerFactory.getLogger(ExecutablesExecutable.class);
032
033 public ExecutablesExecutable() {
034 this(null);
035 }
036
037 public ExecutablesExecutable(List<Executable> executables) {
038 super();
039 this.executables = executables;
040 }
041
042 List<Executable> executables;
043 boolean skip;
044 boolean timed;
045
046 @Override
047 public void execute() {
048 if (skip) {
049 logger.info("Skipping execution of {} executables", CollectionUtils.toEmptyList(executables).size());
050 return;
051 }
052 long start = System.currentTimeMillis();
053 for (Executable executable : executables) {
054 executable.execute();
055 }
056 long stop = System.currentTimeMillis();
057 if (timed) {
058 String elapsed = FormatUtils.getTime(stop - start);
059 logger.info("------------------------------------------------------------------------");
060 logger.info("Total Time: {}", elapsed);
061 logger.info("Finished at: {}", new Date(stop));
062 logger.info("------------------------------------------------------------------------");
063 }
064 }
065
066 public List<Executable> getExecutables() {
067 return executables;
068 }
069
070 public void setExecutables(List<Executable> executables) {
071 this.executables = executables;
072 }
073
074 public boolean isSkip() {
075 return skip;
076 }
077
078 public void setSkip(boolean skip) {
079 this.skip = skip;
080 }
081
082 public boolean isTimed() {
083 return timed;
084 }
085
086 public void setTimed(boolean timed) {
087 this.timed = timed;
088 }
089
090 }