+
+ @VisibleForTesting
+ boolean isEmptyRpcRegistrations() {
+ return this.rpcRegistrations.isEmpty();
+ }
+
+ @Override
+ public CONTEXT_STATE getState() {
+ return this.state;
+ }
+
+ @Override
+ public ServiceGroupIdentifier getServiceIdentifier() {
+ return this.deviceInfo.getServiceIdentifier();
+ }
+
+ @Override
+ public DeviceInfo getDeviceInfo() {
+ return this.deviceInfo;
+ }
+
+ @Override
+ public ListenableFuture<Void> stopClusterServices() {
+ if (CONTEXT_STATE.TERMINATION.equals(this.state)) {
+ return Futures.immediateCancelledFuture();
+ }
+
+ return Futures.transform(Futures.immediateFuture(null), new Function<Object, Void>() {
+ @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());
+ }
+ }
+
+ return null;
+ }
+ });
+ }
+
+ @Override
+ public boolean onContextInstantiateService(final MastershipChangeListener mastershipChangeListener) {
+
+ MdSalRegistrationUtils.registerServices(this, deviceContext, extensionConverterProvider, convertorExecutor);
+
+ if (isStatisticsRpcEnabled && !deviceContext.canUseSingleLayerSerialization()) {
+ MdSalRegistrationUtils.registerStatCompatibilityServices(
+ this,
+ deviceContext,
+ notificationPublishService,
+ convertorExecutor);
+ }
+
+ return true;
+ }