import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipState;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.MastershipChangeListener;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
*/
@Override
public void close() {
- //NOOP
+ if (ContextState.TERMINATION.equals(state)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("RpcContext for node {} is already in TERMINATION state.", getDeviceInfo().getLOGValue());
+ }
+ } else {
+ this.state = ContextState.TERMINATION;
+ unregisterRPCs();
+ }
+ }
+
+ private void unregisterRPCs() {
+ for (final Iterator<Entry<Class<?>, RoutedRpcRegistration<?>>> iterator = Iterators
+ .consumingIterator(rpcRegistrations.entrySet().iterator()); iterator.hasNext(); ) {
+ final RoutedRpcRegistration<?> rpcRegistration = iterator.next().getValue();
+ rpcRegistration.unregisterPath(NodeContext.class, nodeInstanceIdentifier);
+ rpcRegistration.close();
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Closing RPC Registration of service {} for device {}.", rpcRegistration.getServiceType().getSimpleName(),
+ nodeInstanceIdentifier.getKey().getId().getValue());
+ }
+ }
}
@Override
return this.rpcRegistrations.isEmpty();
}
- @Override
- public ContextState getState() {
- return this.state;
- }
-
@Override
public ServiceGroupIdentifier getServiceIdentifier() {
return this.deviceInfo.getServiceIdentifier();
@Nullable
@Override
public Void apply(@Nullable Object input) {
- for (final Iterator<Entry<Class<?>, RoutedRpcRegistration<?>>> iterator = Iterators
- .consumingIterator(rpcRegistrations.entrySet().iterator()); iterator.hasNext(); ) {
- final RoutedRpcRegistration<?> rpcRegistration = iterator.next().getValue();
- rpcRegistration.unregisterPath(NodeContext.class, nodeInstanceIdentifier);
- rpcRegistration.close();
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("Closing RPC Registration of service {} for device {}.", rpcRegistration.getServiceType().getSimpleName(),
- nodeInstanceIdentifier.getKey().getId().getValue());
- }
- }
-
+ unregisterRPCs();
return null;
}
});
@Override
public boolean onContextInstantiateService(final MastershipChangeListener mastershipChangeListener) {
-
+ LOG.info("Starting rpc context cluster services for node {}", deviceInfo.getLOGValue());
MdSalRegistrationUtils.registerServices(this, deviceContext, extensionConverterProvider, convertorExecutor);
if (isStatisticsRpcEnabled && !deviceContext.canUseSingleLayerSerialization()) {
convertorExecutor);
}
+ mastershipChangeListener.onMasterRoleAcquired(deviceInfo, ContextChainMastershipState.RPC_REGISTRATION);
return true;
}
}