001 /**
002 * Copyright 2010-2012 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 List<Executable> executables;
034 boolean skip;
035 boolean timed;
036
037 @Override
038 public void execute() {
039 if (skip) {
040 logger.info("Skipping execution of {} executables", CollectionUtils.toEmptyList(executables).size());
041 return;
042 }
043 long start = System.currentTimeMillis();
044 for (Executable executable : executables) {
045 executable.execute();
046 }
047 long stop = System.currentTimeMillis();
048 if (timed) {
049 String elapsed = FormatUtils.getTime(stop - start);
050 logger.info("------------------------------------------------------------------------");
051 logger.info("Total Time: {}", elapsed);
052 logger.info("Finished at: {}", new Date(stop));
053 logger.info("------------------------------------------------------------------------");
054 }
055 }
056
057 public List<Executable> getExecutables() {
058 return executables;
059 }
060
061 public void setExecutables(List<Executable> executables) {
062 this.executables = executables;
063 }
064
065 public boolean isSkip() {
066 return skip;
067 }
068
069 public void setSkip(boolean skip) {
070 this.skip = skip;
071 }
072
073 public boolean isTimed() {
074 return timed;
075 }
076
077 public void setTimed(boolean timed) {
078 this.timed = timed;
079 }
080
081 }