import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Semaphore;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
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;
// TODO: add private Sal salBroker
private final ConcurrentMap<Class<?>, RoutedRpcRegistration<?>> rpcRegistrations = new ConcurrentHashMap<>();
private final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
- private volatile CONTEXT_STATE state = CONTEXT_STATE.INITIALIZATION;
+ private volatile ContextState state = ContextState.INITIALIZATION;
private final DeviceInfo deviceInfo;
private final DeviceContext deviceContext;
private final ExtensionConverterProvider extensionConverterProvider;
*/
@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
tracker.release();
final long xid = getXid().getValue();
LOG.trace("Removed request context with xid {}", xid);
- messageSpy.spyMessage(RpcContextImpl.class, MessageSpy.STATISTIC_GROUP.REQUEST_STACK_FREED);
+ messageSpy.spyMessage(RpcContextImpl.class, MessageSpy.StatisticsGroup.REQUEST_STACK_FREED);
}
};
}
return this.rpcRegistrations.isEmpty();
}
- @Override
- public CONTEXT_STATE getState() {
- return this.state;
- }
-
@Override
public ServiceGroupIdentifier getServiceIdentifier() {
return this.deviceInfo.getServiceIdentifier();
@Override
public ListenableFuture<Void> stopClusterServices() {
- if (CONTEXT_STATE.TERMINATION.equals(this.state)) {
+ if (ContextState.TERMINATION.equals(this.state)) {
return Futures.immediateCancelledFuture();
}
@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) {
+ if (isStatisticsRpcEnabled && !deviceContext.canUseSingleLayerSerialization()) {
MdSalRegistrationUtils.registerStatCompatibilityServices(
this,
deviceContext,
convertorExecutor);
}
+ mastershipChangeListener.onMasterRoleAcquired(deviceInfo, ContextChainMastershipState.RPC_REGISTRATION);
return true;
}
}