From: Robert Varga Date: Wed, 15 Feb 2017 11:13:36 +0000 (+0100) Subject: Cleanup warnings around methods being potentially static X-Git-Tag: release/carbon~263 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=5bbe45d0b189e706ed587e5e4a30c1205213c2f7 Cleanup warnings around methods being potentially static These are private methods and they do not touch state, hence they can be made static. Change-Id: I1d9adf70d9121e01b2ac8e03a1198c1ba73716fb Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActor.java index e7529fb4bf..5eeed91ee3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActor.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActor.java @@ -71,7 +71,7 @@ public final class ShardSnapshotActor extends AbstractUntypedActorWithMetering { } } - private void onSerializeSnapshot(SerializeSnapshot request) { + private static void onSerializeSnapshot(final SerializeSnapshot request) { Optional installSnapshotStream = request.getInstallSnapshotStream(); if (installSnapshotStream.isPresent()) { try { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java index 47de1195e4..e57874a3ad 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java @@ -88,7 +88,7 @@ class EntityOwnershipShard extends Shard { private final EntityOwnershipStatistics entityOwnershipStatistics; private boolean removeAllInitialCandidates = true; - protected EntityOwnershipShard(Builder builder) { + protected EntityOwnershipShard(final Builder builder) { super(builder); this.localMemberName = builder.localMemberName; this.commitCoordinator = new EntityOwnershipShardCommitCoordinator(builder.localMemberName, LOG); @@ -98,12 +98,12 @@ class EntityOwnershipShard extends Shard { this.entityOwnershipStatistics.init(getDataStore()); } - private static DatastoreContext noPersistenceDatastoreContext(DatastoreContext datastoreContext) { + private static DatastoreContext noPersistenceDatastoreContext(final DatastoreContext datastoreContext) { return DatastoreContext.newBuilderFrom(datastoreContext).persistent(false).build(); } @Override - protected void onDatastoreContext(DatastoreContext context) { + protected void onDatastoreContext(final DatastoreContext context) { super.onDatastoreContext(noPersistenceDatastoreContext(context)); } @@ -142,13 +142,13 @@ class EntityOwnershipShard extends Shard { } } - private void onRemoveAllCandidates(RemoveAllCandidates message) { + private void onRemoveAllCandidates(final RemoveAllCandidates message) { LOG.debug("{}: onRemoveAllCandidates: {}", persistenceId(), message); removeCandidateFromEntities(message.getMemberName()); } - private void onSelectOwner(SelectOwner selectOwner) { + private void onSelectOwner(final SelectOwner selectOwner) { LOG.debug("{}: onSelectOwner: {}", persistenceId(), selectOwner); String currentOwner = getCurrentOwner(selectOwner.getEntityPath()); @@ -166,7 +166,7 @@ class EntityOwnershipShard extends Shard { } } - private void onRegisterCandidateLocal(RegisterCandidateLocal registerCandidate) { + private void onRegisterCandidateLocal(final RegisterCandidateLocal registerCandidate) { LOG.debug("{}: onRegisterCandidateLocal: {}", persistenceId(), registerCandidate); listenerSupport.setHasCandidateForEntity(registerCandidate.getEntity()); @@ -178,7 +178,7 @@ class EntityOwnershipShard extends Shard { getSender().tell(SuccessReply.INSTANCE, getSelf()); } - private void onUnregisterCandidateLocal(UnregisterCandidateLocal unregisterCandidate) { + private void onUnregisterCandidateLocal(final UnregisterCandidateLocal unregisterCandidate) { LOG.debug("{}: onUnregisterCandidateLocal: {}", persistenceId(), unregisterCandidate); DOMEntity entity = unregisterCandidate.getEntity(); @@ -223,7 +223,7 @@ class EntityOwnershipShard extends Shard { }); } - private void onUnregisterListenerLocal(UnregisterListenerLocal unregisterListener) { + private void onUnregisterListenerLocal(final UnregisterListenerLocal unregisterListener) { LOG.debug("{}: onUnregisterListenerLocal: {}", persistenceId(), unregisterListener); listenerSupport.removeEntityOwnershipListener(unregisterListener.getEntityType(), @@ -258,7 +258,7 @@ class EntityOwnershipShard extends Shard { } } - void possiblyRemoveAllInitialCandidates(ActorSelection leader) { + void possiblyRemoveAllInitialCandidates(final ActorSelection leader) { // The following handles removing all candidates on startup when re-joining with a remote leader. When a // follower is detected as down, the leader will re-assign new owners to entities that were owned by the // down member but doesn't remove the down member as a candidate, as the down node may actually be isolated @@ -341,7 +341,7 @@ class EntityOwnershipShard extends Shard { } @Override - protected void onLeaderChanged(String oldLeader, String newLeader) { + protected void onLeaderChanged(final String oldLeader, final String newLeader) { boolean isLeader = isLeader(); LOG.debug("{}: onLeaderChanged: oldLeader: {}, newLeader: {}, isLeader: {}", persistenceId(), oldLeader, newLeader, isLeader); @@ -406,7 +406,7 @@ class EntityOwnershipShard extends Shard { LOG.debug("{}: new downPeerMemberNames: {}", persistenceId(), downPeerMemberNames); } - private void onCandidateRemoved(CandidateRemoved message) { + private void onCandidateRemoved(final CandidateRemoved message) { LOG.debug("{}: onCandidateRemoved: {}", persistenceId(), message); if (isLeader()) { @@ -417,12 +417,12 @@ class EntityOwnershipShard extends Shard { } } - private EntityOwnerSelectionStrategy getEntityOwnerElectionStrategy(YangInstanceIdentifier entityPath) { + private EntityOwnerSelectionStrategy getEntityOwnerElectionStrategy(final YangInstanceIdentifier entityPath) { final String entityType = EntityOwnersModel.entityTypeFromEntityPath(entityPath); return strategyConfig.createStrategy(entityType, entityOwnershipStatistics.byEntityType(entityType)); } - private void onCandidateAdded(CandidateAdded message) { + private void onCandidateAdded(final CandidateAdded message) { if (!isLeader()) { return; } @@ -456,7 +456,7 @@ class EntityOwnershipShard extends Shard { } } - private void onPeerDown(PeerDown peerDown) { + private void onPeerDown(final PeerDown peerDown) { LOG.info("{}: onPeerDown: {}", persistenceId(), peerDown); MemberName downMemberName = peerDown.getMemberName(); @@ -472,7 +472,7 @@ class EntityOwnershipShard extends Shard { } } - private void selectNewOwnerForEntitiesOwnedBy(Set ownedBy) { + private void selectNewOwnerForEntitiesOwnedBy(final Set ownedBy) { final BatchedModifications modifications = commitCoordinator.newBatchedModifications(); searchForEntitiesOwnedBy(ownedBy, (entityTypeNode, entityNode) -> { YangInstanceIdentifier entityPath = YangInstanceIdentifier.builder(ENTITY_TYPES_PATH) @@ -496,7 +496,7 @@ class EntityOwnershipShard extends Shard { commitCoordinator.commitModifications(modifications, this); } - private void onPeerUp(PeerUp peerUp) { + private void onPeerUp(final PeerUp peerUp) { LOG.debug("{}: onPeerUp: {}", persistenceId(), peerUp); downPeerMemberNames.remove(peerUp.getMemberName()); @@ -518,7 +518,7 @@ class EntityOwnershipShard extends Shard { } } - private Collection getCandidateNames(MapEntryNode entity) { + private static Collection getCandidateNames(final MapEntryNode entity) { Collection candidates = ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getValue(); Collection candidateNames = new ArrayList<>(candidates.size()); for (MapEntryNode candidate: candidates) { @@ -528,7 +528,7 @@ class EntityOwnershipShard extends Shard { return candidateNames; } - private void searchForEntitiesOwnedBy(Set ownedBy, EntityWalker walker) { + private void searchForEntitiesOwnedBy(final Set ownedBy, final EntityWalker walker) { LOG.debug("{}: Searching for entities owned by {}", persistenceId(), ownedBy); searchForEntities((entityTypeNode, entityNode) -> { @@ -561,12 +561,12 @@ class EntityOwnershipShard extends Shard { commitCoordinator.commitModifications(modifications, this); } - private static boolean hasCandidate(MapEntryNode entity, MemberName candidateName) { + private static boolean hasCandidate(final MapEntryNode entity, final MemberName candidateName) { return ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getChild(candidateNodeKey(candidateName.getName())) .isPresent(); } - private void searchForEntities(EntityWalker walker) { + private void searchForEntities(final EntityWalker walker) { Optional> possibleEntityTypes = getDataStore().readNode(ENTITY_TYPES_PATH); if (!possibleEntityTypes.isPresent()) { return; @@ -585,7 +585,7 @@ class EntityOwnershipShard extends Shard { } } - private void writeNewOwner(YangInstanceIdentifier entityPath, String newOwner) { + private void writeNewOwner(final YangInstanceIdentifier entityPath, final String newOwner) { LOG.debug("{}: Writing new owner {} for entity {}", persistenceId(), newOwner, entityPath); commitCoordinator.commitModification(new WriteModification(entityPath.node(ENTITY_OWNER_QNAME), @@ -595,8 +595,8 @@ class EntityOwnershipShard extends Shard { /** * Schedule a new owner selection job. Cancelling any outstanding job if it has not been cancelled. */ - private void scheduleOwnerSelection(YangInstanceIdentifier entityPath, Collection allCandidates, - EntityOwnerSelectionStrategy strategy) { + private void scheduleOwnerSelection(final YangInstanceIdentifier entityPath, final Collection allCandidates, + final EntityOwnerSelectionStrategy strategy) { cancelOwnerSelectionTask(entityPath); LOG.debug("{}: Scheduling owner selection after {} ms", persistenceId(), strategy.getSelectionDelayInMillis()); @@ -608,15 +608,15 @@ class EntityOwnershipShard extends Shard { entityToScheduledOwnershipTask.put(entityPath, lastScheduledTask); } - private void cancelOwnerSelectionTask(YangInstanceIdentifier entityPath) { + private void cancelOwnerSelectionTask(final YangInstanceIdentifier entityPath) { final Cancellable lastScheduledTask = entityToScheduledOwnershipTask.get(entityPath); if (lastScheduledTask != null && !lastScheduledTask.isCancelled()) { lastScheduledTask.cancel(); } } - private String newOwner(String currentOwner, Collection candidates, - EntityOwnerSelectionStrategy ownerSelectionStrategy) { + private String newOwner(final String currentOwner, final Collection candidates, + final EntityOwnerSelectionStrategy ownerSelectionStrategy) { Collection viableCandidates = getViableCandidates(candidates); if (viableCandidates.isEmpty()) { return ""; @@ -624,7 +624,7 @@ class EntityOwnershipShard extends Shard { return ownerSelectionStrategy.newOwner(currentOwner, viableCandidates); } - private Collection getViableCandidates(Collection candidates) { + private Collection getViableCandidates(final Collection candidates) { Collection viableCandidates = new ArrayList<>(); for (String candidate : candidates) { @@ -635,7 +635,7 @@ class EntityOwnershipShard extends Shard { return viableCandidates; } - private String getCurrentOwner(YangInstanceIdentifier entityId) { + private String getCurrentOwner(final YangInstanceIdentifier entityId) { Optional> optionalEntityOwner = getDataStore().readNode(entityId.node(ENTITY_OWNER_QNAME)); if (optionalEntityOwner.isPresent()) { return optionalEntityOwner.get().getValue().toString(); @@ -660,13 +660,13 @@ class EntityOwnershipShard extends Shard { super(EntityOwnershipShard.class); } - Builder localMemberName(MemberName newLocalMemberName) { + Builder localMemberName(final MemberName newLocalMemberName) { checkSealed(); this.localMemberName = newLocalMemberName; return this; } - Builder ownerSelectionStrategyConfig(EntityOwnerSelectionStrategyConfig newOwnerSelectionStrategyConfig) { + Builder ownerSelectionStrategyConfig(final EntityOwnerSelectionStrategyConfig newOwnerSelectionStrategyConfig) { checkSealed(); this.ownerSelectionStrategyConfig = newOwnerSelectionStrategyConfig; return this; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardSnapshotState.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardSnapshotState.java index d4556cd374..f56d6ce01f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardSnapshotState.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardSnapshotState.java @@ -47,14 +47,14 @@ public class ShardSnapshotState implements Snapshot.State { snapshotState.snapshot.serialize(toOutputStream(out)); } - private OutputStream toOutputStream(final ObjectOutput out) { + private static OutputStream toOutputStream(final ObjectOutput out) { if (out instanceof OutputStream) { return (OutputStream) out; } return new OutputStream() { @Override - public void write(int value) throws IOException { + public void write(final int value) throws IOException { out.write(value); } }; @@ -65,7 +65,7 @@ public class ShardSnapshotState implements Snapshot.State { snapshotState = new ShardSnapshotState(ShardDataTreeSnapshot.deserialize(toInputStream(in))); } - private InputStream toInputStream(final ObjectInput in) { + private static InputStream toInputStream(final ObjectInput in) { if (in instanceof InputStream) { return (InputStream) in; } @@ -88,7 +88,7 @@ public class ShardSnapshotState implements Snapshot.State { + "aren't serialized. FindBugs does not recognize this.") private final ShardDataTreeSnapshot snapshot; - public ShardSnapshotState(@Nonnull ShardDataTreeSnapshot snapshot) { + public ShardSnapshotState(@Nonnull final ShardDataTreeSnapshot snapshot) { this.snapshot = Preconditions.checkNotNull(snapshot); } @@ -97,7 +97,6 @@ public class ShardSnapshotState implements Snapshot.State { return snapshot; } - @SuppressWarnings("static-method") private Object writeReplace() { return new Proxy(this); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java index 8da5bf7387..3a676586eb 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java @@ -490,7 +490,7 @@ public abstract class AbstractShardTest extends AbstractActorTest { } @SuppressWarnings("unchecked") - private FutureCallback mockFutureCallback(final FutureCallback actual) { + private static FutureCallback mockFutureCallback(final FutureCallback actual) { FutureCallback mock = mock(FutureCallback.class); doAnswer(invocation -> { actual.onFailure(invocation.getArgumentAt(0, Throwable.class));