*/
package org.opendaylight.openflowplugin.impl.mastership;
+import static org.opendaylight.infrautils.utils.concurrent.LoggingFutures.addErrorLogging;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ListenableFuture;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
-import javax.annotation.Nonnull;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Service;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.MasterChecker;
import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeException;
import org.opendaylight.openflowplugin.api.openflow.mastership.ReconciliationFrameworkEvent;
import org.opendaylight.openflowplugin.api.openflow.mastership.ReconciliationFrameworkRegistration;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.rf.state.rev170713.ResultState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+@Singleton
+@Service(classes = MastershipChangeServiceManager.class)
public final class MastershipChangeServiceManagerImpl implements MastershipChangeServiceManager {
+ private static final Logger LOG = LoggerFactory.getLogger(MastershipChangeServiceManagerImpl.class);
+
private final List<MastershipChangeService> serviceGroup = new CopyOnWriteArrayList<>();
private ReconciliationFrameworkEvent rfService = null;
private MasterChecker masterChecker;
- @Nonnull
+ @NonNull
@Override
- public MastershipChangeRegistration register(@Nonnull MastershipChangeService service) {
+ public MastershipChangeRegistration register(@NonNull MastershipChangeService service) {
final MastershipServiceDelegate registration =
new MastershipServiceDelegate(service, () -> serviceGroup.remove(service));
serviceGroup.add(service);
@Override
public ReconciliationFrameworkRegistration reconciliationFrameworkRegistration(
- @Nonnull ReconciliationFrameworkEvent reconciliationFrameworkEvent) throws MastershipChangeException {
+ @NonNull ReconciliationFrameworkEvent reconciliationFrameworkEvent) throws MastershipChangeException {
if (rfService != null) {
throw new MastershipChangeException("Reconciliation framework already registered.");
} else {
}
@Override
- public void becomeMaster(@Nonnull final DeviceInfo deviceInfo) {
+ public void becomeMaster(@NonNull final DeviceInfo deviceInfo) {
serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onBecomeOwner(deviceInfo));
}
@Override
- // FB flags this for onDeviceDisconnected but unclear why - seems a false positive.
- @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
- public void becomeSlaveOrDisconnect(@Nonnull final DeviceInfo deviceInfo) {
+ public void becomeSlaveOrDisconnect(@NonNull final DeviceInfo deviceInfo) {
if (rfService != null) {
- rfService.onDeviceDisconnected(deviceInfo);
+ ListenableFuture<Void> future = rfService.onDeviceDisconnected(deviceInfo);
+ // TODO This null future check here should ideally not be required, but some tests currently rely on it
+ if (future != null) {
+ addErrorLogging(future, LOG, "onDeviceDisconnected() failed");
+ }
}
serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onLoseOwnership(deviceInfo));
}
@Override
- public ListenableFuture<ResultState> becomeMasterBeforeSubmittedDS(@Nonnull DeviceInfo deviceInfo) {
+ public ListenableFuture<ResultState> becomeMasterBeforeSubmittedDS(@NonNull DeviceInfo deviceInfo) {
return rfService == null ? null : rfService.onDevicePrepared(deviceInfo);
}
@Override
- public void setMasterChecker(@Nonnull final MasterChecker masterChecker) {
+ public void setMasterChecker(@NonNull final MasterChecker masterChecker) {
this.masterChecker = masterChecker;
}