X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fsession%2FSessionManagerOFImpl.java;h=afda07fc38961ec1c24156b9a0082811d47cfd36;hb=19199462c5e6e100d03c6a70081d673df3b00a59;hp=71172f4763f72b15018063aef1587e9881fdf8e7;hpb=674739da4facd809c4fa6e776531dc7bb1498522;p=openflowplugin.git diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java index 71172f4763..afda07fc38 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java @@ -8,32 +8,46 @@ package org.opendaylight.openflowplugin.openflow.md.core.session; +import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.controller.sal.binding.api.data.DataProviderService; import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; -import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageListener; +import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator; import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher; +import org.opendaylight.openflowplugin.openflow.md.core.TranslatorKey; +import org.opendaylight.openflowplugin.openflow.md.queue.PopListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.concepts.util.ListenerRegistry; import org.opendaylight.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.util.concurrent.ListeningExecutorService; + /** * @author mirehak */ public class SessionManagerOFImpl implements SessionManager { - private static final Logger LOG = LoggerFactory.getLogger(SessionManagerOFImpl.class); + protected static final Logger LOG = LoggerFactory.getLogger(SessionManagerOFImpl.class); private static SessionManagerOFImpl instance; - private ConcurrentHashMap sessionLot; - private Map, Collection> listenerMapping; + private ConcurrentHashMap sessionLot; + private Map>>> translatorMapping; + private Map, Collection>> popListenerMapping; + + protected ListenerRegistry sessionListeners; + private NotificationProviderService notificationProviderService; - private final ListenerRegistry sessionListeners = new ListenerRegistry<>(); + private DataProviderService dataProviderService; + private ListeningExecutorService rpcPool; + /** * @return singleton instance @@ -44,18 +58,28 @@ public class SessionManagerOFImpl implements SessionManager { } return instance; } + + /** + * close and release singleton instace + */ + public static synchronized void releaseInstance() { + instance.close(); + instance = null; + } private SessionManagerOFImpl() { + LOG.debug("singleton creating"); sessionLot = new ConcurrentHashMap<>(); + sessionListeners = new ListenerRegistry<>(); } @Override - public SessionContext getSessionContext(SwitchConnectionDistinguisher sessionKey) { + public SessionContext getSessionContext(SwitchSessionKeyOF sessionKey) { return sessionLot.get(sessionKey); } @Override - public void invalidateSessionContext(SwitchConnectionDistinguisher sessionKey) { + public void invalidateSessionContext(SwitchSessionKeyOF sessionKey) { SessionContext context = getSessionContext(sessionKey); if (context == null) { LOG.warn("context for invalidation not found"); @@ -65,7 +89,7 @@ public class SessionManagerOFImpl implements SessionManager { } context.getPrimaryConductor().disconnect(); context.setValid(false); - sessionLot.remove(sessionKey); + removeSessionContext(context); // TODO:: notify listeners } } @@ -79,13 +103,21 @@ public class SessionManagerOFImpl implements SessionManager { invalidateAuxiliary(sessionContext, auxEntry.getKey(), true); } sessionContext.setValid(false); - sessionLot.remove(sessionContext.getSessionKey(), sessionContext); + removeSessionContext(sessionContext); // TODO:: notify listeners } } + private void removeSessionContext(SessionContext sessionContext) { + if (LOG.isDebugEnabled()) { + LOG.debug("removing session: {}", Arrays.toString(sessionContext.getSessionKey().getId())); + } + sessionLot.remove(sessionContext.getSessionKey(), sessionContext); + sessionNotifier.onSessionRemoved(sessionContext); + } + @Override - public void addSessionContext(SwitchConnectionDistinguisher sessionKey, SessionContext context) { + public void addSessionContext(SwitchSessionKeyOF sessionKey, SessionContext context) { sessionLot.put(sessionKey, context); sessionNotifier.onSessionAdded(sessionKey, context); @@ -93,7 +125,7 @@ public class SessionManagerOFImpl implements SessionManager { } @Override - public void invalidateAuxiliary(SwitchConnectionDistinguisher sessionKey, + public void invalidateAuxiliary(SwitchSessionKeyOF sessionKey, SwitchConnectionDistinguisher connectionCookie) { SessionContext context = getSessionContext(sessionKey); invalidateAuxiliary(context, connectionCookie, true); @@ -131,23 +163,21 @@ public class SessionManagerOFImpl implements SessionManager { } } - /** - * @param listenerMapping - * the listenerMapping to set - */ - public void setListenerMapping(Map, Collection> listenerMapping) { - this.listenerMapping = listenerMapping; + @Override + public void setTranslatorMapping(Map>>> translatorMapping) { + this.translatorMapping = translatorMapping; } @Override public ListenerRegistration registerSessionListener(SessionListener listener) { + LOG.debug("registerSessionListener"); return sessionListeners.register(listener); } private final SessionListener sessionNotifier = new SessionListener() { @Override - public void onSessionAdded(SwitchConnectionDistinguisher sessionKey, SessionContext context) { + public void onSessionAdded(SwitchSessionKeyOF sessionKey, SessionContext context) { for (ListenerRegistration listener : sessionListeners) { try { listener.getInstance().onSessionAdded(sessionKey, context); @@ -156,11 +186,79 @@ public class SessionManagerOFImpl implements SessionManager { } } } + + @Override + public void onSessionRemoved(SessionContext context) { + for (ListenerRegistration listener : sessionListeners) { + try { + listener.getInstance().onSessionRemoved(context); + } catch (Exception e) { + LOG.error("Unhandled exeption occured while invoking onSessionRemoved on listener", e); + } + } + } }; + + + @Override + public Map>>> getTranslatorMapping() { + return this.translatorMapping; + } @Override - public Map, Collection> getListenerMapping() { - return this.listenerMapping; + public void setNotificationProviderService( + NotificationProviderService notificationProviderService) { + this.notificationProviderService = notificationProviderService; + } + @Override + public DataProviderService getDataProviderService() { + return dataProviderService; + } + + @Override + public void setDataProviderService(DataProviderService dataServiceProvider) { + this.dataProviderService = dataServiceProvider; + + } + + @Override + public NotificationProviderService getNotificationProviderService() { + return notificationProviderService; + } + + @Override + public Map, Collection>> getPopListenerMapping() { + return popListenerMapping; + } + + @Override + public void setPopListenerMapping( + Map, Collection>> popListenerMapping) { + this.popListenerMapping = popListenerMapping; + } + + @Override + public void close() { + LOG.debug("close"); + sessionListeners = null; + synchronized (sessionLot) { + for (SessionContext sessionContext : sessionLot.values()) { + sessionContext.getPrimaryConductor().disconnect(); + } + // TODO: handle timeouted shutdown + rpcPool.shutdown(); + } + } + + @Override + public void setRpcPool(ListeningExecutorService rpcPool) { + this.rpcPool = rpcPool; + } + + @Override + public ListeningExecutorService getRpcPool() { + return rpcPool; + } }