Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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 io.fabric8.camel;
 
 import  org.apache.camel.Endpoint;
 import  org.apache.camel.impl.ProducerCache;
 import  org.apache.camel.util.ObjectHelper;
 import  org.apache.camel.util.ServiceHelper;
 import  org.apache.camel.util.URISupport;
 import  org.apache.commons.logging.Log;
 import  org.apache.commons.logging.LogFactory;
 
 import java.util.Map;

The FABRIC camel component for providing endpoint discovery, clustering and load balancing.
 
 public class FabricComponent extends ZKComponentSupport {
     private static final transient Log LOG = LogFactory.getLog(FabricComponent.class);
 
     private String zkRoot = "/fabric/registry/camel/endpoints";
     private ProducerCache producerCache;
     private int cacheSize = 1000;
 
 
     public String getZkRoot() {
         return ;
     }
 
     public void setZkRoot(String zkRoot) {
         this. = zkRoot;
     }
 
     public int getCacheSize() {
         return ;
     }
 
     public void setCacheSize(int cacheSize) {
         this. = cacheSize;
     }
 
     public ProducerCache getProducerCache() {
         return ;
     }
 
     public void setProducerCache(ProducerCache producerCache) {
         this. = producerCache;
     }
 
         return ;
     }
 
     public void setLoadBalancerFactory(LoadBalancerFactory loadBalancerFactory) {
         this. = loadBalancerFactory;
     }
 
     //  Implementation methods
     //-------------------------------------------------------------------------
 
 
     @Override
     protected void doStart() throws Exception {
         super.doStart();
 
         if ( == null) {
              = new ProducerCache(thisgetCamelContext(), );
         }
         ServiceHelper.startService();
     }
 
     @Override
     protected void doStop() throws Exception {
         ServiceHelper.stopService();
 
         super.doStop();
     }
 
     @Override
     protected Endpoint createEndpoint(String uriString remainingMap<StringObjectparamsthrows Exception {
         int idx = remaining.indexOf(':');
         if (idx > 0) {
            // we are registering a regular endpoint
            String name = remaining.substring(0, idx);
            // need to replace the "0.0.0.0" with the host and port
            String childUri = replaceAnyIpAddress(remaining.substring(idx + 1));
            // we need to apply the params here
            if (params != null && params.size() > 0) {
                childUri = childUri + "?" + URISupport.createQueryString(params);
            }
            return new FabricPublisherEndpoint(urithisnamechildUri);
        } else {
            return new FabricLocatorEndpoint(urithisremaining);
        }
    }
    protected String getFabricPath(String name) {
        String path = name;
        if (ObjectHelper.isNotEmpty()) {
            path =  + "/" + name;
        }
        return path;
    }
    protected String replaceAnyIpAddress(String uri) {
        String result = uri;
        //TODO do we need to support the IPV6 ?
        if (uri.indexOf("0.0.0.0") > 0) {
            try {
                String hostAddress = InetAddress.getLocalHost().getHostAddress();
                result = uri.replace("0.0.0.0"hostAddress);
            } catch (UnknownHostException ex) {
                .warn("Cannot find the local host name, due to {0}"ex);
            }
        }
        return result;
    }
New to GrepCode? Check out our FAQ X