private void connectNewClients() {
   while (_numActiveClients == 0 && _newClients.size() == 0) {
     try {
       Thread.sleep(100);
     } catch (InterruptedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
   for (String client : _newClients) {
     //			StockExchangeBroker keyB = _brokers.firstKey();
     //			StockExchangeBroker broker=_brokers.get(keyB);;
     StockExchangeBroker broker = _brokers.pollFirst();
     ;
     if (broker.getNumOfClients() == N) {
       _stockExchangeStompClient.send("/topic/Connected", "connectFailed " + client + "\n");
       _numActiveClients++;
     } else {
       if (broker.getNumOfClients() == 0) _numActiveCBrokers++;
       broker.addClient(client);
       _stockExchangeStompClient.send(
           "/topic/cConnected", "connected " + client + " " + broker.getName() + "\n");
       _stockExchangeStompClient.subscribe("/topic/cDeals-" + client, this);
       _numActiveClients++;
     }
     _brokers.add(broker);
   }
   _newClients.clear();
 }
  public StockExchange(String server, int port, String login, String pass)
      throws FileNotFoundException, IOException, LoginException {
    _stockExchangeStompClient = new Client(server, port, login, pass);
    _companies = initCompanies();
    _brokers = new TreeSet<StockExchangeBroker>(new BrokerCompare());

    _cash = 0;
    _numOfClosedBrockers = 0;
    _day = -1;
    _numActiveClients = 0;
    _numActiveCBrokers = 0;
    _newBrokers = new Vector<String>();
    _newClients = new Vector<String>();
    // _clients= new HashMap<String,StockExchangeBroker>();
    _stockExchangeStompClient.subscribe("/topic/bConnect", this);
    _stockExchangeStompClient.subscribe("/topic/cConnect", this);
    _stockExchangeStompClient.subscribe("/topic/Orders", this);
    _stockExchangeStompClient.subscribe("/topic/cDisconnect", this);
  }