You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/01/23 09:41:19 UTC

[camel] 04/04: Fixed formatting to comply with rules

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 3d8e61214a9902c5a888a7f875e02316f2a6cd27
Author: Max Fortun <Ma...@wsj.com>
AuthorDate: Mon Jan 22 12:12:25 2018 -0500

    Fixed formatting to comply with rules
---
 .../camel/component/dns/policy/DnsActivation.java  | 229 +++++++------
 .../component/dns/policy/DnsActivationPolicy.java  | 374 +++++++++++----------
 .../component/dns/policy/DnsActivationTest.java    |  19 +-
 3 files changed, 332 insertions(+), 290 deletions(-)

diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/policy/DnsActivation.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/policy/DnsActivation.java
index 4eb8ad5..b7fa1d5 100644
--- a/components/camel-dns/src/main/java/org/apache/camel/component/dns/policy/DnsActivation.java
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/policy/DnsActivation.java
@@ -1,18 +1,37 @@
-package org.apache.camel.component.dns.policy;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
 
-import javax.naming.directory.Attributes;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.InitialDirContext;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
+package org.apache.camel.component.dns.policy;
 
-import java.net.NetworkInterface;
 import java.net.InetAddress;
+import java.net.NetworkInterface;
 import java.net.UnknownHostException;
 
-import java.util.List;
 import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.InitialDirContext;
