001/**
002 * Copyright 2010-2014 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 */
016package org.kuali.common.util.execute;
017
018import java.util.Arrays;
019import java.util.Date;
020import java.util.List;
021
022import org.kuali.common.util.CollectionUtils;
023import org.kuali.common.util.FormatUtils;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026
027/**
028 * Execute the list of <code>executables</code> supplied to this bean
029 * 
030 * @deprecated Use the ExecutablesExecutable from the .impl package instead
031 */
032@Deprecated
033public class ExecutablesExecutable implements Executable {
034
035        private static final Logger logger = LoggerFactory.getLogger(ExecutablesExecutable.class);
036
037        List<? extends Executable> executables;
038        boolean skip;
039        boolean timed;
040
041        public ExecutablesExecutable() {
042                this((List<? extends Executable>) null);
043        }
044
045        public ExecutablesExecutable(Executable... executables) {
046                this(Arrays.asList(executables));
047        }
048
049        public ExecutablesExecutable(List<? extends Executable> executables) {
050                this(executables, false);
051        }
052
053        public ExecutablesExecutable(List<? extends Executable> executables, boolean skip) {
054                this(executables, skip, false);
055        }
056
057        public ExecutablesExecutable(List<? extends Executable> executables, boolean skip, boolean timed) {
058                super();
059                this.executables = executables;
060                this.skip = skip;
061                this.timed = timed;
062        }
063
064        @Override
065        public void execute() {
066                if (skip) {
067                        logger.info("Skipping execution of {} executables", CollectionUtils.toEmptyList(executables).size());
068                        return;
069                }
070                long start = System.currentTimeMillis();
071                for (Executable executable : executables) {
072                        executable.execute();
073                }
074                if (timed) {
075                        long stop = System.currentTimeMillis();
076                        logger.info("------------------------------------------------------------------------");
077                        logger.info("Total Time: {}", FormatUtils.getTime(stop - start));
078                        logger.info("Finished at: {}", new Date(stop));
079                        logger.info("------------------------------------------------------------------------");
080                }
081        }
082
083        public List<? extends Executable> getExecutables() {
084                return executables;
085        }
086
087        public void setExecutables(List<? extends Executable> executables) {
088                this.executables = executables;
089        }
090
091        public boolean isSkip() {
092                return skip;
093        }
094
095        public void setSkip(boolean skip) {
096                this.skip = skip;
097        }
098
099        public boolean isTimed() {
100                return timed;
101        }
102
103        public void setTimed(boolean timed) {
104                this.timed = timed;
105        }
106
107}