class MessageBus implements IOFogModule {

	public void stop() {
		logInfo("Start closing receivers and publishers and stops ActiveMQ server");

		if (receivers != null) {
			for (MessageReceiver receiver : receivers.values()) {
				try {
					receiver.close();
				} catch (Exception e) {
					logError("Error closing receiver " + receiver.getName(), new AgentSystemException(e.getMessage(), e));
				}
			}
			receivers.clear();
		}

		if (publishers != null) {
			for (MessagePublisher publisher : publishers.values()) {
				try {
					publisher.close();
				} catch (Exception e) {
					logError("Error closing publisher " + publisher.getName(), new AgentSystemException(e.getMessage(), e));
				}
			}
			publishers.clear();
		}

		try {
			messageBusServer.stopServer();
		} catch (Exception exp) {
			logError("Error closing receivers and publishers and stops ActiveMQ server", new AgentSystemException(exp.getMessage(), exp));
		}
		logInfo("Finished closing receivers and publishers and stops ActiveMQ server");
	}

	private  MessageBus();

}