gt: 			if (!StringUtils.isBlank(password)) {
context: /**
   * openHAB, the open Home Automation Bus.
   * Copyright (C) 2010-2013, openHAB.org <admin@openhab.org>
   *
   * See the contributors.txt file in the distribution for a
   * full listing of individual contributors.
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as
   * published by the Free Software Foundation; either version 3 of the
   * License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, see <http://www.gnu.org/licenses>.
   *
   * Additional permission under GNU GPL version 3 section 7
   *
   * If you modify this Program, or any covered work, by linking or
   * combining it with Eclipse (or a modified version of that library),
   * containing parts covered by the terms of the Eclipse Public License
   * (EPL), the licensors of this Program grant you additional permission
   * to convey the resulting work.
   */
  package org.openhab.io.transport.mqtt.internal;
  
  import java.security.cert.X509Certificate;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Properties;
  import java.util.Timer;
  
  import javax.net.ssl.SSLContext;
  import javax.net.ssl.SSLSocketFactory;
  import javax.net.ssl.TrustManager;
  import javax.net.ssl.X509TrustManager;
  
  import org.apache.commons.lang.StringUtils;
  import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
  import org.eclipse.paho.client.mqttv3.MqttCallback;
  import org.eclipse.paho.client.mqttv3.MqttClient;
  import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
  import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
  import org.eclipse.paho.client.mqttv3.MqttException;
  import org.eclipse.paho.client.mqttv3.MqttMessage;
  import org.eclipse.paho.client.mqttv3.MqttTopic;
  import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
  import org.openhab.io.transport.mqtt.MqttMessageConsumer;
  import org.openhab.io.transport.mqtt.MqttMessageProducer;
  import org.openhab.io.transport.mqtt.MqttSenderChannel;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  /**
   * An MQTTBrokerConnection represents a single client connection to a MQTT
   * broker. The connection is configured by the MQTTService with properties from
   * the openhab.cfg file.
   * 
   * When a connection to an MQTT broker is lost, it will try to reconnect every
   * 60 seconds.
   * 
   * @author Davy Vanherbergen
   * @since 1.3.0
   */
  public class MqttBrokerConnection implements MqttCallback {
  
  	private static Logger logger = LoggerFactory.getLogger(MqttBrokerConnection.class);
  
  	private static final int RECONNECT_FREQUENCY = 60000;
  
  	private String name;
  
  	private String url;
  
  	private String user;
  
  	private String password;
  
  	private int qos = 0;
  
  	private boolean retain = false;
  
  	private boolean async = true;
  
  	private String clientId;
  
  	private MqttClient client;
  
  	private boolean started;
  
  	private List<MqttMessageConsumer> consumers = new ArrayList<MqttMessageConsumer>();
  
  	private List<MqttMessageProducer> producers = new ArrayList<MqttMessageProducer>();
  
  	private Timer reconnectTimer;
  
  	/**
  	 * Create a new connection with the given name.
  	 * 
  	 * @param name
  	 *            for the connection.
  	 */
  	public MqttBrokerConnection(String name) {
  		this.name = name;
  	}
  
  	/**
  	 * Start the connection. This will try to open an MQTT client connection to
  	 * the MQTT broker and notify all publishers and subscribers on this
  	 * connection that the connection has become active.
  	 * 
  	 * @throws Exception
  	 *             If connection could not be created.
  	 */
  	public void start() throws Exception {
  
  		if (StringUtils.isEmpty(url)) {
  			logger.debug("No url defined for MQTT broker connection '{}'. Not starting.", name);
  			return;
  		}
  
  		logger.info("Starting MQTT broker connection '{}'", name);
  		openConnection();
  
  		if (reconnectTimer != null) {
  			// we are active, so stop trying to reconnect
  			reconnectTimer.cancel();
  		}
  
  		// start all consumers
  		for (MqttMessageConsumer c : consumers) {
  			startConsumer(c);
  		}
  
  		// start all producers
  		for (MqttMessageProducer p : producers) {
  			startProducer(p);
  		}
  
  		started = true;
  	}
  
  	/**
  	 * @return name for the connection as defined in openhab.cfg.
  	 */
  	public String getName() {
  		return name;
  	}
  
  	/**
  	 * Get the url for the MQTT broker. Valid URL's are in the format:
  	 * tcp://localhost:1883 or ssl://localhost:8883
  	 * 
  	 * @return url for the MQTT broker.
  	 */
  	public String getUrl() {
  		return url;
  	}
  
  	/**
  	 * Set the url for the MQTT broker. Valid URL's are in the format:
  	 * tcp://localhost:1883 or ssl://localhost:8883
  	 * 
  	 * @param url
  	 *            url string for the MQTT broker.
  	 */
  	public void setUrl(String url) {
  		this.url = url;
  	}
  
  	/**
  	 * @return optional user name for the MQTT connection.
  	 */
  	public String getUser() {
  		return user;
  	}
  
  	/**
  	 * Set the optional user name to use when connecting to the MQTT broker.
  	 * 
  	 * @param user
  	 *            name to use for connection.
  	 */
  	public void setUser(String user) {
  		this.user = user;
  	}
  
  	/**
  	 * @return connection password.
  	 */
  	public String getPassword() {
  		return password;
  	}
  
  	/**
  	 * Set the optional password to use when connecting to the MQTT broker.
  	 * 
  	 * @param password
  	 */
  	public void setPassword(String password) {
  		this.password = password;
  	}
  
  	/**
  	 * @return quality of service level.
  	 */
  	public int getQos() {
  		return qos;
  	}
  
  	/**
  	 * Set quality of service. Valid values are 0,1,2
  	 * 
  	 * @param qos
  	 *            level.
  	 */
  	public void setQos(int qos) {
  		if (qos >= 0 && qos <= 2) {
  			this.qos = qos;
  		}
  	}
  
  	/**
  	 * @return true if messages sent to the broker should be retained by the
  	 *         broker.
  	 */
  	public boolean isRetain() {
  		return retain;
  	}
  
  	/**
  	 * Set whether any published messages should be retained by the broker.
  	 * 
  	 * @param retain
  	 *            true to retain.
  	 */
  	public void setRetain(boolean retain) {
  		this.retain = retain;
  	}
  
  	/**
  	 * @return true if messages are sent asynchronously.
  	 */
  	public boolean isAsync() {
  		return async;
  	}
  
  	/**
  	 * Set whether messages should be sent synchronously (the message is sent
  	 * and the thread waits until delivery to the broker has completed) or
  	 * asynchronously (the message is sent and the sendign thread does not wait
  	 * for delivery completion). In the case of async, the sending thread
  	 * currently does not receive any feedback when delivery is completed.
  	 * 
  	 * @param async
  	 */
  	public void setAsync(boolean async) {
  		this.async = async;
  	}
  
  	/**
  	 * Set client id to use when connecting to the broker. If none is specified,
  	 * a default is generated.
  	 * 
  	 * @param value
  	 *            clientId to use.
  	 */
  	public void setClientId(String value) {
  		this.clientId = value;
  	}
  
  	/**
  	 * Open an MQTT client connection.
  	 * 
  	 * @throws Exception
  	 */
  	private void openConnection() throws Exception {
  
  		try {
  			if (client != null && client.isConnected()) {
  				return;
  			}
  
  			if (StringUtils.isBlank(url)) {
  				throw new Exception("Missing url.");
  			}
  
  			if (client == null) {
  				if (StringUtils.isBlank(clientId) || clientId.length() > 23) {
  					clientId = MqttClient.generateClientId();
  				}
  
  				String tmpDir = System.getProperty("java.io.tmpdir");
  				MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir + "/" + name);
  				logger.debug("Creating new client for '{}' using id '{}' and file store '{}'", new Object[] { url, clientId,
  						tmpDir + "/" + name });
  				client = new MqttClient(url, clientId, dataStore);
  				client.setCallback(this);
  			}
  
  			MqttConnectOptions options = new MqttConnectOptions();
  
  			if (!StringUtils.isBlank(user)) {
  				options.setUserName(user);
  			}
  