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.impl; 017 018import java.util.Date; 019import java.util.List; 020 021import org.kuali.common.util.Assert; 022import org.kuali.common.util.FormatUtils; 023import org.kuali.common.util.execute.Executable; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027import com.google.common.collect.ImmutableList; 028 029/** 030 * Execute the list of <code>executables</code> supplied to this bean 031 */ 032public class ExecutablesExecutable implements Executable { 033 034 private static final Logger logger = LoggerFactory.getLogger(ExecutablesExecutable.class); 035 036 private final List<Executable> executables; 037 private final boolean skip; 038 private final boolean timed; 039 040 public ExecutablesExecutable(Executable... executables) { 041 this(ImmutableList.copyOf(executables)); 042 } 043 044 public ExecutablesExecutable(List<Executable> executables) { 045 this(executables, false); 046 } 047 048 public ExecutablesExecutable(List<Executable> executables, boolean skip) { 049 this(executables, skip, false); 050 } 051 052 public ExecutablesExecutable(List<Executable> executables, boolean skip, boolean timed) { 053 Assert.noNulls(executables); 054 this.executables = ImmutableList.copyOf(executables); 055 this.skip = skip; 056 this.timed = timed; 057 } 058 059 @Override 060 public void execute() { 061 if (skip) { 062 logger.info("Skipping execution of {} executables", executables.size()); 063 return; 064 } 065 long start = System.currentTimeMillis(); 066 for (Executable executable : executables) { 067 executable.execute(); 068 } 069 if (timed) { 070 long stop = System.currentTimeMillis(); 071 logger.info("------------------------------------------------------------------------"); 072 logger.info("Total Time: {}", FormatUtils.getTime(stop - start)); 073 logger.info("Finished at: {}", new Date(stop)); 074 logger.info("------------------------------------------------------------------------"); 075 } 076 } 077 078 public List<Executable> getExecutables() { 079 return executables; 080 } 081 082 public boolean isSkip() { 083 return skip; 084 } 085 086 public boolean isTimed() { 087 return timed; 088 } 089 090}