package org.eclipse.scanning.test.event.queues.mocks;

import java.util.concurrent.CountDownLatch;

import org.eclipse.scanning.api.event.EventException;
import org.eclipse.scanning.api.event.queues.IQueueProcessor;
import org.eclipse.scanning.api.event.queues.IQueueProgressBroadcaster;
import org.eclipse.scanning.test.event.queues.dummy.DummyBean;

public class MockQueueProcessor implements IQueueProcessor<DummyBean> {

	private CountDownLatch execLatch;
	private int counter = 500;

	//Metrics for reporting interactions.
	private long runTime = 0;
	private boolean executed;
	private boolean complete;
	private boolean terminated;

	public MockQueueProcessor(CountDownLatch latch) {
		execLatch = latch;
	}

	@Override
	public void execute() throws EventException, InterruptedException {
		executed = true;
		
		long startTime = System.currentTimeMillis();
		while (counter > 0) {
			Thread.sleep(10);
			counter -= 10;
			runTime = System.currentTimeMillis() - startTime;
			if (terminated) {
				execLatch.countDown();
				return;
			}
		}
		complete = true;
		execLatch.countDown();
	}

	@Override
	public void terminate() throws EventException {
		terminated = true;
	}

	public long getCounter() {
		return counter;
	}

	public void setCounter(int counter) {
		this.counter = counter;
	}

	public long getRunTime() {
		return runTime;
	}

	public boolean isExecuted() {
		return executed;
	}

	public boolean isComplete() {
		return complete;
	}

	public boolean isTerminated() {
		return terminated;
	}

	@Override
	public Class<DummyBean> getBeanClass() {
		return DummyBean.class;
	}

	@Override
	public void pause() throws EventException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() throws EventException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void recoverBeanData(DummyBean bean) throws EventException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setProgressBroadcaster(IQueueProgressBroadcaster broadcaster) {
		// TODO Auto-generated method stub
		
	}

}

@@ -205,18 +205,16 @@
 eProcess
-or
 ;%0Aimport
@@ -261,32 +261,84 @@
 QueuePro
-gressBroadcaster
+cessor;%0Aimport org.eclipse.scanning.api.event.queues.beans.Queueable
 ;%0Aimport
@@ -1872,154 +1872,23 @@
 oid 
-recoverBeanData(DummyBean bean) throws EventException %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09%0A%09%7D%0A%0A%09@Override%0A%09public void setProgr
+setQueueProc
 ess
-Broadcaster
 (IQu
@@ -1897,36 +1897,41 @@
 ePro
-gressBroadcaster broadcaster
+cess%3C? extends Queueable%3E process
 ) %7B%0A

Update to reflect changes in API etc.