package org.mbj.performance;

import java.util.List;
import java.util.Observable;
import java.util.Observer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Loader implements Observer {
	private static Logger log = LoggerFactory.getLogger(Loader.class);
	private List<Client> clients;
	private int countDown;
	private long totalTime;
	private long totalNbOfExecutions;

	public Loader(List<Client> clients) {
		super();
		this.clients = clients;
		this.countDown = clients.size();
		this.totalTime = 0;
		this.totalNbOfExecutions = 0;
	}

	public long getTotalTime() {
		return totalTime;
	}

	public void start() {
		for (Client client : clients) {
			client.addObserver(this);
			new Thread(client).start();
			log.debug("Started client {}", client.getId());
		}
		synchronized (this) {
			while (countDown > 0) {
				try {
					this.wait();
				} catch (InterruptedException e) {
					log.error("", e);
				}
			}
		}
		log.debug("Total time: {} ms.", totalTime);
		log.debug("Total number of executions: {}.", totalNbOfExecutions);
		log.debug("Average time/execution: {} ms.", (((double)totalTime) / ((double)totalNbOfExecutions)));
		log.debug("Average executions/s: {}.", (((double)totalNbOfExecutions) / ((double)totalTime)) * 1000);
	}

	public void update(Observable observable, Object time) {
		synchronized (this) {
			Client client = (Client)observable;
			long clientTime = (Long) time;
			log.debug("Finished client {} in {} ms.", client.getId(), clientTime);
			totalTime += clientTime;
			totalNbOfExecutions += client.getNbOfExecutions();
			countDown--;
			this.notifyAll();
		}
	}
}
@@ -326,16 +326,36 @@
 ntDown;%0A
+%09private long time;%0A
 %09private
@@ -367,24 +367,24 @@
  totalTime;%0A
-
 %09private lon
@@ -514,24 +514,41 @@
 nts.size();%0A
+%09%09this.time = 0;%0A
 %09%09this.total
@@ -633,21 +633,16 @@
 return t
-otalT
 ime;%0A%09%7D%0A
@@ -728,16 +728,92 @@
 (this);%0A
+%09%09%7D%0A%09%09time = -System.currentTimeMillis();%0A%09%09for (Client client : clients) %7B%0A
 %09%09%09new T
@@ -1046,16 +1046,89 @@
 %09%09%7D%0A%09%09%7D%0A
+%09%09time += System.currentTimeMillis();%0A%09%09log.debug(%22Time: %7B%7D ms.%22, time);%0A
 %09%09log.de
@@ -1336,16 +1336,16 @@
 ons)));%0A
+
 %09%09log.de
@@ -1416,29 +1416,24 @@
 / ((double)t
-otalT
 ime)) * 1000

Fix and updated logging