X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft-example%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fexample%2FExampleActor.java;h=50eda52aeaa6b76bc2a6716f53b790d9a8f2f8c5;hb=d0f46920468c8e4b67c68bd9058572b2d10d75f1;hp=a1916f15002113c2e3a900b7b7be6cfa22c8b35c;hpb=6cd5778f454ba882d0e15361dfa6a5cd06721d97;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java index a1916f1500..50eda52aea 100644 --- a/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java +++ b/opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java @@ -5,20 +5,17 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.example; import akka.actor.ActorRef; import akka.actor.Props; -import com.google.common.base.Optional; -import com.google.common.base.Throwables; import com.google.common.io.ByteSource; import java.io.IOException; import java.io.OutputStream; import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import javax.annotation.Nonnull; +import java.util.Optional; import org.apache.commons.lang3.SerializationUtils; import org.opendaylight.controller.cluster.example.messages.KeyValue; import org.opendaylight.controller.cluster.example.messages.KeyValueSaved; @@ -50,13 +47,12 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, } private final Map state = new HashMap<>(); - - private long persistIdentifier = 1; private final Optional roleChangeNotifier; + private long persistIdentifier = 1; - public ExampleActor(String id, Map peerAddresses, - Optional configParams) { + public ExampleActor(final String id, final Map peerAddresses, + final Optional configParams) { super(id, peerAddresses, configParams, (short)0); setPersistence(true); roleChangeNotifier = createRoleChangeNotifier(id); @@ -68,7 +64,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - protected void handleNonRaftCommand(Object message) { + protected void handleNonRaftCommand(final Object message) { if (message instanceof KeyValue) { if (isLeader()) { persistData(getSender(), new PayloadIdentifier(persistIdentifier++), (Payload) message, false); @@ -109,7 +105,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, + ", im-mem journal size=" + getRaftActorContext().getReplicatedLog().size(); } - public Optional createRoleChangeNotifier(String actorId) { + public Optional createRoleChangeNotifier(final String actorId) { ActorRef exampleRoleChangeNotifier = this.getContext().actorOf( RoleChangeNotifier.getProps(actorId), actorId + "-notifier"); return Optional.of(exampleRoleChangeNotifier); @@ -133,7 +129,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, @Override @SuppressWarnings("checkstyle:IllegalCatch") - public void createSnapshot(ActorRef actorRef, java.util.Optional installSnapshotStream) { + public void createSnapshot(final ActorRef actorRef, final Optional installSnapshotStream) { try { if (installSnapshotStream.isPresent()) { SerializationUtils.serialize((Serializable) state, installSnapshotStream.get()); @@ -146,7 +142,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - public void applySnapshot(Snapshot.State snapshotState) { + public void applySnapshot(final Snapshot.State snapshotState) { state.clear(); state.putAll(((MapState)snapshotState).state); @@ -155,26 +151,27 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, } } - @Override protected void onStateChanged() { + @Override + protected void onStateChanged() { } - @Override public String persistenceId() { + @Override + public String persistenceId() { return getId(); } @Override - @Nonnull protected RaftActorRecoveryCohort getRaftActorRecoveryCohort() { return this; } @Override - public void startLogRecoveryBatch(int maxBatchSize) { + public void startLogRecoveryBatch(final int maxBatchSize) { } @Override - public void appendRecoveredLogEntry(Payload data) { + public void appendRecoveredLogEntry(final Payload data) { } @Override @@ -186,7 +183,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - public void applyRecoverySnapshot(Snapshot.State snapshotState) { + public void applyRecoverySnapshot(final Snapshot.State snapshotState) { } @Override @@ -201,11 +198,11 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, @SuppressWarnings("unchecked") @Override - public Snapshot.State deserializeSnapshot(ByteSource snapshotBytes) { + public Snapshot.State deserializeSnapshot(final ByteSource snapshotBytes) { try { return new MapState((Map) SerializationUtils.deserialize(snapshotBytes.read())); } catch (IOException e) { - throw Throwables.propagate(e); + throw new IllegalStateException(e); } } @@ -214,7 +211,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, Map state; - MapState(Map state) { + MapState(final Map state) { this.state = state; } }