package org.gmagnotta.log;

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;

public class LogEventSpooler implements Runnable {

	private LinkedBlockingQueue<LogEvent> logEventsQueue;
	private List<LogEventWriter> strategies;

	public LogEventSpooler(LinkedBlockingQueue<LogEvent> logEventsQueue, List<LogEventWriter> strategies) {
		this.logEventsQueue = logEventsQueue;
		this.strategies = strategies;
	}

	@Override
	public void run() {

		while (!Thread.currentThread().isInterrupted()) {

			try {

				LogEvent logEvent = logEventsQueue.take();

				for (Iterator<LogEventWriter> iterator = strategies.iterator(); iterator.hasNext();) {

					// Get next logger strategy
					LogEventWriter loggerStrategy = (LogEventWriter) iterator.next();

					// Stop logger strategy
					loggerStrategy.write(logEvent);

				}

			} catch (InterruptedException ex) {

				// We were interrupted!
				return;
				
			}

		}

	}

}
@@ -25,35 +25,8 @@
 g;%0A%0A
-import java.util.Iterator;%0A
 impo
@@ -94,16 +94,116 @@
 Queue;%0A%0A
+/**%0A * Spooler class that takes log events from the queue and send them to each logger strategy%0A */%0A
 public c
@@ -672,102 +672,13 @@
 ();%0A
-%0A
 %09%09%09%09
-for (Iterator%3CLogEventWriter%3E iterator = strategies.iterator(); iterator.hasNext();) %7B%0A%0A%09
+%0A
 %09%09%09%09
@@ -709,17 +709,21 @@
 egy%0A%09%09%09%09
-%09
+for (
 LogEvent
@@ -748,57 +748,49 @@
 egy 
-= (LogEventWriter) iterator.next();%0A%0A%09%09%09%09%09// Stop
+: strategies) %7B%0A%09%09%09%09%09%0A%09%09%09%09%09// write event
  log

use for... each syntax