while(!addressAssigned) { try { connection.setClientID(generateLocalAddress()); addressAssigned = true; } catch(javax.jms.InvalidClientIDException ex) {  } }
    public void start() throws Exception     {        if (initCtxFactory != null && providerUrl != null) {            Hashtable env = new Hashtable();            env.put(Context.INITIAL_CONTEXT_FACTORY, initCtxFactory);            env.put(Context.PROVIDER_URL, providerUrl);            ctx = new InitialContext(env);        } else            ctx = new InitialContext();        connectionFactory = (javax.jms.TopicConnectionFactory)ctx.lookup(cfName);                if (connectionFactory == null)            throw new IllegalArgumentException(                    "Topic connection factory cannot be found in JNDI.");                topic = (javax.jms.Topic)ctx.lookup(topicName);                if (topic == null)            throw new IllegalArgumentException("Topic cannot be found in JNDI.");        connection = connectionFactory.createTopicConnection();        boolean addressAssigned = false;                // check if JMS connection contains client ID,         // if not, try to assign randomly generated one        while(!addressAssigned) {            if (connection.getClientID() != null)                addressAssigned = true;            else                try {                    connection.setClientID(generateLocalAddress());                    addressAssigned = true;                } catch(javax.jms.InvalidClientIDException ex) {                    // duplicate... ok, let's try again                                    }        }                local_addr = new JMSAddress(connection.getClientID(), false);        mcast_addr = new JMSAddress(topicName, true);        session = connection.createTopicSession(false,            javax.jms.Session.AUTO_ACKNOWLEDGE);        publisher = session.createPublisher(topic);        publisher.setTimeToLive(timeToLive);                subscriber = session.createSubscriber(topic);        subscriber.setMessageListener(this);                connection.start();        passUp(new Event(Event.SET_LOCAL_ADDRESS, local_addr));    }