X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Frpc%2FRpcContextImpl.java;h=2911a89b161f2a31e9f328b8424216d5cf12000f;hb=93fa4f844b0712c35a01f16ec321693557496202;hp=d7e2bb8c52cbb663a4da76694aa158e9f3257abe;hpb=9688b3b10ee4113753705f0080b29cd30e61a85d;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java index d7e2bb8c52..2911a89b16 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -8,7 +8,7 @@ package org.opendaylight.openflowplugin.impl.rpc; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterators; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -18,11 +18,9 @@ import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Semaphore; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; @@ -34,57 +32,59 @@ import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.Messa import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider; import org.opendaylight.openflowplugin.impl.util.MdSalRegistrationUtils; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.binding.RpcService; +import org.opendaylight.yangtools.yang.common.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; class RpcContextImpl implements RpcContext { private static final Logger LOG = LoggerFactory.getLogger(RpcContextImpl.class); - private final RpcProviderRegistry rpcProviderRegistry; + private final RpcProviderService rpcProviderRegistry; private final MessageSpy messageSpy; private final Semaphore tracker; - private boolean isStatisticsRpcEnabled; + private final boolean isStatisticsRpcEnabled; // TODO: add private Sal salBroker - private final ConcurrentMap, RoutedRpcRegistration> rpcRegistrations = new ConcurrentHashMap<>(); + private final ConcurrentMap, ObjectRegistration> rpcRegistrations = + new ConcurrentHashMap<>(); private final KeyedInstanceIdentifier nodeInstanceIdentifier; private final DeviceInfo deviceInfo; private final DeviceContext deviceContext; private final ExtensionConverterProvider extensionConverterProvider; private final ConvertorExecutor convertorExecutor; private final NotificationPublishService notificationPublishService; - private ContextChainMastershipWatcher contextChainMastershipWatcher; - RpcContextImpl(@Nonnull final RpcProviderRegistry rpcProviderRegistry, + private ContextChainMastershipWatcher contextChainMastershipWatcher = null; + + RpcContextImpl(@NonNull final RpcProviderService rpcProviderRegistry, final int maxRequests, - @Nonnull final DeviceContext deviceContext, - @Nonnull final ExtensionConverterProvider extensionConverterProvider, - @Nonnull final ConvertorExecutor convertorExecutor, - @Nonnull final NotificationPublishService notificationPublishService, - boolean statisticsRpcEnabled) { + @NonNull final DeviceContext deviceContext, + @NonNull final ExtensionConverterProvider extensionConverterProvider, + @NonNull final ConvertorExecutor convertorExecutor, + @NonNull final NotificationPublishService notificationPublishService, + final boolean statisticsRpcEnabled) { this.deviceContext = deviceContext; - this.deviceInfo = deviceContext.getDeviceInfo(); - this.nodeInstanceIdentifier = deviceContext.getDeviceInfo().getNodeInstanceIdentifier(); - this.messageSpy = deviceContext.getMessageSpy(); + deviceInfo = deviceContext.getDeviceInfo(); + nodeInstanceIdentifier = deviceContext.getDeviceInfo().getNodeInstanceIdentifier(); + messageSpy = deviceContext.getMessageSpy(); this.rpcProviderRegistry = rpcProviderRegistry; this.extensionConverterProvider = extensionConverterProvider; this.notificationPublishService = notificationPublishService; this.convertorExecutor = convertorExecutor; - this.isStatisticsRpcEnabled = statisticsRpcEnabled; - this.tracker = new Semaphore(maxRequests, true); + isStatisticsRpcEnabled = statisticsRpcEnabled; + tracker = new Semaphore(maxRequests, true); } @Override public void registerRpcServiceImplementation(final Class serviceClass, final S serviceInstance) { if (!rpcRegistrations.containsKey(serviceClass)) { - final RoutedRpcRegistration routedRpcReg = - rpcProviderRegistry.addRoutedRpcImplementation(serviceClass, serviceInstance); - routedRpcReg.registerPath(NodeContext.class, nodeInstanceIdentifier); + final ObjectRegistration routedRpcReg = rpcProviderRegistry.registerRpcImplementation(serviceClass, + serviceInstance, ImmutableSet.of(nodeInstanceIdentifier)); rpcRegistrations.put(serviceClass, routedRpcReg); if (LOG.isDebugEnabled()) { LOG.debug("Registration of service {} for device {}.", @@ -96,7 +96,7 @@ class RpcContextImpl implements RpcContext { @Override public S lookupRpcService(final Class serviceClass) { - RoutedRpcRegistration registration = rpcRegistrations.get(serviceClass); + ObjectRegistration registration = rpcRegistrations.get(serviceClass); final RpcService rpcService = registration.getInstance(); return serviceClass.cast(rpcService); } @@ -107,15 +107,14 @@ class RpcContextImpl implements RpcContext { } private void unregisterRPCs() { - for (final Iterator, RoutedRpcRegistration>> iterator = Iterators + for (final Iterator, ObjectRegistration>> iterator = Iterators .consumingIterator(rpcRegistrations.entrySet().iterator()); iterator.hasNext(); ) { - final RoutedRpcRegistration rpcRegistration = iterator.next().getValue(); - rpcRegistration.unregisterPath(NodeContext.class, nodeInstanceIdentifier); + final ObjectRegistration rpcRegistration = iterator.next().getValue(); rpcRegistration.close(); if (LOG.isDebugEnabled()) { LOG.debug("Closing RPC Registration of service {} for device {}.", - rpcRegistration.getServiceType().getSimpleName(), + rpcRegistration.getInstance().getClass().getSimpleName(), nodeInstanceIdentifier.getKey().getId().getValue()); } } @@ -131,7 +130,7 @@ class RpcContextImpl implements RpcContext { nodeInstanceIdentifier.getKey().getId().getValue(), tracker.availablePermits()); } - final Long xid = deviceInfo.reserveXidForDeviceMessage(); + final Uint32 xid = deviceInfo.reserveXidForDeviceMessage(); if (xid == null) { LOG.warn("Xid cannot be reserved for new RequestContext, node:{}", nodeInstanceIdentifier.getKey().getId().getValue()); @@ -139,12 +138,11 @@ class RpcContextImpl implements RpcContext { return null; } - return new AbstractRequestContext(xid) { + return new AbstractRequestContext<>(xid) { @Override public void close() { tracker.release(); - final long xid = getXid().getValue(); - LOG.trace("Removed request context with xid {}", xid); + LOG.trace("Removed request context with xid {}", getXid().getValue()); messageSpy.spyMessage(RpcContextImpl.class, MessageSpy.StatisticsGroup.REQUEST_STACK_FREED); } }; @@ -154,9 +152,8 @@ class RpcContextImpl implements RpcContext { public void unregisterRpcServiceImplementation(final Class serviceClass) { LOG.trace("Try to unregister serviceClass {} for Node {}", serviceClass, nodeInstanceIdentifier.getKey().getId()); - final RoutedRpcRegistration rpcRegistration = rpcRegistrations.remove(serviceClass); + final ObjectRegistration rpcRegistration = rpcRegistrations.remove(serviceClass); if (rpcRegistration != null) { - rpcRegistration.unregisterPath(NodeContext.class, nodeInstanceIdentifier); rpcRegistration.close(); LOG.debug("Un-registration serviceClass {} for Node {}", serviceClass.getSimpleName(), nodeInstanceIdentifier.getKey().getId().getValue()); @@ -165,28 +162,24 @@ class RpcContextImpl implements RpcContext { @VisibleForTesting boolean isEmptyRpcRegistrations() { - return this.rpcRegistrations.isEmpty(); + return rpcRegistrations.isEmpty(); } @Override public DeviceInfo getDeviceInfo() { - return this.deviceInfo; + return deviceInfo; } @Override - public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher newWatcher) { - this.contextChainMastershipWatcher = newWatcher; + public void registerMastershipWatcher(@NonNull final ContextChainMastershipWatcher newWatcher) { + contextChainMastershipWatcher = newWatcher; } @Override public ListenableFuture closeServiceInstance() { - return Futures.transform(Futures.immediateFuture(null), new Function() { - @Nullable - @Override - public Void apply(@Nullable final Void input) { - unregisterRPCs(); - return null; - } + return Futures.transform(Futures.immediateFuture(null), input -> { + unregisterRPCs(); + return null; }, MoreExecutors.directExecutor()); } @@ -205,7 +198,7 @@ class RpcContextImpl implements RpcContext { contextChainMastershipWatcher.onMasterRoleAcquired(deviceInfo, ContextChainMastershipState.RPC_REGISTRATION); } - @Nonnull + @NonNull @Override public ServiceGroupIdentifier getIdentifier() { return deviceInfo.getServiceIdentifier();