Index: trunk/src/main/java/omq/common/broker/Broker.java
===================================================================
--- trunk/src/main/java/omq/common/broker/Broker.java	(revision 51)
+++ trunk/src/main/java/omq/common/broker/Broker.java	(revision 53)
@@ -35,50 +35,40 @@
 	private static final Logger logger = Logger.getLogger(Broker.class.getName());
 
-	private static Connection connection;
-	private static Channel channel;
-	private static boolean clientStarted = false;
-	private static boolean connectionClosed = false;
-	private static Properties environment = null;
-	// TODO ask Pedro if it can be only one object in the map (an object can
-	// have multiple threads in the same broker -see environment-)
-	private static Map<String, RemoteObject> remoteObjs;
-
-	/**
-	 * Initializes a new Broker with the environment called by reference
-	 * 
-	 * @param env
-	 * @throws Exception
-	 */
-	public static synchronized void initBroker(Properties env) throws Exception {
-		if (environment == null) {
-
-			// Load log4j configuration
-			URL log4jResource = Broker.class.getResource("/log4j.xml");
-			DOMConfigurator.configure(log4jResource);
-
-			remoteObjs = new HashMap<String, RemoteObject>();
-			environment = env;
-			connection = OmqConnectionFactory.getNewConnection(env);
-			channel = connection.createChannel();
-			addFaultTolerance();
-			try {
-				tryConnection(env);
-			} catch (Exception e) {
-				channel.close();
-				connection.close();
-				throw new InitBrokerException("The connection didn't work");
-			}
-		} else {
-			logger.error("Broker is already started");
-			throw new InitBrokerException("Broker is already started");
-		}
-	}
-
-	public static void stopBroker() throws Exception {
+	private Connection connection;
+	private Channel channel;
+	private ResponseListener responseListener;
+	private EventDispatcher eventDispatcher;
+	private Serializer serializer;
+	private boolean clientStarted = false;
+	private boolean connectionClosed = false;
+	private Properties environment = null;
+	private Map<String, RemoteObject> remoteObjs;
+
+	public Broker(Properties env) throws Exception {
+		// Load log4j configuration
+		URL log4jResource = Broker.class.getResource("/log4j.xml");
+		DOMConfigurator.configure(log4jResource);
+
+		remoteObjs = new HashMap<String, RemoteObject>();
+		serializer = new Serializer(env);
+		environment = env;
+		connection = OmqConnectionFactory.getNewConnection(env);
+		channel = connection.createChannel();
+		addFaultTolerance();
+		try {
+			tryConnection(env);
+		} catch (Exception e) {
+			channel.close();
+			connection.close();
+			throw new InitBrokerException("The connection didn't work");
+		}
+	}
+
+	public void stopBroker() throws Exception {
 		logger.warn("Stopping broker");
 		// Stop the client
 		if (clientStarted) {
-			ResponseListener.stopResponseListner();
-			EventDispatcher.stopEventDispatcher();
+			responseListener.kill();
+			eventDispatcher.kill();
 			Proxymq.stopProxy();
 		}
@@ -95,5 +85,5 @@
 		environment = null;
 		remoteObjs = null;
-		Serializer.removeSerializers();
+		// Serializer.removeSerializers();
 	}
 
@@ -102,9 +92,9 @@
 	 * @throws Exception
 	 */
-	public static Connection getConnection() throws Exception {
+	public Connection getConnection() throws Exception {
 		return connection;
 	}
 
-	public static void closeConnection() throws IOException {
+	public void closeConnection() throws IOException {
 		logger.warn("Clossing connection");
 		connectionClosed = true;
@@ -118,5 +108,5 @@
 	 * @throws Exception
 	 */
-	public static Channel getChannel() throws Exception {
+	public Channel getChannel() throws Exception {
 		return channel;
 	}
@@ -128,10 +118,10 @@
 	 * @throws IOException
 	 */
-	public static Channel getNewChannel() throws IOException {
+	public Channel getNewChannel() throws IOException {
 		return connection.createChannel();
 	}
 
 	@SuppressWarnings("unchecked")
-	public static <T extends Remote> T lookup(String reference, Class<T> contract) throws RemoteException {
+	public <T extends Remote> T lookup(String reference, Class<T> contract) throws RemoteException {
 		try {
 
@@ -142,5 +132,5 @@
 
 			if (!Proxymq.containsProxy(reference)) {
-				Proxymq proxy = new Proxymq(reference, contract, environment);
+				Proxymq proxy = new Proxymq(reference, contract, this);
 				Class<?>[] array = { contract };
 				return (T) Proxymq.newProxyInstance(contract.getClassLoader(), array, proxy);
@@ -153,7 +143,7 @@
 	}
 
-	public static void bind(String reference, RemoteObject remote) throws RemoteException {
+	public void bind(String reference, RemoteObject remote) throws RemoteException {
 		try {
-			remote.startRemoteObject(reference, environment);
+			remote.startRemoteObject(reference, this);
 			remoteObjs.put(reference, remote);
 		} catch (Exception e) {
@@ -162,5 +152,5 @@
 	}
 
-	public static void unbind(String reference) throws RemoteException, IOException {
+	public void unbind(String reference) throws RemoteException, IOException {
 		if (remoteObjs.containsKey(reference)) {
 			RemoteObject remote = remoteObjs.get(reference);
@@ -183,10 +173,10 @@
 	 * @throws Exception
 	 */
-	private static synchronized void initClient(Properties environment) throws Exception {
-		if (ResponseListener.isVoid()) {
-			ResponseListener.init(environment);
-		}
-		if (EventDispatcher.isVoid()) {
-			EventDispatcher.init(environment);
+	private synchronized void initClient(Properties environment) throws Exception {
+		if (responseListener == null) {
+			responseListener = new ResponseListener(this);
+		}
+		if (eventDispatcher == null) {
+			eventDispatcher = new EventDispatcher(this);
 		}
 	}
@@ -199,5 +189,5 @@
 	 * @throws SerializerException
 	 */
-	public static void trigger(Event event) throws IOException, SerializerException {
+	public void trigger(Event event) throws IOException, SerializerException {
 		String UID = event.getTopic();
 		EventWrapper wrapper = new EventWrapper(event);
@@ -205,5 +195,5 @@
 		channel.exchangeDeclare(UID, "fanout");
 
-		byte[] bytesResponse = Serializer.serialize(wrapper);
+		byte[] bytesResponse = serializer.serialize(wrapper);
 		channel.basicPublish(UID, "", null, bytesResponse);
 
@@ -218,5 +208,5 @@
 	 * @throws Exception
 	 */
-	public static void tryConnection(Properties env) throws Exception {
+	public void tryConnection(Properties env) throws Exception {
 		Channel channel = connection.createChannel();
 		String message = "ping";
@@ -252,5 +242,5 @@
 	 * have the listener.
 	 */
-	private static void addFaultTolerance() {
+	private void addFaultTolerance() {
 		connection.addShutdownListener(new ShutdownListener() {
 			@Override
@@ -287,7 +277,18 @@
 	}
 
-	public static Properties getEnvironment() {
+	public Properties getEnvironment() {
 		return environment;
 	}
 
+	public ResponseListener getResponseListener() {
+		return responseListener;
+	}
+
+	public EventDispatcher getEventDispatcher() {
+		return eventDispatcher;
+	}
+
+	public Serializer getSerializer() {
+		return serializer;
+	}
 }
Index: trunk/src/main/java/omq/common/event/EventDispatcher.java
===================================================================
--- trunk/src/main/java/omq/common/event/EventDispatcher.java	(revision 51)
+++ trunk/src/main/java/omq/common/event/EventDispatcher.java	(revision 53)
@@ -29,6 +29,7 @@
 public class EventDispatcher extends Thread {
 	private static final Logger logger = Logger.getLogger(EventDispatcher.class.getName());
-	private static EventDispatcher dispatcher;
 
+	private Broker broker;
+	private Serializer serializer;
 	private Map<String, Vector<EventListener>> listeners;
 	private Channel channel;
@@ -37,6 +38,8 @@
 	private boolean killed = false;
 
-	private EventDispatcher(Properties env) throws Exception {
-		this.env = env;
+	public EventDispatcher(Broker broker) throws Exception {
+		this.broker = broker;
+		env = broker.getEnvironment();
+		serializer = broker.getSerializer();
 
 		// Declare the listeners map
@@ -44,10 +47,9 @@
 
 		startEventQueue();
-
 	}
 
 	private void startEventQueue() throws Exception {
 		// Get a new connection and a new channel
-		channel = Broker.getNewChannel();
+		channel = broker.getNewChannel();
 
 		String event_queue = env.getProperty(ParameterQueue.EVENT_REPLY_QUEUE);
@@ -60,35 +62,10 @@
 	}
 
-	public static void init(Properties env) throws Exception {
-		if (dispatcher == null) {
-			dispatcher = new EventDispatcher(env);
-			dispatcher.start();
-		} else {
-			throw new Exception("Already initialized");
-		}
-	}
-
-	public static void stopEventDispatcher() throws Exception {
+	public void kill() throws Exception {
 		logger.warn("Stopping EventDispatcher");
-		dispatcher.setListeners(null);
-		dispatcher.killed = true;
-		dispatcher.interrupt();
-		dispatcher.channel.close();
-		dispatcher = null;
-	}
-
-	public static EventDispatcher getDispatcher(Properties env) throws Exception {
-		if (dispatcher == null) {
-			dispatcher = new EventDispatcher(env);
-			dispatcher.start();
-		}
-		return dispatcher;
-	}
-
-	public static EventDispatcher getDispatcher() throws Exception {
-		if (dispatcher == null) {
-			throw new Exception("EventDispatcher not initialized");
-		}
-		return dispatcher;
+		setListeners(null);
+		killed = true;
+		interrupt();
+		channel.close();
 	}
 
@@ -104,5 +81,5 @@
 
 				// Get the event
-				event = Serializer.deserializeEvent(delivery.getBody());
+				event = serializer.deserializeEvent(delivery.getBody());
 
 				logger.info("Event received -> Topic: " + event.getTopic() + "CorrId: " + event.getCorrId());
@@ -210,7 +187,3 @@
 	}
 
-	public static boolean isVoid() {
-		return dispatcher == null;
-	}
-
 }
Index: trunk/src/main/java/omq/common/util/Log.java
===================================================================
--- trunk/src/main/java/omq/common/util/Log.java	(revision 51)
+++ 	(revision )
@@ -1,80 +1,0 @@
-package omq.common.util;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.Date;
-import java.util.Properties;
-
-import omq.common.broker.Broker;
-
-public class Log {
-
-	public static void saveLog(String processName, byte[] bytesResponse) throws IOException {
-
-		Properties env = Broker.getEnvironment();
-
-		String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, "");
-		if (debugPath.length() > 0) {
-			long timeNow = (new Date()).getTime();
-
-			File outputFolder = new File(debugPath + File.separator);
-			outputFolder.mkdirs();
-
-			// File outputFolder = new File(debugPath + File.separator +
-			// processName);
-			// outputFolder.mkdirs();
-
-			// File outputFileContent = new
-			// File(outputFolder.getAbsoluteFile() + File.separator +
-			// "content_" + timeNow);
-			// FileOutputStream outputStream = new
-			// FileOutputStream(outputFileContent);
-			// IOUtils.write(bytesResponse, outputStream);
-			// outputStream.close();
-
-			File outputFileLog = new File(debugPath + File.separator + "log");
-			boolean exist = outputFileLog.exists();
-
-			FileWriter fw = new FileWriter(outputFileLog, true); // the true
-																	// will
-																	// append
-																	// the
-																	// new
-																	// data
-			if (!exist) {
-				fw.write("#ProcessName\t\tFile\t\t\t\t\tDate\t\t\tSize\n");
-			}
-			fw.write(processName + "\t" + "content_" + timeNow + "\t" + timeNow + "\t" + bytesResponse.length + "\tbytes\n");
-			fw.close();
-		}
-
-	}
-
-	public static void saveTimeSendRequestLog(String processName, String coorId, String method, long timeNow) throws IOException {
-
-		Properties env = Broker.getEnvironment();
-
-		String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, "");
-		if (debugPath.length() > 0) {
-			File outputFolder = new File(debugPath + File.separator + processName);
-			outputFolder.mkdirs();
-
-			File outputFileLog = new File(outputFolder + File.separator + "log");
-			boolean exist = outputFileLog.exists();
-
-			FileWriter fw = new FileWriter(outputFileLog, true); // the true
-																	// will
-																	// append
-																	// the
-																	// new
-																	// data
-			if (!exist) {
-				fw.write("#CoorId\tMethod\tDate\n");
-			}
-			fw.write(coorId + "\t" + method + "\t" + timeNow + "\n");
-			fw.close();
-		}
-
-	}
-}
Index: trunk/src/main/java/omq/common/util/Serializer.java
===================================================================
--- trunk/src/main/java/omq/common/util/Serializer.java	(revision 51)
+++ trunk/src/main/java/omq/common/util/Serializer.java	(revision 53)
@@ -4,7 +4,4 @@
 import java.util.Properties;
 
-import org.apache.log4j.Logger;
-
-import omq.common.broker.Broker;
 import omq.common.event.Event;
 import omq.common.message.Request;
@@ -23,26 +20,31 @@
  */
 public class Serializer {
-	private static final Logger logger = Logger.getLogger(Serializer.class.getName());
-	public static String kryo = "kryo";
-	public static String java = "java";
-	public static String gson = "gson";
+	// private static final Logger logger =
+	// Logger.getLogger(Serializer.class.getName());
+	public static final String kryo = "kryo";
+	public static final String java = "java";
+	public static final String gson = "gson";
 
 	// Client serializer
-	public static ISerializer serializer;
+	public ISerializer serializer;
 
 	// Server serializers
-	private static ISerializer kryoSerializer;
-	private static ISerializer javaSerializer;
-	private static ISerializer gsonSerializer;
+	private ISerializer kryoSerializer;
+	private ISerializer javaSerializer;
+	private ISerializer gsonSerializer;
 
-	private static Boolean getEnableCompression() {
-		Properties env = Broker.getEnvironment();
+	private Properties env;
+
+	public Serializer(Properties env) {
+		this.env = env;
+	}
+
+	private Boolean getEnableCompression() {
 		return Boolean.valueOf(env.getProperty(ParameterQueue.ENABLECOMPRESSION, "false"));
 	}
 
-	public static ISerializer getInstance() throws SerializerException {
+	public ISerializer getInstance() throws SerializerException {
 		if (serializer == null) {
 			try {
-				Properties env = Broker.getEnvironment();
 				String className = env.getProperty(ParameterQueue.SERIALIZER_NAME, Serializer.java);
 
@@ -60,5 +62,5 @@
 	}
 
-	public static ISerializer getInstance(String type) throws SerializerException {
+	public ISerializer getInstance(String type) throws SerializerException {
 		if (kryo.equals(type)) {
 			if (kryoSerializer == null) {
@@ -79,5 +81,5 @@
 	}
 
-	public static byte[] serialize(String type, Object obj) throws SerializerException {
+	public byte[] serialize(String type, Object obj) throws SerializerException {
 		ISerializer instance = getInstance(type);
 
@@ -96,5 +98,5 @@
 
 	// TODO: remove this function and think about the event serialization
-	public static byte[] serialize(Object obj) throws SerializerException {
+	public byte[] serialize(Object obj) throws SerializerException {
 		ISerializer instance = getInstance();
 
@@ -112,5 +114,5 @@
 	}
 
-	public static Request deserializeRequest(String type, byte[] bytes, RemoteObject obj) throws SerializerException {
+	public Request deserializeRequest(String type, byte[] bytes, RemoteObject obj) throws SerializerException {
 		ISerializer instance = getInstance(type);
 
@@ -128,5 +130,5 @@
 	}
 
-	public static Response deserializeResponse(byte[] bytes, Class<?> type) throws SerializerException {
+	public Response deserializeResponse(byte[] bytes, Class<?> type) throws SerializerException {
 		ISerializer instance = getInstance();
 
@@ -144,5 +146,5 @@
 	}
 
-	public static Event deserializeEvent(byte[] bytes) throws SerializerException {
+	public Event deserializeEvent(byte[] bytes) throws SerializerException {
 		ISerializer instance = getInstance();
 
@@ -160,10 +162,10 @@
 	}
 
-	public static void removeSerializers() {
-		logger.warn("Removing serializers");
-		serializer = null;
-		kryoSerializer = null;
-		javaSerializer = null;
-		gsonSerializer = null;
-	}
+	// public static void removeSerializers() {
+	// logger.warn("Removing serializers");
+	// serializer = null;
+	// kryoSerializer = null;
+	// javaSerializer = null;
+	// gsonSerializer = null;
+	// }
 }
