From e2d4db3b6fa3be4c1ea40b5227499aedef5dd393 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Wed, 7 Mar 2018 16:06:58 -0500 Subject: [PATCH] Fix checkstyle violations in /sal-connector-api and sal-dummy-distributed-datastore Change-Id: I9ff8db03ca921517595dc133c1b3869c3a29fa34 Signed-off-by: Tom Pantelis --- .../connector/api/BindingAwareRpcRouter.java | 44 ++++++++++--------- .../sal/connector/api/ConnectorListener.java | 4 +- .../sal/connector/api/RpcRouter.java | 16 +++---- .../dummy/datastore/DummyShard.java | 37 ++++++++-------- .../dummy/datastore/DummyShardManager.java | 18 ++++---- .../controller/dummy/datastore/Main.java | 36 ++++++++------- 6 files changed, 81 insertions(+), 74 deletions(-) diff --git a/opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/BindingAwareRpcRouter.java b/opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/BindingAwareRpcRouter.java index 17221bc0af..db10b08ff4 100644 --- a/opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/BindingAwareRpcRouter.java +++ b/opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/BindingAwareRpcRouter.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.sal.connector.api; import java.util.concurrent.Future; - import org.opendaylight.yangtools.concepts.Immutable; public interface BindingAwareRpcRouter extends RpcRouter { @@ -27,6 +26,7 @@ public interface BindingAwareRpcRouter extends RpcRouter prefixes); - void onPrefixesWithdrawn(Set prefixes); + void onPrefixesWithdrawn(Set prefixes); } diff --git a/opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/RpcRouter.java b/opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/RpcRouter.java index f49f7ef5f4..c56560ac75 100644 --- a/opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/RpcRouter.java +++ b/opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/RpcRouter.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.sal.connector.api; import java.util.concurrent.Future; /** + * Interface for an RPC router. * * @author ttkacik * @@ -19,31 +20,30 @@ import java.util.concurrent.Future; * @param Data Type */ public interface RpcRouter { - - - Future> sendRpc(RpcRequest input); /** - * - * @author + * Interface for an RPC request. * * @param Routing Context Identifier - * @param Route Type - * @param Rpc Type - * @param Data Type + * @param Route Type + * @param Rpc Type + * @param Data Type */ interface RpcRequest { RouteIdentifier getRoutingInformation(); + D getPayload(); } interface RouteIdentifier { C getContext(); // defines a routing table (e.g. NodeContext) + T getType(); // rpc type + R getRoute(); // e.g. (node identity) } diff --git a/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShard.java b/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShard.java index 2cd5b97ceb..db9515b43e 100644 --- a/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShard.java +++ b/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShard.java @@ -24,10 +24,11 @@ import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class DummyShard extends UntypedActor{ +public class DummyShard extends UntypedActor { + private static final Logger LOG = LoggerFactory.getLogger(DummyShard.class); + private final Configuration configuration; private final String followerId; - private final Logger LOG = LoggerFactory.getLogger(DummyShard.class); private long lastMessageIndex = -1; private long lastMessageSize = 0; private Stopwatch appendEntriesWatch; @@ -39,16 +40,16 @@ public class DummyShard extends UntypedActor{ } @Override - public void onReceive(Object o) throws Exception { - if(o instanceof RequestVote){ - RequestVote req = (RequestVote) o; + public void onReceive(Object message) throws Exception { + if (message instanceof RequestVote) { + RequestVote req = (RequestVote) message; sender().tell(new RequestVoteReply(req.getTerm(), true), self()); - } else if(o instanceof AppendEntries) { - handleAppendEntries((AppendEntries)o); - } else if(o instanceof InstallSnapshot){ - handleInstallSnapshot((InstallSnapshot) o); + } else if (message instanceof AppendEntries) { + handleAppendEntries((AppendEntries) message); + } else if (message instanceof InstallSnapshot) { + handleInstallSnapshot((InstallSnapshot) message); } else { - LOG.error("Unknown message : {}", o.getClass()); + LOG.error("Unknown message : {}", message.getClass()); } } @@ -60,11 +61,11 @@ public class DummyShard extends UntypedActor{ LOG.info("{} - Received AppendEntries message : leader term = {}, index = {}, prevLogIndex = {}, size = {}", followerId, req.getTerm(),req.getLeaderCommit(), req.getPrevLogIndex(), req.getEntries().size()); - if(appendEntriesWatch != null){ + if (appendEntriesWatch != null) { long elapsed = appendEntriesWatch.elapsed(TimeUnit.SECONDS); - if(elapsed >= 5){ - LOG.error("More than 5 seconds since last append entry, elapsed Time = {} seconds" + - ", leaderCommit = {}, prevLogIndex = {}, size = {}", + if (elapsed >= 5) { + LOG.error("More than 5 seconds since last append entry, elapsed Time = {} seconds" + + ", leaderCommit = {}, prevLogIndex = {}, size = {}", elapsed, req.getLeaderCommit(), req.getPrevLogIndex(), req.getEntries().size()); } appendEntriesWatch.reset().start(); @@ -72,8 +73,9 @@ public class DummyShard extends UntypedActor{ appendEntriesWatch = Stopwatch.createStarted(); } - if(lastMessageIndex == req.getLeaderCommit() && req.getEntries().size() > 0 && lastMessageSize > 0){ - LOG.error("{} - Duplicate message with leaderCommit = {} prevLogIndex = {} received", followerId, req.getLeaderCommit(), req.getPrevLogIndex()); + if (lastMessageIndex == req.getLeaderCommit() && req.getEntries().size() > 0 && lastMessageSize > 0) { + LOG.error("{} - Duplicate message with leaderCommit = {} prevLogIndex = {} received", followerId, + req.getLeaderCommit(), req.getPrevLogIndex()); } lastMessageIndex = req.getLeaderCommit(); @@ -81,7 +83,7 @@ public class DummyShard extends UntypedActor{ long lastIndex = req.getLeaderCommit(); if (req.getEntries().size() > 0) { - for(ReplicatedLogEntry entry : req.getEntries()) { + for (ReplicatedLogEntry entry : req.getEntries()) { lastIndex = entry.getIndex(); } } @@ -128,5 +130,4 @@ public class DummyShard extends UntypedActor{ return new DummyShard(configuration, followerId); } } - } diff --git a/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShardManager.java b/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShardManager.java index 339f37e0bb..abc73db9ed 100644 --- a/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShardManager.java +++ b/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShardManager.java @@ -14,16 +14,17 @@ import akka.actor.UntypedActor; import akka.japi.Creator; public class DummyShardManager extends UntypedActor { - public DummyShardManager(Configuration configuration, String memberName, String[] shardNames, String type) throws Exception { + public DummyShardManager(Configuration configuration, String memberName, String[] shardNames, + String type) throws Exception { new DummyShardsCreator(configuration, context(), memberName, shardNames, type).create(); } @Override - public void onReceive(Object o) throws Exception { + public void onReceive(Object message) throws Exception { } - public static Props props(Configuration configuration, String memberName, String[] shardNames, String type){ + public static Props props(Configuration configuration, String memberName, String[] shardNames, String type) { return Props.create(new DummyShardManagerCreator(configuration, memberName, shardNames, type)); } @@ -34,7 +35,7 @@ public class DummyShardManager extends UntypedActor { private final String[] shardNames; private final String type; - public DummyShardManagerCreator(Configuration configuration, String memberName, String[] shardNames, String type) { + DummyShardManagerCreator(Configuration configuration, String memberName, String[] shardNames, String type) { this.configuration = configuration; this.memberName = memberName; this.shardNames = shardNames; @@ -43,7 +44,7 @@ public class DummyShardManager extends UntypedActor { @Override public DummyShardManager create() throws Exception { - return new DummyShardManager(configuration, memberName, shardNames, type ); + return new DummyShardManager(configuration, memberName, shardNames, type); } } @@ -54,7 +55,8 @@ public class DummyShardManager extends UntypedActor { private final String[] shardNames; private final String type; - DummyShardsCreator(Configuration configuration, ActorContext actorSystem, String memberName, String[] shardNames, String type){ + DummyShardsCreator(Configuration configuration, ActorContext actorSystem, String memberName, + String[] shardNames, String type) { this.configuration = configuration; this.actorSystem = actorSystem; this.memberName = memberName; @@ -62,8 +64,8 @@ public class DummyShardManager extends UntypedActor { this.type = type; } - void create(){ - for(String shardName : shardNames){ + void create() { + for (String shardName : shardNames) { String shardId = memberName + "-shard-" + shardName + "-" + type; actorSystem.actorOf(DummyShard.props(configuration, shardId), shardId); } diff --git a/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/Main.java b/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/Main.java index 81da1f89a6..3342b5de8b 100644 --- a/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/Main.java +++ b/opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/Main.java @@ -10,42 +10,45 @@ package org.opendaylight.controller.dummy.datastore; import akka.actor.ActorSystem; import com.typesafe.config.ConfigFactory; +import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.Option; public class Main { - @Option(name="-member-name", usage="Sets the member name", required = true) + @Option(name = "-member-name", usage = "Sets the member name", required = true) public String memberName; - @Option(name="-max-delay-millis", usage = "Sets the maximum delay that should be applied for any append entry. Only applies when cause-trouble is present.") + @Option(name = "-max-delay-millis", usage = "Sets the maximum delay that should be applied for any append entry. " + + "Only applies when cause-trouble is present.") public int maxDelayInMillis = 500; - @Option(name="-cause-trouble", usage="If present turns on artificial failures") + @Option(name = "-cause-trouble", usage = "If present turns on artificial failures") public boolean causeTrouble = false; - @Option(name="-drop-replies", usage = "If present drops replies. Only applies when cause-trouble is present.") + @Option(name = "-drop-replies", usage = "If present drops replies. Only applies when cause-trouble is present.") public boolean dropReplies = false; - public void run(){ - ActorSystem actorSystem = ActorSystem.create("opendaylight-cluster-data", ConfigFactory.load(memberName).getConfig("odl-cluster-data")); + public void run() { + ActorSystem actorSystem = ActorSystem.create("opendaylight-cluster-data", + ConfigFactory.load(memberName).getConfig("odl-cluster-data")); Configuration configuration = new Configuration(maxDelayInMillis, dropReplies, causeTrouble); - actorSystem.actorOf(DummyShardManager.props(configuration, memberName, new String[] {"inventory", "default", "toaster", "topology"}, "operational"), "shardmanager-operational"); - actorSystem.actorOf(DummyShardManager.props(configuration, memberName, new String[] {"inventory", "default", "toaster", "topology"}, "config"), "shardmanager-config"); + actorSystem.actorOf(DummyShardManager.props(configuration, memberName, + new String[] {"inventory", "default", "toaster", "topology"}, "operational"), + "shardmanager-operational"); + actorSystem.actorOf(DummyShardManager.props(configuration, memberName, + new String[] {"inventory", "default", "toaster", "topology"}, "config"), "shardmanager-config"); } @Override public String toString() { - return "Main{" + - "memberName='" + memberName + '\'' + - ", maxDelayInMillis=" + maxDelayInMillis + - ", causeTrouble=" + causeTrouble + - ", dropReplies=" + dropReplies + - '}'; + return "Main{" + "memberName='" + memberName + '\'' + ", maxDelayInMillis=" + maxDelayInMillis + + ", causeTrouble=" + causeTrouble + ", dropReplies=" + dropReplies + '}'; } - public static void main(String[] args){ + @SuppressWarnings("checkstyle:RegexpSingleLineJava") + public static void main(String[] args) { Main bean = new Main(); CmdLineParser parser = new CmdLineParser(bean); @@ -53,10 +56,9 @@ public class Main { parser.parseArgument(args); System.out.println(bean.toString()); bean.run(); - } catch(Exception e){ + } catch (CmdLineException e) { System.err.println(e.getMessage()); parser.printUsage(System.err); } } - } -- 2.36.6