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

com.elephantdrummer.executor.engine.DrummerJobWrapper Maven / Gradle / Ivy

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

import java.util.Date;
import java.util.concurrent.Callable;

import com.elephantdrummer.trigger.Trigger;

/**
 * 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 DrummerJobWrapper implements Comparable{
	
	private Callable job;
	private Trigger trigger;
	private boolean cachedThread;
	private volatile String name;
	
	public DrummerJobWrapper(String name,Callable job,Trigger trigger,boolean cachedThreadPool){
		setJob(job);
		setTrigger(trigger);
		setCachedThread(cachedThreadPool);
		setName(name);
	}
	
	public Callable getJob() {
		return job;
	}
	public void setJob(Callable job) {
		this.job = job;
	}
	public Trigger getTrigger() {
		return trigger;
	}
	public void setTrigger(Trigger trigger) {
		this.trigger = trigger;
	}

	@Override
	public int compareTo(DrummerJobWrapper o) {
		if (o==null) return 1;
//		if (getTrigger()==null) System.out.println("TRIGGER NULLEM DLA "+getName());
//		if (o.getTrigger()==null) System.out.println("TRIGGER2 NULLEM DLA "+o.getName());
		return getTrigger().getNextRunTime(new Date()).compareTo(o.getTrigger().getNextRunTime(new Date()));
	}
	
	public long howMuchLonger(){
		Date dt=new Date();
		long retval= getTrigger().getNextRunTime(dt).getTime()-dt.getTime();
		long waitoffset=0;
		while (retval<=3){
			waitoffset=waitoffset+3;
			dt=new Date(dt.getTime()+3);
			retval= getTrigger().getNextRunTime(dt).getTime()-dt.getTime();
		}
		
		return retval+waitoffset;
	}

	public boolean isCachedThread() {
		return cachedThread;
	}

	public void setCachedThread(boolean cachedThread) {
		this.cachedThread = cachedThread;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy