All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.elephantdrummer.executor.SimpleJobExecutor Maven / Gradle / Ivy

There is a newer version: 1.2.5
Show newest version
package com.elephantdrummer.executor;

import java.util.concurrent.ExecutionException;
import java.util.logging.Level;

import com.elephantdrummer.container.Container;
import com.elephantdrummer.container.ContainerElement;
import com.elephantdrummer.executor.base.ExecutorBase;
import com.elephantdrummer.executor.base.JobType;
import com.elephantdrummer.tool.HistoryBuffer;

/**
 * Copyright 2018 Elephant Software Klaudiusz Wojtkowiak e-mail: [email protected]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0 
 *  
 *  Unless required by applicable law or agreed to in writing, software 
 *  distributed under the License is distributed on an "AS IS" BASIS, 
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 *  See the License for the specific language governing permissions and 
 *  limitations under the License. 
 */
public class SimpleJobExecutor extends ExecutorBase implements ContainerElement{
	
	public SimpleJobExecutor() { 
		historyBuffer=Container.getElement(HistoryBuffer.class);
	}
	
	@Override
	protected final JobType getJobType() {
		return JobType.TYPICAL_JOB;
	}
	

	 @Override
	public Void call() throws InterruptedException, ExecutionException{
		if (isEnabled()==false|| (isUnderExecution()==true&&isSkipExecutionWhenPreviousJobIsRunning()) ){
			log.fine("Thread "+Thread.currentThread().getId()+ " is under execution. Skipping...");
			
			return null;
		}
		
		setUnderExecution(true);
		try{
			startJobProcedure();
		
			if (getJobLogicProvider()==null==false&& isAbandoned()==false){
				getJobLogicProvider().jobLogic();
			}
			
		}catch(Throwable t){
			log.log(Level.SEVERE,"job execution error ",t);
			handleThrowable(t);
			
		}finally{
			setUnderExecution(false);
		}
		
		
		
		try{
			finishJobProcedure();
		}catch (Exception e){
			e.printStackTrace();
		}
    	return null;
	}
	


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy