Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 Michael Ruflin, Andr´┐Ż Locher, Claudia von Bastian. This file is part of Tatool. Tatool is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Tatool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tatool. If not, see <http://www.gnu.org/licenses/>. /
 
 package ch.tatool.core.element.handler.pause;
 
Pauses the execution between two elements.
 
 	
 	private static final int DEFAULT_PAUSE_DURATION = 500;

    
Default pause duration between two tasks.
 
     private long defaultInterElementPauseDuration = ;
    
    
Current pause duration between two tasks.
 
     private long currentInterElementPauseDuration;

    
PhaseRunnable that stops the execution thread.
 
     private ExecutionPauser pauser;
     
 		super("executor-pause-handler");
 		 = new ExecutionPauser();
 	}
 	
     public void processExecutionPhase(ExecutionContext event) {
     	switch(event.getPhase()) {
     	case :
     		registerPauser(event);
     		break;
     	case :
     		unregisterPauser(event);
     		break;
     	case :
     		resetPauseDuration();
     		break;
     	case :
     		//postProcess(event);
     		break;
     	default:
     		// do nothing
     	}
     }
     
     private void registerPauser(ExecutionContext context) {
     	// to execute the pause
     	PhaseRunnableManager execManager = context.getExecutor().getPhaseRunnableManager();
     	// to fetch what pause duration should be used in the next pre element execution
     }
     
     private void unregisterPauser(ExecutionContext context) {
     	PhaseRunnableManager execManager = context.getExecutor().getPhaseRunnableManager();
     }

Overwrite the duration for which the module is paused before execution the next element.
 
 	public void setCurrentInterElementPauseDuration(long duration) {
 	}
 	
 	}

Set the default duration for which the execution is paused in between two elements.
 
 	public void setDefaultInterElementPauseDuration(long duration) {
 	}
 	
 	}

    
Resets the pause duration.
    public void resetPauseDuration() {
    }
    
    
PhaseRunnable that stops the execution thread for a predefined duration
    class ExecutionPauser implements PhaseRunnable {
    	private Thread thread;
    	private long duration = 0;
    	
    	public void setDuration(long duration) {
    		this. = duration;
    	}
    	
		public void run(ExecutionContext context) {
			switch (context.getPhase()) {
				// before the element execution, pause the time we previously stored
				if ( <= 0) return;
				 = Thread.currentThread();
				try {
		            Thread.sleep();
		        } catch (InterruptedException ie) {
		        	// ok, just return
		        }
		         = null;
		        break;
				// after the element has been executed, store the duration we want to wait fore before the next
				// element execution
			default:
				break;
			}
		}
		public void stop() {
			// wake the thread up if possible
			try {
				if ( != null) {
				}
catch (NullPointerException npe) {
				// bad luck
			}
		}
    	
    }
New to GrepCode? Check out our FAQ X