Repository: incubator-ratis Updated Branches: refs/heads/master f04ac8590 -> 718fa9ea3
RATIS-31. Support customized RPC types. Project: http://git-wip-us.apache.org/repos/asf/incubator-ratis/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ratis/commit/718fa9ea Tree: http://git-wip-us.apache.org/repos/asf/incubator-ratis/tree/718fa9ea Diff: http://git-wip-us.apache.org/repos/asf/incubator-ratis/diff/718fa9ea Branch: refs/heads/master Commit: 718fa9ea3e1b1a3f4f88150b7433857fa1ed1f1e Parents: f04ac85 Author: Tsz-Wo Nicholas Sze <[email protected]> Authored: Mon Feb 27 17:40:42 2017 -0800 Committer: Tsz-Wo Nicholas Sze <[email protected]> Committed: Mon Feb 27 17:40:42 2017 -0800 ---------------------------------------------------------------------- .../java/org/apache/ratis/RaftConfigKeys.java | 23 ++++++-- .../src/main/java/org/apache/ratis/RpcType.java | 34 ----------- .../java/org/apache/ratis/conf/ConfUtils.java | 17 ++++++ .../java/org/apache/ratis/rpc/RpcFactory.java | 22 +++++++ .../main/java/org/apache/ratis/rpc/RpcType.java | 35 +++++++++++ .../org/apache/ratis/rpc/SupportedRpcType.java | 44 ++++++++++++++ .../java/org/apache/ratis/util/RaftUtils.java | 16 +++++ .../org/apache/ratis/grpc/RaftGRpcService.java | 6 +- .../ratis/grpc/server/GrpcServerFactory.java | 9 ++- .../ratis/grpc/MiniRaftClusterWithGRpc.java | 4 +- .../apache/ratis/hadooprpc/HadoopFactory.java | 9 ++- .../hadooprpc/server/HadoopRpcService.java | 6 +- .../hadooprpc/MiniRaftClusterWithHadoopRpc.java | 4 +- .../org/apache/ratis/netty/NettyFactory.java | 9 ++- .../ratis/netty/server/NettyRpcService.java | 19 +++--- .../ratis/netty/MiniRaftClusterWithNetty.java | 4 +- .../org/apache/ratis/server/RaftServer.java | 17 +++--- .../ratis/server/RaftServerConfigKeys.java | 42 ------------- .../org/apache/ratis/server/RaftServerRpc.java | 2 +- .../ratis/server/impl/RaftServerImpl.java | 10 ++-- .../apache/ratis/server/impl/ServerFactory.java | 36 ++++-------- .../MiniRaftClusterWithSimulatedRpc.java | 6 +- .../ratis/server/simulation/SimulatedRpc.java | 62 ++++++++++++++++++++ .../server/simulation/SimulatedServerRpc.java | 29 ++++----- .../server/simulation/SimulationFactory.java | 41 ------------- 25 files changed, 295 insertions(+), 211 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-common/src/main/java/org/apache/ratis/RaftConfigKeys.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/RaftConfigKeys.java b/ratis-common/src/main/java/org/apache/ratis/RaftConfigKeys.java index 4155023..adf393b 100644 --- a/ratis-common/src/main/java/org/apache/ratis/RaftConfigKeys.java +++ b/ratis-common/src/main/java/org/apache/ratis/RaftConfigKeys.java @@ -18,9 +18,12 @@ package org.apache.ratis; import org.apache.ratis.conf.ConfUtils; +import org.apache.ratis.conf.RaftProperties; +import org.apache.ratis.rpc.SupportedRpcType; +import org.apache.ratis.rpc.RpcType; +import org.apache.ratis.util.RaftUtils; import java.util.function.BiConsumer; -import java.util.function.BiFunction; public interface RaftConfigKeys { String PREFIX = "raft"; @@ -29,14 +32,22 @@ public interface RaftConfigKeys { String PREFIX = RaftConfigKeys.PREFIX + ".rpc"; String TYPE_KEY = PREFIX + ".type"; - RpcType TYPE_DEFAULT = RpcType.GRPC; + String TYPE_DEFAULT = SupportedRpcType.GRPC.name(); - static RpcType type(BiFunction<String, RpcType, RpcType> getRpcType) { - return ConfUtils.get(getRpcType, TYPE_KEY, TYPE_DEFAULT); + static RpcType type(RaftProperties properties) { + final String t = ConfUtils.get(properties::get, TYPE_KEY, TYPE_DEFAULT); + + try { // Try parsing it as a SupportedRpcType + return SupportedRpcType.valueOfIgnoreCase(t); + } catch(IllegalArgumentException iae) { + } + + // Try using it as a class name + return RaftUtils.newInstance(t, properties, RpcType.class); } - static void setType(BiConsumer<String, RpcType> setRpcType, RpcType type) { - ConfUtils.set(setRpcType, TYPE_KEY, type); + static void setType(BiConsumer<String, String> setRpcType, RpcType type) { + ConfUtils.set(setRpcType, TYPE_KEY, type.name()); } } } http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-common/src/main/java/org/apache/ratis/RpcType.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/RpcType.java b/ratis-common/src/main/java/org/apache/ratis/RpcType.java deleted file mode 100644 index 7787613..0000000 --- a/ratis-common/src/main/java/org/apache/ratis/RpcType.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis; - -/** The type of RPC implementations. */ -public enum RpcType { - NETTY, GRPC, HADOOP, SIMULATED; - - /** Same as {@link #valueOf(String)} except that this method is case insensitive. */ - public static RpcType valueOfIgnoreCase(String s) { - return valueOf(s.toUpperCase()); - } - - /** An interface to get {@link RpcType}. */ - public interface Get { - /** @return the {@link RpcType}. */ - RpcType getRpcType(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java b/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java index f3870e5..8593aa4 100644 --- a/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java @@ -1,3 +1,20 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.ratis.conf; import org.apache.ratis.util.NetUtils; http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-common/src/main/java/org/apache/ratis/rpc/RpcFactory.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/rpc/RpcFactory.java b/ratis-common/src/main/java/org/apache/ratis/rpc/RpcFactory.java new file mode 100644 index 0000000..a2dbb6b --- /dev/null +++ b/ratis-common/src/main/java/org/apache/ratis/rpc/RpcFactory.java @@ -0,0 +1,22 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ratis.rpc; + +/** The type of RPC Factory. */ +public interface RpcFactory extends RpcType.Get { +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-common/src/main/java/org/apache/ratis/rpc/RpcType.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/rpc/RpcType.java b/ratis-common/src/main/java/org/apache/ratis/rpc/RpcType.java new file mode 100644 index 0000000..a8085fe --- /dev/null +++ b/ratis-common/src/main/java/org/apache/ratis/rpc/RpcType.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ratis.rpc; + +import org.apache.ratis.conf.RaftProperties; + +/** The type of RPC implementations. */ +public interface RpcType { + /** @return the name of the rpc type. */ + String name(); + + /** @return a new factory created using the given properties. */ + RpcFactory newFactory(RaftProperties properties); + + /** An interface to get {@link RpcType}. */ + interface Get { + /** @return the {@link RpcType}. */ + RpcType getRpcType(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-common/src/main/java/org/apache/ratis/rpc/SupportedRpcType.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/rpc/SupportedRpcType.java b/ratis-common/src/main/java/org/apache/ratis/rpc/SupportedRpcType.java new file mode 100644 index 0000000..d222495 --- /dev/null +++ b/ratis-common/src/main/java/org/apache/ratis/rpc/SupportedRpcType.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ratis.rpc; + +import org.apache.ratis.conf.RaftProperties; +import org.apache.ratis.util.RaftUtils; + +/** The RPC types supported. */ +public enum SupportedRpcType implements RpcType { + NETTY("org.apache.ratis.netty.NettyFactory"), + GRPC("org.apache.ratis.grpc.server.GrpcServerFactory"), + HADOOP("org.apache.ratis.hadooprpc.HadoopFactory"); + + /** Same as {@link #valueOf(String)} except that this method is case insensitive. */ + public static SupportedRpcType valueOfIgnoreCase(String s) { + return valueOf(s.toUpperCase()); + } + + private final String factoryClassName; + + SupportedRpcType(String factoryClassName) { + this.factoryClassName = factoryClassName; + } + + @Override + public RpcFactory newFactory(RaftProperties properties) { + return RaftUtils.newInstance(factoryClassName, properties, RpcFactory.class); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-common/src/main/java/org/apache/ratis/util/RaftUtils.java ---------------------------------------------------------------------- diff --git a/ratis-common/src/main/java/org/apache/ratis/util/RaftUtils.java b/ratis-common/src/main/java/org/apache/ratis/util/RaftUtils.java index 17e2e41..5f62f47 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/RaftUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/RaftUtils.java @@ -20,6 +20,7 @@ package org.apache.ratis.util; import com.google.common.base.Preconditions; import org.apache.log4j.Level; import org.apache.log4j.LogManager; +import org.apache.ratis.conf.RaftProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -138,6 +139,21 @@ public abstract class RaftUtils { } } + public static <BASE, SUB extends BASE> SUB newInstance( + String subClassName, RaftProperties properties, Class<BASE> base) { + return newInstance(getClass(subClassName, properties, base)); + } + + public static <BASE, SUB extends BASE> Class<SUB> getClass( + String subClassName, RaftProperties properties, Class<BASE> base) { + try { + return (Class<SUB>) properties.getClassByName(subClassName).asSubclass(base); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("Failed to get class " + + subClassName + " as a subclass of " + base, e); + } + } + /** * Create a memoized supplier which gets a value by invoking the initializer once * and then keeps returning the same value as its supplied results. http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-grpc/src/main/java/org/apache/ratis/grpc/RaftGRpcService.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/RaftGRpcService.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/RaftGRpcService.java index 22b295c..875efbb 100644 --- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/RaftGRpcService.java +++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/RaftGRpcService.java @@ -18,12 +18,12 @@ package org.apache.ratis.grpc; import com.google.common.base.Preconditions; -import org.apache.ratis.RpcType; import org.apache.ratis.grpc.client.RaftClientProtocolService; import org.apache.ratis.grpc.server.RaftServerProtocolClient; import org.apache.ratis.grpc.server.RaftServerProtocolService; import org.apache.ratis.protocol.RaftPeer; import org.apache.ratis.protocol.RaftPeerId; +import org.apache.ratis.rpc.SupportedRpcType; import org.apache.ratis.server.RaftServer; import org.apache.ratis.server.RaftServerRpc; import org.apache.ratis.shaded.io.grpc.Server; @@ -95,8 +95,8 @@ public class RaftGRpcService implements RaftServerRpc { } @Override - public RpcType getRpcType() { - return RpcType.GRPC; + public SupportedRpcType getRpcType() { + return SupportedRpcType.GRPC; } @Override http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerFactory.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerFactory.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerFactory.java index e280faf..9c1d6f0 100644 --- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerFactory.java +++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerFactory.java @@ -18,18 +18,23 @@ package org.apache.ratis.grpc.server; import org.apache.ratis.grpc.RaftGRpcService; -import org.apache.ratis.server.RaftServerRpc; +import org.apache.ratis.rpc.SupportedRpcType; import org.apache.ratis.server.impl.*; public class GrpcServerFactory implements ServerFactory { @Override + public SupportedRpcType getRpcType() { + return SupportedRpcType.GRPC; + } + + @Override public LogAppender newLogAppender(RaftServerImpl server, LeaderState state, FollowerInfo f) { return new GRpcLogAppender(server, state, f); } @Override - public RaftServerRpc newRaftServerRpc(RaftServerImpl server) { + public RaftGRpcService newRaftServerRpc(RaftServerImpl server) { return RaftGRpcService.newBuilder() .setServer(server) .build(); http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-grpc/src/test/java/org/apache/ratis/grpc/MiniRaftClusterWithGRpc.java ---------------------------------------------------------------------- diff --git a/ratis-grpc/src/test/java/org/apache/ratis/grpc/MiniRaftClusterWithGRpc.java b/ratis-grpc/src/test/java/org/apache/ratis/grpc/MiniRaftClusterWithGRpc.java index c0c4f6d..186cac6 100644 --- a/ratis-grpc/src/test/java/org/apache/ratis/grpc/MiniRaftClusterWithGRpc.java +++ b/ratis-grpc/src/test/java/org/apache/ratis/grpc/MiniRaftClusterWithGRpc.java @@ -20,12 +20,12 @@ package org.apache.ratis.grpc; import org.apache.ratis.MiniRaftCluster; import org.apache.ratis.RaftConfigKeys; import org.apache.ratis.RaftTestUtil; -import org.apache.ratis.RpcType; import org.apache.ratis.client.RaftClientRequestSender; import org.apache.ratis.conf.RaftProperties; import org.apache.ratis.grpc.client.RaftClientSenderWithGrpc; import org.apache.ratis.protocol.RaftPeer; import org.apache.ratis.protocol.RaftPeerId; +import org.apache.ratis.rpc.SupportedRpcType; import org.apache.ratis.server.impl.BlockRequestHandlingInjection; import org.apache.ratis.server.impl.DelayLocalExecutionInjection; import org.apache.ratis.server.impl.RaftServerImpl; @@ -38,7 +38,7 @@ public class MiniRaftClusterWithGRpc extends MiniRaftCluster.RpcBase { @Override public MiniRaftClusterWithGRpc newCluster( String[] ids, RaftProperties prop, boolean formatted) { - RaftConfigKeys.Rpc.setType(prop::setEnum, RpcType.GRPC); + RaftConfigKeys.Rpc.setType(prop::set, SupportedRpcType.GRPC); return new MiniRaftClusterWithGRpc(ids, prop, formatted); } }; http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/HadoopFactory.java ---------------------------------------------------------------------- diff --git a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/HadoopFactory.java b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/HadoopFactory.java index a083f05..063858a 100644 --- a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/HadoopFactory.java +++ b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/HadoopFactory.java @@ -19,7 +19,7 @@ package org.apache.ratis.hadooprpc; import org.apache.hadoop.conf.Configuration; import org.apache.ratis.hadooprpc.server.HadoopRpcService; -import org.apache.ratis.server.RaftServerRpc; +import org.apache.ratis.rpc.SupportedRpcType; import org.apache.ratis.server.impl.RaftServerImpl; import org.apache.ratis.server.impl.ServerFactory; @@ -31,7 +31,12 @@ public class HadoopFactory extends ServerFactory.BaseFactory { } @Override - public RaftServerRpc newRaftServerRpc(RaftServerImpl server) { + public SupportedRpcType getRpcType() { + return SupportedRpcType.HADOOP; + } + + @Override + public HadoopRpcService newRaftServerRpc(RaftServerImpl server) { return HadoopRpcService.newBuilder() .setServer(server) .setConf(conf) http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/server/HadoopRpcService.java ---------------------------------------------------------------------- diff --git a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/server/HadoopRpcService.java b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/server/HadoopRpcService.java index 74716be..87fd2e2 100644 --- a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/server/HadoopRpcService.java +++ b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/server/HadoopRpcService.java @@ -20,13 +20,13 @@ package org.apache.ratis.hadooprpc.server; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ipc.ProtobufRpcEngineShaded; import org.apache.hadoop.ipc.RPC; -import org.apache.ratis.RpcType; import org.apache.ratis.hadooprpc.Proxy; import org.apache.ratis.hadooprpc.client.RaftClientProtocolPB; import org.apache.ratis.hadooprpc.client.RaftClientProtocolServerSideTranslatorPB; import org.apache.ratis.protocol.RaftClientProtocol; import org.apache.ratis.protocol.RaftPeer; import org.apache.ratis.protocol.RaftPeerId; +import org.apache.ratis.rpc.SupportedRpcType; import org.apache.ratis.server.RaftServer; import org.apache.ratis.server.RaftServerRpc; import org.apache.ratis.server.protocol.RaftServerProtocol; @@ -106,8 +106,8 @@ public class HadoopRpcService implements RaftServerRpc { } @Override - public RpcType getRpcType() { - return RpcType.HADOOP; + public SupportedRpcType getRpcType() { + return SupportedRpcType.HADOOP; } @Override http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-hadoop/src/test/java/org/apache/ratis/hadooprpc/MiniRaftClusterWithHadoopRpc.java ---------------------------------------------------------------------- diff --git a/ratis-hadoop/src/test/java/org/apache/ratis/hadooprpc/MiniRaftClusterWithHadoopRpc.java b/ratis-hadoop/src/test/java/org/apache/ratis/hadooprpc/MiniRaftClusterWithHadoopRpc.java index 157891f..c09c300 100644 --- a/ratis-hadoop/src/test/java/org/apache/ratis/hadooprpc/MiniRaftClusterWithHadoopRpc.java +++ b/ratis-hadoop/src/test/java/org/apache/ratis/hadooprpc/MiniRaftClusterWithHadoopRpc.java @@ -21,13 +21,13 @@ import org.apache.hadoop.conf.Configuration; import org.apache.ratis.MiniRaftCluster; import org.apache.ratis.RaftConfigKeys; import org.apache.ratis.RaftTestUtil; -import org.apache.ratis.RpcType; import org.apache.ratis.client.RaftClientRequestSender; import org.apache.ratis.conf.RaftProperties; import org.apache.ratis.hadooprpc.client.HadoopClientRequestSender; import org.apache.ratis.hadooprpc.server.HadoopRpcServerConfigKeys; import org.apache.ratis.hadooprpc.server.HadoopRpcService; import org.apache.ratis.protocol.RaftPeerId; +import org.apache.ratis.rpc.SupportedRpcType; import org.apache.ratis.server.impl.DelayLocalExecutionInjection; import org.apache.ratis.server.impl.RaftServerImpl; import org.slf4j.Logger; @@ -51,7 +51,7 @@ public class MiniRaftClusterWithHadoopRpc extends MiniRaftCluster.RpcBase { public MiniRaftClusterWithHadoopRpc newCluster( String[] ids, RaftProperties prop, Configuration conf, boolean formatted) { - RaftConfigKeys.Rpc.setType(prop::setEnum, RpcType.HADOOP); + RaftConfigKeys.Rpc.setType(prop::set, SupportedRpcType.HADOOP); HadoopRpcServerConfigKeys.Ipc.setAddress(conf::set, "0.0.0.0:0"); return new MiniRaftClusterWithHadoopRpc(ids, prop, conf, formatted); } http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-netty/src/main/java/org/apache/ratis/netty/NettyFactory.java ---------------------------------------------------------------------- diff --git a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyFactory.java b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyFactory.java index 6265f02..ac71f44 100644 --- a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyFactory.java +++ b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyFactory.java @@ -18,13 +18,18 @@ package org.apache.ratis.netty; import org.apache.ratis.netty.server.NettyRpcService; -import org.apache.ratis.server.RaftServerRpc; +import org.apache.ratis.rpc.SupportedRpcType; import org.apache.ratis.server.impl.RaftServerImpl; import org.apache.ratis.server.impl.ServerFactory; public class NettyFactory extends ServerFactory.BaseFactory { @Override - public RaftServerRpc newRaftServerRpc(RaftServerImpl server) { + public SupportedRpcType getRpcType() { + return SupportedRpcType.NETTY; + } + + @Override + public NettyRpcService newRaftServerRpc(RaftServerImpl server) { return NettyRpcService.newBuilder().setServer(server).build(); } } http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyRpcService.java ---------------------------------------------------------------------- diff --git a/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyRpcService.java b/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyRpcService.java index 140cbb1..a1486b6 100644 --- a/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyRpcService.java +++ b/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyRpcService.java @@ -25,10 +25,15 @@ import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; - +import org.apache.ratis.client.impl.ClientProtoUtils; import org.apache.ratis.netty.NettyConfigKeys; +import org.apache.ratis.netty.NettyRpcProxy; +import org.apache.ratis.protocol.RaftClientReply; +import org.apache.ratis.protocol.RaftPeer; import org.apache.ratis.protocol.RaftPeerId; -import org.apache.ratis.RpcType; +import org.apache.ratis.rpc.SupportedRpcType; +import org.apache.ratis.server.RaftServer; +import org.apache.ratis.server.RaftServerRpc; import org.apache.ratis.shaded.io.netty.handler.codec.protobuf.ProtobufDecoder; import org.apache.ratis.shaded.io.netty.handler.codec.protobuf.ProtobufEncoder; import org.apache.ratis.shaded.io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder; @@ -37,12 +42,6 @@ import org.apache.ratis.shaded.proto.RaftProtos.*; import org.apache.ratis.shaded.proto.netty.NettyProtos.RaftNettyExceptionReplyProto; import org.apache.ratis.shaded.proto.netty.NettyProtos.RaftNettyServerReplyProto; import org.apache.ratis.shaded.proto.netty.NettyProtos.RaftNettyServerRequestProto; -import org.apache.ratis.client.impl.ClientProtoUtils; -import org.apache.ratis.netty.NettyRpcProxy; -import org.apache.ratis.protocol.RaftClientReply; -import org.apache.ratis.protocol.RaftPeer; -import org.apache.ratis.server.RaftServer; -import org.apache.ratis.server.RaftServerRpc; import org.apache.ratis.util.CodeInjectionForTesting; import org.apache.ratis.util.LifeCycle; import org.apache.ratis.util.ProtoUtils; @@ -126,8 +125,8 @@ public final class NettyRpcService implements RaftServerRpc { } @Override - public RpcType getRpcType() { - return RpcType.NETTY; + public SupportedRpcType getRpcType() { + return SupportedRpcType.NETTY; } private Channel getChannel() { http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-netty/src/test/java/org/apache/ratis/netty/MiniRaftClusterWithNetty.java ---------------------------------------------------------------------- diff --git a/ratis-netty/src/test/java/org/apache/ratis/netty/MiniRaftClusterWithNetty.java b/ratis-netty/src/test/java/org/apache/ratis/netty/MiniRaftClusterWithNetty.java index 7167d0d..d6d1dc9 100644 --- a/ratis-netty/src/test/java/org/apache/ratis/netty/MiniRaftClusterWithNetty.java +++ b/ratis-netty/src/test/java/org/apache/ratis/netty/MiniRaftClusterWithNetty.java @@ -20,12 +20,12 @@ package org.apache.ratis.netty; import org.apache.ratis.MiniRaftCluster; import org.apache.ratis.RaftConfigKeys; import org.apache.ratis.RaftTestUtil; -import org.apache.ratis.RpcType; import org.apache.ratis.client.RaftClientRequestSender; import org.apache.ratis.conf.RaftProperties; import org.apache.ratis.netty.client.NettyClientRequestSender; import org.apache.ratis.netty.server.NettyRpcService; import org.apache.ratis.protocol.RaftPeerId; +import org.apache.ratis.rpc.SupportedRpcType; import org.apache.ratis.server.impl.DelayLocalExecutionInjection; import org.apache.ratis.server.impl.RaftServerImpl; @@ -35,7 +35,7 @@ public class MiniRaftClusterWithNetty extends MiniRaftCluster.RpcBase { @Override public MiniRaftClusterWithNetty newCluster( String[] ids, RaftProperties prop, boolean formatted) { - RaftConfigKeys.Rpc.setType(prop::setEnum, RpcType.NETTY); + RaftConfigKeys.Rpc.setType(prop::set, SupportedRpcType.NETTY); return new MiniRaftClusterWithNetty(ids, prop, formatted); } }; http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-server/src/main/java/org/apache/ratis/server/RaftServer.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/main/java/org/apache/ratis/server/RaftServer.java b/ratis-server/src/main/java/org/apache/ratis/server/RaftServer.java index 3eed3c1..7417e0d 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/RaftServer.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/RaftServer.java @@ -17,13 +17,13 @@ */ package org.apache.ratis.server; -import com.google.common.base.Preconditions; -import org.apache.ratis.RpcType; import org.apache.ratis.conf.RaftProperties; import org.apache.ratis.protocol.RaftClientAsynchronousProtocol; import org.apache.ratis.protocol.RaftClientProtocol; import org.apache.ratis.protocol.RaftPeer; import org.apache.ratis.protocol.RaftPeerId; +import org.apache.ratis.rpc.RpcType; +import org.apache.ratis.server.impl.RaftConfiguration; import org.apache.ratis.server.impl.ServerFactory; import org.apache.ratis.server.impl.ServerImplUtils; import org.apache.ratis.server.protocol.RaftServerProtocol; @@ -31,6 +31,7 @@ import org.apache.ratis.statemachine.StateMachine; import java.io.Closeable; import java.io.IOException; +import java.util.Objects; /** Raft server interface */ public interface RaftServer extends Closeable, RpcType.Get, RaftServerProtocol, @@ -67,13 +68,11 @@ public interface RaftServer extends Closeable, RpcType.Get, RaftServerProtocol, /** @return a {@link RaftServer} object. */ public RaftServer build() throws IOException { - Preconditions.checkNotNull(stateMachine); - Preconditions.checkNotNull(peers); - Preconditions.checkNotNull(properties); - Preconditions.checkNotNull(serverId); - - return ServerImplUtils.newRaftServer(serverId, stateMachine, peers, - properties); + return ServerImplUtils.newRaftServer( + Objects.requireNonNull(serverId, "The 'serverId' field is not initialized."), + Objects.requireNonNull(stateMachine, "The 'stateMachine' is not initialized."), + Objects.requireNonNull(peers, "The 'peers' field is not initialized."), + Objects.requireNonNull(properties, "The 'properties' field is not initialized.")); } /** Set the server ID. */ http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-server/src/main/java/org/apache/ratis/server/RaftServerConfigKeys.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/main/java/org/apache/ratis/server/RaftServerConfigKeys.java b/ratis-server/src/main/java/org/apache/ratis/server/RaftServerConfigKeys.java index 1203cdd..7721d3c 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/RaftServerConfigKeys.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/RaftServerConfigKeys.java @@ -17,52 +17,10 @@ */ package org.apache.ratis.server; -import org.apache.ratis.RpcType; - public interface RaftServerConfigKeys { String PREFIX = "raft.server"; - enum Factory { - NETTY("org.apache.ratis.netty.NettyFactory"), - GRPC("org.apache.ratis.grpc.server.GrpcServerFactory"), - HADOOP("org.apache.ratis.hadooprpc.HadoopFactory"), - SIMULATED("org.apache.ratis.server.simulation.SimulationFactory"); - - public static String getKey(String rpcType) { - return RaftServerConfigKeys.PREFIX + ".factory." + rpcType + ".class"; - } - - public static Factory valueOf(RpcType rpcType) { - return valueOf(rpcType.name()); - } - - private final RpcType rpcType = RpcType.valueOf(name()); - private final String key = getKey(name().toLowerCase()); - private final String defaultClass; - - Factory(String defaultClass) { - this.defaultClass = defaultClass; - } - - public RpcType getRpcType() { - return rpcType; - } - - public String getKey() { - return key; - } - - public String getDefaultClass() { - return defaultClass; - } - - @Override - public String toString() { - return getRpcType() + ":" + getKey() + ":" + getDefaultClass(); - } - } - String RAFT_SERVER_USE_MEMORY_LOG_KEY = "raft.server.use.memory.log"; boolean RAFT_SERVER_USE_MEMORY_LOG_DEFAULT = false; http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-server/src/main/java/org/apache/ratis/server/RaftServerRpc.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/main/java/org/apache/ratis/server/RaftServerRpc.java b/ratis-server/src/main/java/org/apache/ratis/server/RaftServerRpc.java index 40a8363..77958c0 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/RaftServerRpc.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/RaftServerRpc.java @@ -17,7 +17,7 @@ */ package org.apache.ratis.server; -import org.apache.ratis.RpcType; +import org.apache.ratis.rpc.RpcType; import org.apache.ratis.protocol.RaftPeer; import org.apache.ratis.server.protocol.RaftServerProtocol; http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java index c5fe336..470141c 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java @@ -20,7 +20,7 @@ package org.apache.ratis.server.impl; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import org.apache.ratis.RaftConfigKeys; -import org.apache.ratis.RpcType; +import org.apache.ratis.rpc.RpcType; import org.apache.ratis.conf.RaftProperties; import org.apache.ratis.protocol.*; import org.apache.ratis.server.RaftServer; @@ -66,7 +66,6 @@ public class RaftServerImpl implements RaftServer { LEADER, CANDIDATE, FOLLOWER } - private final RpcType rpcType; private final int minTimeoutMs; private final int maxTimeoutMs; @@ -93,7 +92,6 @@ public class RaftServerImpl implements RaftServer { RaftConfiguration raftConf, RaftProperties properties) throws IOException { this.lifeCycle = new LifeCycle(id); - this.rpcType = RaftConfigKeys.Rpc.type(properties::getEnum); minTimeoutMs = properties.getInt( RaftServerConfigKeys.RAFT_SERVER_RPC_TIMEOUT_MIN_MS_KEY, RaftServerConfigKeys.RAFT_SERVER_RPC_TIMEOUT_MIN_MS_DEFAULT); @@ -105,13 +103,15 @@ public class RaftServerImpl implements RaftServer { this.properties = properties; this.stateMachine = stateMachine; this.state = new ServerState(id, raftConf, properties, this, stateMachine); - this.factory = ServerFactory.Util.newServerFactory(rpcType, properties); + + final RpcType rpcType = RaftConfigKeys.Rpc.type(properties); + this.factory = ServerFactory.cast(rpcType.newFactory(properties)); this.serverRpc = RaftUtils.memoize(() -> initRaftServerRpc()); } @Override public RpcType getRpcType() { - return rpcType; + return getFactory().getRpcType(); } @Override http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerFactory.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerFactory.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerFactory.java index 2b7fb77..e7fb3cc 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerFactory.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerFactory.java @@ -17,18 +17,20 @@ */ package org.apache.ratis.server.impl; -import org.apache.ratis.conf.RaftProperties; -import org.apache.ratis.RpcType; -import org.apache.ratis.server.RaftServer; -import org.apache.ratis.server.RaftServerConfigKeys; +import org.apache.ratis.rpc.RpcFactory; import org.apache.ratis.server.RaftServerRpc; -import org.apache.ratis.util.RaftUtils; - -import java.io.IOException; -import java.util.Objects; /** A factory interface for creating server components. */ -public interface ServerFactory { +public interface ServerFactory extends RpcFactory { + static ServerFactory cast(RpcFactory rpcFactory) { + if (rpcFactory instanceof ServerFactory) { + return (ServerFactory)rpcFactory; + } + throw new ClassCastException("Cannot cast " + rpcFactory.getClass() + + " to " + ServerFactory.class + + "; rpc type is " + rpcFactory.getRpcType()); + } + /** Create a new {@link LogAppender}. */ LogAppender newLogAppender(RaftServerImpl server, LeaderState state, FollowerInfo f); @@ -41,20 +43,4 @@ public interface ServerFactory { return new LogAppender(server, state, f); } } - - class Util { - private static <T extends ServerFactory> Class<T> getClass( - RaftServerConfigKeys.Factory f, RaftProperties properties) { - final Class<T> defaultClass = (Class<T>) properties.getClassByNameOrNull(f.getDefaultClass()); - Objects.requireNonNull(defaultClass, () -> "Failed to get the default class for " + f); - return properties.getClass(f.getKey(), defaultClass, ServerFactory.class); - } - - /** Create a new {@link ServerFactory}. */ - public static <T extends ServerFactory> T newServerFactory( - RpcType rpcType, RaftProperties properties) { - return RaftUtils.newInstance( - getClass(RaftServerConfigKeys.Factory.valueOf(rpcType), properties)); - } - } } http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-server/src/test/java/org/apache/ratis/server/simulation/MiniRaftClusterWithSimulatedRpc.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/test/java/org/apache/ratis/server/simulation/MiniRaftClusterWithSimulatedRpc.java b/ratis-server/src/test/java/org/apache/ratis/server/simulation/MiniRaftClusterWithSimulatedRpc.java index 121159b..c978bbe 100644 --- a/ratis-server/src/test/java/org/apache/ratis/server/simulation/MiniRaftClusterWithSimulatedRpc.java +++ b/ratis-server/src/test/java/org/apache/ratis/server/simulation/MiniRaftClusterWithSimulatedRpc.java @@ -19,11 +19,11 @@ package org.apache.ratis.server.simulation; import org.apache.ratis.MiniRaftCluster; import org.apache.ratis.RaftConfigKeys; -import org.apache.ratis.RpcType; import org.apache.ratis.client.RaftClientRequestSender; import org.apache.ratis.conf.RaftProperties; import org.apache.ratis.protocol.RaftPeer; import org.apache.ratis.protocol.RaftPeerId; +import org.apache.ratis.rpc.SupportedRpcType; import org.apache.ratis.server.impl.RaftServerImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +41,7 @@ public class MiniRaftClusterWithSimulatedRpc extends MiniRaftCluster { @Override public MiniRaftClusterWithSimulatedRpc newCluster( String[] ids, RaftProperties prop, boolean formatted) { - RaftConfigKeys.Rpc.setType(prop::setEnum, RpcType.SIMULATED); + RaftConfigKeys.Rpc.setType(prop::set, SimulatedRpc.INSTANCE); if (ThreadLocalRandom.current().nextBoolean()) { // turn off simulate latency half of the times. prop.setInt(SimulatedRequestReply.SIMULATE_LATENCY_KEY, 0); @@ -74,7 +74,7 @@ public class MiniRaftClusterWithSimulatedRpc extends MiniRaftCluster { private void initRpc(RaftServerImpl s) { if (serverRequestReply != null) { - ((SimulationFactory)s.getFactory()).initRpc( + ((SimulatedRpc.Factory)s.getFactory()).initRpc( serverRequestReply, client2serverRequestReply); } } http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRpc.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRpc.java b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRpc.java new file mode 100644 index 0000000..ec85661 --- /dev/null +++ b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRpc.java @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ratis.server.simulation; + +import org.apache.ratis.conf.RaftProperties; +import org.apache.ratis.rpc.RpcFactory; +import org.apache.ratis.rpc.RpcType; +import org.apache.ratis.server.impl.RaftServerImpl; +import org.apache.ratis.server.impl.ServerFactory; + +import java.util.Objects; + +class SimulatedRpc implements RpcType { + static final SimulatedRpc INSTANCE = new SimulatedRpc(); + + @Override + public String name() { + return getClass().getName(); + } + + @Override + public RpcFactory newFactory(RaftProperties properties) { + return new Factory(); + } + + static class Factory extends ServerFactory.BaseFactory { + private SimulatedRequestReply<RaftServerRequest, RaftServerReply> serverRequestReply; + private SimulatedClientRequestReply client2serverRequestReply; + + public void initRpc( + SimulatedRequestReply<RaftServerRequest, RaftServerReply> serverRequestReply, + SimulatedClientRequestReply client2serverRequestReply) { + this.serverRequestReply = Objects.requireNonNull(serverRequestReply); + this.client2serverRequestReply = Objects.requireNonNull(client2serverRequestReply); + } + + @Override + public SimulatedServerRpc newRaftServerRpc(RaftServerImpl server) { + return new SimulatedServerRpc(server, serverRequestReply, client2serverRequestReply); + } + + @Override + public RpcType getRpcType() { + return INSTANCE; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java index c8257ac..8344453 100644 --- a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java +++ b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java @@ -17,30 +17,25 @@ */ package org.apache.ratis.server.simulation; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import org.apache.ratis.RpcType; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.apache.ratis.protocol.RaftClientReply; import org.apache.ratis.protocol.RaftClientRequest; import org.apache.ratis.protocol.RaftPeer; import org.apache.ratis.protocol.SetConfigurationRequest; +import org.apache.ratis.rpc.SupportedRpcType; +import org.apache.ratis.rpc.RpcType; import org.apache.ratis.server.RaftServerRpc; import org.apache.ratis.server.impl.RaftServerImpl; -import org.apache.ratis.shaded.proto.RaftProtos.AppendEntriesReplyProto; -import org.apache.ratis.shaded.proto.RaftProtos.AppendEntriesRequestProto; -import org.apache.ratis.shaded.proto.RaftProtos.InstallSnapshotReplyProto; -import org.apache.ratis.shaded.proto.RaftProtos.InstallSnapshotRequestProto; -import org.apache.ratis.shaded.proto.RaftProtos.RequestVoteReplyProto; -import org.apache.ratis.shaded.proto.RaftProtos.RequestVoteRequestProto; +import org.apache.ratis.shaded.proto.RaftProtos.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.util.concurrent.ThreadFactoryBuilder; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; class SimulatedServerRpc implements RaftServerRpc { static final Logger LOG = LoggerFactory.getLogger(SimulatedServerRpc.class); @@ -62,8 +57,8 @@ class SimulatedServerRpc implements RaftServerRpc { } @Override - public RpcType getRpcType() { - return RpcType.SIMULATED; + public SimulatedRpc getRpcType() { + return SimulatedRpc.INSTANCE; } @Override http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/718fa9ea/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulationFactory.java ---------------------------------------------------------------------- diff --git a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulationFactory.java b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulationFactory.java deleted file mode 100644 index d0b3d38..0000000 --- a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulationFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ratis.server.simulation; - -import org.apache.ratis.server.RaftServerRpc; -import org.apache.ratis.server.impl.RaftServerImpl; -import org.apache.ratis.server.impl.ServerFactory; - -import java.util.Objects; - -public class SimulationFactory extends ServerFactory.BaseFactory { - private SimulatedRequestReply<RaftServerRequest, RaftServerReply> serverRequestReply; - private SimulatedClientRequestReply client2serverRequestReply; - - public void initRpc( - SimulatedRequestReply<RaftServerRequest, RaftServerReply> serverRequestReply, - SimulatedClientRequestReply client2serverRequestReply) { - this.serverRequestReply = Objects.requireNonNull(serverRequestReply); - this.client2serverRequestReply = Objects.requireNonNull(client2serverRequestReply); - } - - @Override - public RaftServerRpc newRaftServerRpc(RaftServerImpl server) { - return new SimulatedServerRpc(server, serverRequestReply, client2serverRequestReply); - } -}
