Index: trunk/src/main/java/omq/common/broker/Broker.java
===================================================================
--- trunk/src/main/java/omq/common/broker/Broker.java	(revision 50)
+++ 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;
+	}
 }
