X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2FMDController.java;h=1ba75ed1c32a1c537e5a4d6356f1ae0fd7e3b44e;hb=674739da4facd809c4fa6e776531dc7bb1498522;hp=d450573cf89f18d7c8f8b6c803119ce7d83654ea;hpb=bfedb8bc96ae3e517a1b02267942f548604c52be;p=openflowplugin.git diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java index d450573cf8..1ba75ed1c3 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java @@ -8,13 +8,22 @@ package org.opendaylight.openflowplugin.openflow.md.core; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; +import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; +import org.opendaylight.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,26 +33,39 @@ import com.google.common.collect.Lists; * @author mirehak * */ -public class MDController { +public class MDController implements IMDController { - private static final Logger LOG = LoggerFactory - .getLogger(MDController.class); + private static final Logger LOG = LoggerFactory.getLogger(MDController.class); private SwitchConnectionProvider switchConnectionProvider; + private ConcurrentMap, Collection> messageListeners; + + public Map, Collection> getMessageListeners() { + return messageListeners; + } + + + public void init() { + LOG.debug("Initializing!"); + this.messageListeners = new ConcurrentHashMap, Collection>(); + // Push the updated Listeners to Session Manager which will be then picked up by ConnectionConductor eventually + OFSessionUtil.getSessionManager().setListenerMapping(messageListeners); + } + /** - * @param switchConnectionProvider the switchConnectionProvider to set + * @param switchConnectionProvider + * the switchConnectionProvider to set */ - public void setSwitchConnectionProvider( - SwitchConnectionProvider switchConnectionProvider) { + public void setSwitchConnectionProvider(SwitchConnectionProvider switchConnectionProvider) { this.switchConnectionProvider = switchConnectionProvider; } /** - * @param switchConnectionProviderToUnset the switchConnectionProvider to unset + * @param switchConnectionProviderToUnset + * the switchConnectionProvider to unset */ - public void unsetSwitchConnectionProvider( - SwitchConnectionProvider switchConnectionProviderToUnset) { + public void unsetSwitchConnectionProvider(SwitchConnectionProvider switchConnectionProviderToUnset) { if (this.switchConnectionProvider == switchConnectionProviderToUnset) { this.switchConnectionProvider = null; } @@ -56,7 +78,7 @@ public class MDController { */ public void start() { LOG.debug("starting .."); - LOG.debug("switchConnectionProvider: "+switchConnectionProvider); + LOG.debug("switchConnectionProvider: " + switchConnectionProvider); // setup handler SwitchConnectionHandler switchConnectionHandler = new SwitchConnectionHandlerImpl(); switchConnectionProvider.setSwitchConnectionHandler(switchConnectionHandler); @@ -68,8 +90,8 @@ public class MDController { /** * @return wished connections configurations */ - private Collection getConnectionConfiguration() { - //TODO:: get config from state manager + private static Collection getConnectionConfiguration() { + // TODO:: get config from state manager ConnectionConfiguration configuration = ConnectionConfigurationFactory.getDefault(); return Lists.newArrayList(configuration); } @@ -82,6 +104,12 @@ public class MDController { */ public void stop() { LOG.debug("stopping"); + Future> srvStopped = switchConnectionProvider.shutdown(); + try { + srvStopped.get(5000, TimeUnit.MILLISECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + LOG.error(e.getMessage(), e); + } } /** @@ -94,4 +122,30 @@ public class MDController { // do nothing } + @Override + public void addMessageListener(Class messageType, IMDMessageListener listener) { + + Collection existingValues = messageListeners.get(messageType); + if (existingValues == null) { + existingValues = new ArrayList(); + messageListeners.put(messageType, existingValues); + } + existingValues.add(listener); + LOG.debug("{} is now listened by {}", messageType, listener); + } + + @Override + public void removeMessageListener(Class messageType, IMDMessageListener listener) { + + Collection values = messageListeners.get(messageType); + if (values != null) { + values.remove(listener); + if (values.size() == 0) { + messageListeners.remove(messageType); + } + LOG.debug("{} is now removed", listener); + } + } + + }