package ei.engine.network.worker;

public class EchoWorker extends Worker {
	
	public void update() {
		WorkerDataEvent dataEvent;
		
		while(true) {
			// Wait for data to become available
			synchronized(getEventQueue()) {
				while(getEventQueue().isEmpty()) {
					try {
						getEventQueue().wait();
					} catch (InterruptedException e) {
					}
				}
				dataEvent = (WorkerDataEvent) getEventQueue().remove(0);
			}
			
			// Return to sender
			System.out.println("Recived Msg: "+dataEvent.data);
			dataEvent.network.send(dataEvent.socket, dataEvent.data);
		}
	}
}
