Skip to content

amlinv/javaScheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IDEA:
	- Process: set of steps with a defined start and finish

		public interface Process {
			void	start();
			void	addStep(Step newStep);
		}

	- Step: a step in a process

		public interface Step {
			void	execute (Process process);
			boolean isBlocking();
		}

	- AbstractBlockingStep: a step in a process that blocks

		public abstract AbstractBlockingStep extends Step {
		    public boolean  isBlocking () {
		        return true;
		    }
		}

	- InputSteamReadStep: (TBD: can an asynchronous operation be used instead internally?)

		public class InputStreamReadStep implements Step {
			private InputStream	inputStream;
			private int		startOffset;
			private int		requestLength;
			private byte[]		buffer;

			private int		result;
			private Exception	exception;

			public	InputStreamReadStep (InputStream inputStream, byte[] buffer, int startOffset,
				                     int requestLength);

			public void	execute (Process process) {
				result = -1;
				try {
					result = inputStream.read(inputStream, buffer, startOffset, requestLength);
				} catch ( Exception exc ) {
					this.exception = exc;
				}
			}

			public int	getResult () {
				if ( exception != null ) {
					throw	new RuntimeException("execution failed", this.exception);
				}

				return	this.result;
			}

			public boolean	wasExceptionThrown () {
				return	( this.exception != null );
			}

			public Exception	getException () {
				return	this.exception;
			}
		}

	- AsyncStep: a step in a process that does not block

		public interface AsyncStep extends Step {
		}

	- Scheduler: decide which process is the next to be scheduled
		- Implement an EngineSource
		- RoundRobinScheduler
			- Simple list of processes
			- Steps from processes are fed to the Engine in simple round-robin fashion (first come, first served)
		- PriorityScheduler
			- List of processes by priority
			- SimplePriorityScheduler
				- Higher priority always takes precedence over lower priority
					- i.e. when a higher priority has an available task, no lower priority will go to the engine until
					  after the higher priority step hits the engine
				- Default SinglePriorityScheduler is a RoundRobinProcessScheduler; every process gets selected in
				 round-robin fashion.
			- FairnessPriorityScheduler
				- Higher priority gets more cycles from the Engine, but lower priority steps still have opportunity to
				  execute
				- May split threads into two groups: one which allows any priority to run regardless of all available
				  step priority levels; another which is dedicated to higher priorities first

	- Engine: manage thread pools
		- Let EngineSource know when a thread is ready for work (really, EngineSource.getNextTask())

	- RunningTask
		- Notify listener of events (task complete; task exception)