X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fforwarding%2Fstaticrouting%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwarding%2Fstaticrouting%2Finternal%2FStaticRoutingImplementation.java;fp=opendaylight%2Fforwarding%2Fstaticrouting%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwarding%2Fstaticrouting%2Finternal%2FStaticRoutingImplementation.java;h=bccdea416208ef27d30294b9f7ddcebf83a77ba2;hb=a2e03732c76b35b28622be16bd3c1c0c5bd7c2b5;hp=4afd4fb8e444136562b2d59fff79728c74bc763f;hpb=4731ee462f09ad75d31a175b0dd5abfa11eb2b6a;p=controller.git diff --git a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java index 4afd4fb8e4..bccdea4162 100644 --- a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java +++ b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java @@ -24,8 +24,11 @@ import java.util.Map; import java.util.Set; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -55,9 +58,6 @@ import org.slf4j.LoggerFactory; /** * Static Routing feature provides the bridge between SDN and Non-SDN networks. - * - * - * */ public class StaticRoutingImplementation implements IfNewHostNotify, IForwardingStaticRouting, IObjectReader, IConfigurationContainerAware, @@ -75,6 +75,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify, private IClusterContainerServices clusterContainerService = null; private Set staticRoutingAware = Collections .synchronizedSet(new HashSet()); + private ExecutorService executor; void setStaticRoutingAware(IStaticRoutingAware s) { if (this.staticRoutingAware != null) { @@ -235,43 +236,53 @@ public class StaticRoutingImplementation implements IfNewHostNotify, } } - private class NotifyStaticRouteThread extends Thread { + private class NotifyStaticRouteWorker implements Callable { private StaticRoute staticRoute; private boolean added; - public NotifyStaticRouteThread(StaticRoute s, boolean update) { + public NotifyStaticRouteWorker(StaticRoute s, boolean update) { this.staticRoute = s; this.added = update; } - public void run() { + @Override + public Object call() throws Exception { if (!added || (staticRoute.getType() == StaticRoute.NextHopType.SWITCHPORT)) { notifyStaticRouteUpdate(staticRoute, added); } else { - HostNodeConnector host = hostTracker.hostQuery(staticRoute - .getNextHopAddress()); + InetAddress nh = staticRoute.getNextHopAddress(); + HostNodeConnector host = hostTracker.hostQuery(nh); if (host == null) { - Future future = hostTracker - .discoverHost(staticRoute.getNextHopAddress()); + log.debug("Next hop {} is not present, try to discover it", nh.getHostAddress()); + Future future = hostTracker.discoverHost(nh); if (future != null) { try { host = future.get(); } catch (Exception e) { - log.error("",e); + log.error("", e); } } } if (host != null) { + log.debug("Next hop {} is found", nh.getHostAddress()); staticRoute.setHost(host); notifyStaticRouteUpdate(staticRoute, added); + } else { + log.debug("Next hop {} is still not present, try again later", nh.getHostAddress()); } } + return null; } } private void checkAndUpdateListeners(StaticRoute staticRoute, boolean added) { - new NotifyStaticRouteThread(staticRoute, added).start(); + NotifyStaticRouteWorker worker = new NotifyStaticRouteWorker(staticRoute, added); + try { + executor.submit(worker); + } catch (Exception e) { + log.error("got Exception ", e); + } } private void notifyHostUpdate(HostNodeConnector host, boolean added) { @@ -440,7 +451,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify, //staticRoutes = new ConcurrentHashMap(); allocateCaches(); retrieveCaches(); - + this.executor = Executors.newFixedThreadPool(1); if (staticRouteConfigs.isEmpty()) loadConfiguration(); @@ -494,10 +505,12 @@ public class StaticRoutingImplementation implements IfNewHostNotify, * */ void stop() { + executor.shutdown(); } @Override public Status saveConfiguration() { return this.saveConfig(); } + }