- added AutoCloseable interface to MDController, MessageCountCommandProvider, SalRegistrationManager, SessionManager
- added init/start and close/destroy logging
- added closing/destroying upon bundle stop
Change-Id: I5fe94bbcfa37225790b68d2e1ef01ffb1f6ab675
Signed-off-by: Michal Rehak <mirehak@cisco.com>
*
*/
public void init() {
+ logger.debug("init");
}
/**
*
*/
public void destroy() {
+ logger.debug("destroy");
pluginProvider.close();
super.destroy();
}
@Override
public void start(BundleContext arg0) {
+ logger.debug("start");
super.start(arg0);
pluginProvider.setContext(arg0);
}
* Object
*/
public Object[] getGlobalImplementations() {
- //TODO:: is MDController still needed here?
- Object[] res = { MDController.class, pluginProvider };
+ Object[] res = { pluginProvider };
return res;
}
* as the same routine can configure multiple implementations
*/
public void configureGlobalInstance(Component c, Object imp) {
-
if (imp == pluginProvider) {
// c.setInterface(new String[] { IDiscoveryListener.class.getName(),
// IContainerListener.class.getName(),
package org.opendaylight.openflowplugin.openflow.md;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+/**
+ * @deprecated seems there is no use for this interface
+ */
+@Deprecated
public interface SwitchInventory {
ModelDrivenSwitch getSwitch(NodeRef node);
* @author mirehak
*
*/
-public class MDController implements IMDController {
+public class MDController implements IMDController, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(MDController.class);
* provisioning of translator mapping
*/
public void init() {
- LOG.debug("Initializing!");
+ LOG.debug("init");
messageTranslators = new ConcurrentHashMap<>();
popListeners = new ConcurrentHashMap<>();
//TODO: move registration to factory
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOG.error(e.getMessage(), e);
}
+ close();
}
/**
*
*/
public void destroy() {
- // do nothing
+ close();
}
@Override
MessageSpy<OfHeader, DataObject> messageSpyCounter) {
this.messageSpyCounter = messageSpyCounter;
}
-
+
+ @Override
+ public void close() {
+ LOG.debug("close");
+ messageSpyCounter = null;
+ messageTranslators = null;
+ popListeners = null;
+ switchConnectionProvider = null;
+ OFSessionUtil.releaseSessionManager();
+ }
}
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.openflowplugin.openflow.md.queue.MessageCountDumper;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
*/
-public class MessageCountCommandProvider implements CommandProvider {
+public class MessageCountCommandProvider implements CommandProvider, AutoCloseable {
+
+ private static Logger LOG = LoggerFactory
+ .getLogger(MessageCountCommandProvider.class);
private boolean sessionInitiated;
private BundleContext ctx;
private MessageCountDumper provider;
+
+ private ServiceRegistration commandRegistration;
/**
* @param ctx
* @param session
*/
public void onSessionInitiated(ProviderContext session) {
- ctx.registerService(CommandProvider.class.getName(), this, null);
+ LOG.debug("onSessionInitiated");
+ commandRegistration = ctx.registerService(CommandProvider.class.getName(), this, null);
this.sessionInitiated = true;
}
ci.println("Session not initiated, try again in a few seconds");
}
}
+
+ @Override
+ public void close() {
+ LOG.debug("close");
+ if (commandRegistration != null) {
+ commandRegistration.unregister();
+ }
+ ctx = null;
+ provider = null;
+ sessionInitiated = false;
+ }
}
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.RpcService;
import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* OFPlugin provider implementation
*/
public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseable {
-
+
+ private static Logger LOG = LoggerFactory.getLogger(OpenflowPluginProvider.class);
+
private BindingAwareBroker broker;
private BundleContext context;
private MessageObservatory<OfHeader, DataObject> messageCountProvider;
+ private SalRegistrationManager registrationManager;
+
public void unsetSwitchConnectionProvider() {
switchConnectionProvider = null;
}
this.context = context;
}
- SalRegistrationManager registrationManager = new SalRegistrationManager();
-
-
@Override
public void onSessionInitiated(ProviderContext session) {
+ LOG.debug("onSessionInitiated");
messageCountProvider = new MessageSpyCounterImpl();
+ registrationManager = new SalRegistrationManager();
registrationManager.onSessionInitiated(session);
mdController = new MDController();
mdController.setSwitchConnectionProvider(switchConnectionProvider);
@Override
public void close() {
+ LOG.debug("close");
mdController.stop();
+ mdController = null;
+ registrationManager.close();
+ registrationManager = null;
+ messageCountCommandProvider.close();
+ messageCountCommandProvider = null;
}
@Override
/**
* session and inventory listener implementation
*/
-public class SalRegistrationManager implements SessionListener, SwitchInventory {
+public class SalRegistrationManager implements SessionListener, AutoCloseable {
private final static Logger LOG = LoggerFactory.getLogger(SalRegistrationManager.class);
- Map<InstanceIdentifier<Node>, ModelDrivenSwitch> salSwitches = new ConcurrentHashMap<>();
-
private ProviderContext providerContext;
private NotificationProviderService publishService;
}
public void onSessionInitiated(ProviderContext session) {
+ LOG.debug("onSessionInitiated");
this.providerContext = session;
this.publishService = session.getSALService(NotificationProviderService.class);
this.dataService = session.getSALService(DataProviderService.class);
getSessionManager().setNotificationProviderService(publishService);
getSessionManager().setDataProviderService(dataService);
LOG.debug("SalRegistrationManager initialized");
-
}
@Override
NodeId nodeId = nodeIdFromDatapathId(datapathId);
ModelDrivenSwitchImpl ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier, context);
LLDPSpeaker.getInstance().addModelDrivenSwitch(identifier, ofSwitch);
- salSwitches.put(identifier, ofSwitch);
ofSwitch.register(providerContext);
LOG.debug("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId.toString());
return builder.build();
}
- @Override
- public ModelDrivenSwitch getSwitch(NodeRef node) {
- return salSwitches.get(node.getValue());
- }
-
public static InstanceIdentifier<Node> identifierFromDatapathId(BigInteger datapathId) {
NodeKey nodeKey = nodeKeyFromDatapathId(datapathId);
InstanceIdentifierBuilder<Node> builder = InstanceIdentifier.builder(Nodes.class).child(Node.class,nodeKey);
public SessionManager getSessionManager() {
return OFSessionUtil.getSessionManager();
}
+
+ @Override
+ public void close() {
+ LOG.debug("close");
+ dataService = null;
+ providerContext = null;
+ publishService = null;
+ }
}
public static SessionManager getSessionManager() {
return SessionManagerOFImpl.getInstance();
}
-
+
+ /**
+ * release session manager singleton instance
+ */
+ public static void releaseSessionManager() {
+ SessionManagerOFImpl.releaseInstance();
+ }
+
/**
* @return session manager listener Map
*/
/**
* @author mirehak
*/
-public interface SessionManager {
+public interface SessionManager extends AutoCloseable {
/**
* @param sessionKey
public class SessionManagerOFImpl implements SessionManager {
protected static final Logger LOG = LoggerFactory.getLogger(SessionManagerOFImpl.class);
- private static SessionManager instance;
+ private static SessionManagerOFImpl instance;
private ConcurrentHashMap<SwitchConnectionDistinguisher, SessionContext> sessionLot;
private Map<TranslatorKey, Collection<IMDMessageTranslator<OfHeader, List<DataObject>>>> translatorMapping;
private Map<Class<? extends DataObject>, Collection<PopListener<DataObject>>> popListenerMapping;
- protected final ListenerRegistry<SessionListener> sessionListeners = new ListenerRegistry<>();
+ protected ListenerRegistry<SessionListener> sessionListeners;
private NotificationProviderService notificationProviderService;
private DataProviderService dataProviderService;
}
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
@Override
public ListenerRegistration<SessionListener> registerSessionListener(SessionListener listener) {
+ LOG.debug("registerSessionListener");
return sessionListeners.register(listener);
}
Map<Class<? extends DataObject>, Collection<PopListener<DataObject>>> popListenerMapping) {
this.popListenerMapping = popListenerMapping;
}
-
+
+ @Override
+ public void close() {
+ LOG.debug("close");
+ sessionListeners = null;
+ synchronized (sessionLot) {
+ for (SessionContext sessionContext : sessionLot.values()) {
+ sessionContext.getPrimaryConductor().disconnect();
+ }
+ }
+ }
}