/**
 * Copyright (C) FuseSource, Inc.
 * http://fusesource.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fusesource.fabric.camel;

import org.apache.camel.impl.DefaultComponent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.fusesource.fabric.zookeeper.IZKClient;
import org.fusesource.fabric.zookeeper.internal.ZKClient;
import org.linkedin.util.clock.Timespan;

/**
 */
public abstract class ZKComponentSupport extends DefaultComponent {
    private static final transient Log LOG = LogFactory.getLog(MasterComponent.class);
    private IZKClient zkClient;
    private boolean shouldCloseZkClient = false;
    private long maximumConnectionTimeout = 10 * 1000L;

    public IZKClient getZkClient() {
        return zkClient;
    }

    public void setZkClient(IZKClient zkClient) {
        this.zkClient = zkClient;
    }

    public boolean isShouldCloseZkClient() {
        return shouldCloseZkClient;
    }

    public void setShouldCloseZkClient(boolean shouldCloseZkClient) {
        this.shouldCloseZkClient = shouldCloseZkClient;
    }

    public long getMaximumConnectionTimeout() {
        return maximumConnectionTimeout;
    }

    public void setMaximumConnectionTimeout(long maximumConnectionTimeout) {
        this.maximumConnectionTimeout = maximumConnectionTimeout;
    }

    @Override
    protected void doStart() throws Exception {
        super.doStart();
        if (zkClient == null) {
            try {
                zkClient = (IZKClient) getCamelContext().getRegistry().lookup("zkClient");
            } catch (Exception exception) {
                // try to get the zkClient from the OSGi service registry
                zkClient = (IZKClient) getCamelContext().getRegistry().lookup(IZKClient.class.getName());
            }
            if (zkClient != null) {
                LOG.debug("IZKClient found in camel registry. " + zkClient);
            }
        }
        if (zkClient == null) {
            String connectString = System.getProperty("zookeeper.url", "localhost:2181");
            LOG.debug("IZKClient not find in camel registry, creating new with connection " + connectString);
            ZKClient client = new ZKClient(connectString, Timespan.parse("10s"), null);
            LOG.debug("Starting IZKClient " + zkClient);
            client.start();
            zkClient = client;
            setShouldCloseZkClient(true);
        }
        // ensure we are started
        zkClient.waitForConnected(new Timespan(getMaximumConnectionTimeout()));
    }

    @Override
    protected void doStop() throws Exception {
        super.doStop();
        if (zkClient != null && isShouldCloseZkClient()) {
            zkClient.close();
        }
    }

}

@@ -1100,16 +1100,157 @@
 class);%0A
+    private static final String ZOOKEEPER_URL = %22zookeeper.url%22;%0A    private static final String ZOOKEEPER_PASSWORD = %22zookeeper.password%22;%0A%0A
     priv
@@ -2695,31 +2695,29 @@
 roperty(
-%22zookeeper.url%22
+ZOOKEEPER_URL
 , %22local
@@ -2725,24 +2725,94 @@
 ost:2181%22);%0A
+            String password = System.getProperty(ZOOKEEPER_PASSWORD);%0A
             
@@ -2909,16 +2909,16 @@
 tring);%0A
-
         
@@ -2997,16 +2997,135 @@
  null);%0A
+            if (password != null && !password.isEmpty()) %7B%0A                client.setPassword(password);%0A            %7D%0A
         
@@ -3594,11 +3594,10 @@
 %7D%0A    %7D%0A
-%0A
 %7D%0A

Add support for specifying zookeeper password via system properties.