+
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -22,102 +41,102 @@ import org.slf4j.LoggerFactory;
  */
 
 public class DnsActivation {
-    private static final transient Logger logger = LoggerFactory.getLogger(DnsActivation.class);
-
-	private final static String[] DNS_TYPES = {"CNAME", "A"}; 
-
-	private String hostname;
-	private List<String> resolvesTo = new ArrayList<String>();
-
-	public DnsActivation() throws Exception {
-	}
-
-	public DnsActivation(String hostname, List<String> resolvesTo) throws Exception {
-		this.hostname = hostname;
-		this.resolvesTo.addAll(resolvesTo);
-	}
-
-	public void setHostname(String hostname) {
-		this.hostname = hostname;
-	}
-
-	public void setResolvesTo(List<String> resolvesTo) {
-		this.resolvesTo.addAll(resolvesTo);
-	}
-
-	public void setResolvesTo(String resolvesTo) {
-		this.resolvesTo.add(resolvesTo);
-	}
-
-	public boolean isActive() {
-		if(resolvesTo.isEmpty()) {
-			try {
-				resolvesTo.addAll(getLocalIps());
-			} catch(Exception e) {
-				logger.warn("Failed to get local ips and resolvesTo not specified. Identifying as inactive.", e);
-				return false;
-			}
-		}
-
-		logger.debug("Resolving "+hostname);
-		ArrayList<String> hostnames = new ArrayList<String>();
-		hostnames.add(hostname);
-
-		ArrayList<String> resolved = new ArrayList<String>();
-		while(!hostnames.isEmpty()) {
-			NamingEnumeration attributeEnumeration = null;
-			try {
-				String hostname = hostnames.remove(0);
-				InetAddress inetAddress = InetAddress.getByName(hostname);
-				InitialDirContext initialDirContext = new InitialDirContext();
-				Attributes attributes = initialDirContext.getAttributes("dns:/" + inetAddress.getHostName(), DNS_TYPES);
-				attributeEnumeration = attributes.getAll();
-				while(attributeEnumeration.hasMore()) {
-					Attribute attribute = (Attribute)attributeEnumeration.next();
-					String id = attribute.getID();
-					String value = (String)attribute.get();
-					if(resolvesTo.contains(value)) {
-						logger.debug(id+" = " + value + " matched. Identifying as active.");
-						return true;
-					}
-					logger.debug(id+" = " + value);
-					if(id.equals("CNAME") && !resolved.contains(value)) {
-						hostnames.add(value);
-					}
-					resolved.add(value);
-				}
-			} catch(Exception e) {
-				logger.warn(hostname, e);
-			} finally {
-				if(attributeEnumeration != null) {
-					try {
-						attributeEnumeration.close();
-					} catch(Exception e) {
-						logger.warn("Failed to close attributeEnumeration. Memory leak possible.", e);
-					}
-					attributeEnumeration = null;
-				}
-			}
-		}
-		return false;
-	}
-
-	private List<String> getLocalIps() throws Exception {
-		List<String> localIps = new ArrayList<String>();
-
-		Enumeration<NetworkInterface> networkInterfacesEnumeration = NetworkInterface.getNetworkInterfaces();
-		while(networkInterfacesEnumeration.hasMoreElements()) {
-			NetworkInterface networkInterface = networkInterfacesEnumeration.nextElement();
-
-			Enumeration<InetAddress> inetAddressesEnumeration = networkInterface.getInetAddresses();
-			while (inetAddressesEnumeration.hasMoreElements()) {
-				InetAddress inetAddress = inetAddressesEnumeration.nextElement();
-				String ip = inetAddress.getHostAddress();
-				logger.debug("Local ip: "+ip);
-				localIps.add(ip);
-			}
-		}
-		return localIps;
-	}
+    private static final transient String[] DNS_TYPES = {"CNAME", "A"}; 
+    private static final transient Logger LOG = LoggerFactory.getLogger(DnsActivation.class);
+
+
+    private String hostname;
+    private List<String> resolvesTo = new ArrayList<String>();
+
+    public DnsActivation() throws Exception {
+    }
+
+    public DnsActivation(String hostname, List<String> resolvesTo) throws Exception {
+        this.hostname = hostname;
+        this.resolvesTo.addAll(resolvesTo);
+    }
+
+    public void setHostname(String hostname) {
+        this.hostname = hostname;
+    }
+
+    public void setResolvesTo(List<String> resolvesTo) {
+        this.resolvesTo.addAll(resolvesTo);
+    }
+
+    public void setResolvesTo(String resolvesTo) {
+        this.resolvesTo.add(resolvesTo);
+    }
+
+    public boolean isActive() {
+        if (resolvesTo.isEmpty()) {
+            try {
+                resolvesTo.addAll(getLocalIps());
+            } catch (Exception e) {
+                LOG.warn("Failed to get local ips and resolvesTo not specified. Identifying as inactive.", e);
+                return false;
+            }
+        }
+
+        LOG.debug("Resolving " + hostname);
+        ArrayList<String> hostnames = new ArrayList<String>();
+        hostnames.add(hostname);
+
+        ArrayList<String> resolved = new ArrayList<String>();
+        while (!hostnames.isEmpty()) {
+            NamingEnumeration attributeEnumeration = null;
+            try {
+                String hostname = hostnames.remove(0);
+                InetAddress inetAddress = InetAddress.getByName(hostname);
+                InitialDirContext initialDirContext = new InitialDirContext();
+                Attributes attributes = initialDirContext.getAttributes("dns:/" + inetAddress.getHostName(), DNS_TYPES);
+                attributeEnumeration = attributes.getAll();
+                while (attributeEnumeration.hasMore()) {
+                    Attribute attribute = (Attribute)attributeEnumeration.next();
+                    String id = attribute.getID();
+                    String value = (String)attribute.get();
+                    if (resolvesTo.contains(value)) {
+                        LOG.debug(id + " = " + value + " matched. Identifying as active.");
+                        return true;
+                    }
+                    LOG.debug(id + " = " + value);
+                    if (id.equals("CNAME") && !resolved.contains(value)) {
+                        hostnames.add(value);
+                    }
+                    resolved.add(value);
+                }
+            } catch (Exception e) {
+                LOG.warn(hostname, e);
+            } finally {
+                if (attributeEnumeration != null) {
+                    try {
+                        attributeEnumeration.close();
+                    } catch (Exception e) {
+                        LOG.warn("Failed to close attributeEnumeration. Memory leak possible.", e);
+                    }
+                    attributeEnumeration = null;
+                }
+            }
+        }
+        return false;
+    }
+
+    private List<String> getLocalIps() throws Exception {
+        List<String> localIps = new ArrayList<String>();
+
+        Enumeration<NetworkInterface> networkInterfacesEnumeration = NetworkInterface.getNetworkInterfaces();
+        while (networkInterfacesEnumeration.hasMoreElements()) {
+            NetworkInterface networkInterface = networkInterfacesEnumeration.nextElement();
+
+            Enumeration<InetAddress> inetAddressesEnumeration = networkInterface.getInetAddresses();
+            while (inetAddressesEnumeration.hasMoreElements()) {
+                InetAddress inetAddress = inetAddressesEnumeration.nextElement();
+                String ip = inetAddress.getHostAddress();
+                LOG.debug("Local ip: " + ip);
+                localIps.add(ip);
+            }
+        }
+        return localIps;
+    }
 }
 
diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/policy/DnsActivationPolicy.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/policy/DnsActivationPolicy.java
index c401a38..74e6825 100644
--- a/components/camel-dns/src/main/java/org/apache/camel/component/dns/policy/DnsActivationPolicy.java
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/policy/DnsActivationPolicy.java
@@ -1,11 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.dns.policy;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.HashMap;
 import java.util.Timer;
 import java.util.TimerTask;
-import java.util.Collections;
+
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.camel.Consumer;
@@ -13,197 +31,185 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Route;
 import org.apache.camel.ServiceStatus;
-import org.apache.camel.util.ServiceHelper;
 
-import org.apache.camel.spi.RoutePolicy;
+import org.apache.camel.impl.LoggingExceptionHandler;
+
 import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.spi.RoutePolicy;
 
-import org.apache.camel.impl.LoggingExceptionHandler;
 import org.apache.camel.support.RoutePolicySupport;
 
+import org.apache.camel.util.ServiceHelper;
+
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class DnsActivationPolicy extends RoutePolicySupport {
-	private final static Logger logger = LoggerFactory.getLogger(DnsActivationPolicy.class);
-
-	private ExceptionHandler exceptionHandler;
-	
-	private DnsActivation dnsActivation;
-	private long ttl;
-
-	private Map<String,Route> routes = new ConcurrentHashMap<String, Route>();
-	private Timer timer;
-
-	public DnsActivationPolicy() throws Exception
-	{
-		dnsActivation = new DnsActivation();
-	}
-
-	public void onInit(Route route)
-	{
-		logger.debug("onInit "+route.getId());
-		routes.put(route.getId(), route);
-	}
-
-	public void onRemove(Route route)
-	{
-		logger.debug("onRemove "+route.getId());
-		// noop
-	}
-
-	@Override
-	public void onStart(Route route)
-	{
-		logger.debug("onStart "+route.getId());
-		// noop
-	}
-
-	@Override
-	public void onStop(Route route)
-	{
-		logger.debug("onStop "+route.getId());
-		// noop
-	}
-
-	@Override
-	public void onSuspend(Route route)
-	{
-		logger.debug("onSuspend "+route.getId());
-		// noop
-	}
-
-	@Override
-	public void onResume(Route route)
-	{
-		logger.debug("onResume "+route.getId());
-		// noop
-	}
-
-	public void onExchangeBegin(Route route, Exchange exchange)
-	{
-		logger.debug("onExchange start "+route.getId()+"/"+exchange.getExchangeId());
-		// noop
-	}
-
-	public void onExchangeDone(Route route, Exchange exchange)
-	{
-		logger.debug("onExchange end "+route.getId()+"/"+exchange.getExchangeId());
-		// noop
-	}
-
-	@Override
-	protected void doStart() throws Exception
-	{
-		logger.debug("doStart");
-		timer = new Timer();
-		timer.schedule(new DnsActivationTask(), 0, ttl);
-		// noop
-	}
-
-	@Override
-	protected void doStop() throws Exception
-	{
-		logger.debug("doStop");
-		if(timer != null)
-		{
-			timer.cancel();
-			timer = null;
-		}
-
-		// noop
-	}
-
-	public ExceptionHandler getExceptionHandler() {
-		if (exceptionHandler == null) {
-			exceptionHandler = new LoggingExceptionHandler(getClass());
-		}
-		return exceptionHandler;
-	}
-
-	public void setExceptionHandler(ExceptionHandler exceptionHandler) {
-		this.exceptionHandler = exceptionHandler;
-	}
-
-	public void setHostname(String hostname) {
-		dnsActivation.setHostname(hostname);
-	}
-
-	public void setResolvesTo(List<String> resolvesTo) {
-		dnsActivation.setResolvesTo(resolvesTo);
-	}
-
-	public void setResolvesTo(String resolvesTo) {
-		dnsActivation.setResolvesTo(resolvesTo);
-	}
-
-	public void setTtl(String ttl) {
-		this.ttl = Long.parseLong(ttl);
-	}
-
-	private void startRouteImpl(Route route) throws Exception {
-		ServiceStatus routeStatus = route.getRouteContext().getCamelContext().getRouteStatus(route.getId());
-
-		if(routeStatus == ServiceStatus.Stopped) {
-			logger.info("Starting "+route.getId());
-			startRoute(route);
-		} else if(routeStatus == ServiceStatus.Suspended) {
-			logger.info("Resuming "+route.getId());
-			startConsumer(route.getConsumer());
-		} else {
-			logger.debug("Nothing to do "+route.getId()+" is "+routeStatus);
-		}
-	}
-
-	private void startRoutes()
-	{
-			for(String routeId : routes.keySet()) {
-				try {
-					Route route = routes.get(routeId);
-					startRouteImpl(route);
-				} catch(Exception e) {
-					logger.warn(routeId, e);
-				}
-			}
-	}
-
-	private void stopRouteImpl(Route route) throws Exception {
-		ServiceStatus routeStatus = route.getRouteContext().getCamelContext().getRouteStatus(route.getId());
-
-		if(routeStatus == ServiceStatus.Started) {
-			logger.info("Stopping "+route.getId());
-			stopRoute(route);
-		} else {
-			logger.debug("Nothing to do "+route.getId()+" is "+routeStatus);
-		}
-	}
-
-	private void stopRoutes()
-	{
-			for(String routeId : routes.keySet()) {
-				try {
-					Route route = routes.get(routeId);
-					stopRouteImpl(route);
-				} catch(Exception e) {
-					logger.warn(routeId, e);
-				}
-			}
-	}
-
- 	class DnsActivationTask extends TimerTask {
-		public void run() {
-			try {
-				if(dnsActivation.isActive()) {
-					startRoutes();
-				} else {
-					stopRoutes();
-				}
-			}
-			catch(Exception e) {
-				logger.warn("DnsActivation TimerTask failed", e);
-			}
-		}
-	}
+    private static final transient Logger LOG = LoggerFactory.getLogger(DnsActivationPolicy.class);
+
+    private ExceptionHandler exceptionHandler;
+    
+    private DnsActivation dnsActivation;
+    private long ttl;
+
+    private Map<String, Route> routes = new ConcurrentHashMap<String, Route>();
+    private Timer timer;
+
+    public DnsActivationPolicy() throws Exception {
+        dnsActivation = new DnsActivation();
+    }
+
+    public void onInit(Route route) {
+        LOG.debug("onInit " + route.getId());
+        routes.put(route.getId(), route);
+    }
+
+    public void onRemove(Route route) {
+        LOG.debug("onRemove " + route.getId());
+        // noop
+    }
+
+    @Override
+    public void onStart(Route route) {
+        LOG.debug("onStart " + route.getId());
+        // noop
+    }
+
+    @Override
+    public void onStop(Route route) {
+        LOG.debug("onStop " + route.getId());
+        // noop
+    }
+
+    @Override
+    public void onSuspend(Route route) {
+        LOG.debug("onSuspend " + route.getId());
+        // noop
+    }
+
+    @Override
+    public void onResume(Route route) {
+        LOG.debug("onResume " + route.getId());
+        // noop
+    }
+
+    public void onExchangeBegin(Route route, Exchange exchange) {
+        LOG.debug("onExchange start " + route.getId() + "/" + exchange.getExchangeId());
+        // noop
+    }
+
+    public void onExchangeDone(Route route, Exchange exchange) {
+        LOG.debug("onExchange end " + route.getId() + "/" + exchange.getExchangeId());
+        // noop
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        LOG.debug("doStart");
+        timer = new Timer();
+        timer.schedule(new DnsActivationTask(), 0, ttl);
+        // noop
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        LOG.debug("doStop");
+        if (timer != null) {
+            timer.cancel();
+            timer = null;
+        }
+
+        // noop
+    }
+
+    public ExceptionHandler getExceptionHandler() {
+        if (exceptionHandler == null) {
+            exceptionHandler = new LoggingExceptionHandler(getClass());
+        }
+        return exceptionHandler;
+    }
+
+    public void setExceptionHandler(ExceptionHandler exceptionHandler) {
+        this.exceptionHandler = exceptionHandler;
+    }
+
+    public void setHostname(String hostname) {
+        dnsActivation.setHostname(hostname);
+    }
+
+    public void setResolvesTo(List<String> resolvesTo) {
+        dnsActivation.setResolvesTo(resolvesTo);
+    }
+
+    public void setResolvesTo(String resolvesTo) {
+        dnsActivation.setResolvesTo(resolvesTo);
+    }
+
+    public void setTtl(String ttl) {
+        this.ttl = Long.parseLong(ttl);
+    }
+
+    private void startRouteImpl(Route route) throws Exception {
+        ServiceStatus routeStatus = route.getRouteContext().getCamelContext().getRouteStatus(route.getId());
+
+        if (routeStatus == ServiceStatus.Stopped) {
+            LOG.info("Starting " + route.getId());
+            startRoute(route);
+        } else if (routeStatus == ServiceStatus.Suspended) {
+            LOG.info("Resuming " + route.getId());
+            startConsumer(route.getConsumer());
+        } else {
+            LOG.debug("Nothing to do " + route.getId() + " is " + routeStatus);
+        }
+    }
+
+    private void startRoutes() {
+        for (String routeId : routes.keySet()) {
+            try {
+                Route route = routes.get(routeId);
+                startRouteImpl(route);
+            } catch (Exception e) {
+                LOG.warn(routeId, e);
+            }
+        }
+    }
+
+    private void stopRouteImpl(Route route) throws Exception {
+        ServiceStatus routeStatus = route.getRouteContext().getCamelContext().getRouteStatus(route.getId());
+
+        if (routeStatus == ServiceStatus.Started) {
+            LOG.info("Stopping " + route.getId());
+            stopRoute(route);
+        } else {
+            LOG.debug("Nothing to do " + route.getId() + " is " + routeStatus);
+        }
+    }
+
+    private void stopRoutes() {
+        for (String routeId : routes.keySet()) {
+            try {
+                Route route = routes.get(routeId);
+                stopRouteImpl(route);
+            } catch (Exception e) {
+                LOG.warn(routeId, e);
+            }
+        }
+    }
+
+    class DnsActivationTask extends TimerTask {
+        public void run() {
+            try {
+                if (dnsActivation.isActive()) {
+                    startRoutes();
+                } else {
+                    stopRoutes();
+                }
+            } catch (Exception e) {
+                LOG.warn("DnsActivation TimerTask failed", e);
+            }
+        }
+    }
 }
 
 
diff --git a/components/camel-dns/src/test/java/org/apache/camel/component/dns/policy/DnsActivationTest.java b/components/camel-dns/src/test/java/org/apache/camel/component/dns/policy/DnsActivationTest.java
index ad74e09..1071a31 100644
--- a/components/camel-dns/src/test/java/org/apache/camel/component/dns/policy/DnsActivationTest.java
+++ b/components/camel-dns/src/test/java/org/apache/camel/component/dns/policy/DnsActivationTest.java
@@ -1,3 +1,20 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.dns.policy;
 
 import java.util.Arrays;
@@ -5,8 +22,8 @@ import java.util.List;
 
 import org.junit.Test;
 
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public class DnsActivationTest {
     @Test

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.