You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2020/08/06 00:27:20 UTC

[GitHub] [incubator-ratis] szetszwo commented on a change in pull request #164: RATIS-1011 - Interfaces for client, server for netty streaming

szetszwo commented on a change in pull request #164:
URL: https://github.com/apache/incubator-ratis/pull/164#discussion_r466071843



##########
File path: ratis-client/src/main/java/org/apache/ratis/client/DataStreamClient.java
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.client;
+
+import org.apache.ratis.RaftConfigKeys;
+import org.apache.ratis.datastream.DataStreamApi;
+import org.apache.ratis.client.impl.DataStreamClientImpl;
+import org.apache.ratis.conf.Parameters;
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.datastream.SupportedDataStreamType;
+import org.apache.ratis.datastream.objects.DataStreamReply;
+import org.apache.ratis.datastream.objects.DataStreamRequest;
+import org.apache.ratis.protocol.ClientId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * A client interface that sends request to the streaming pipeline.
+ * Associated with it will be a Netty Client.
+ */
+public interface DataStreamClient {
+
+  Logger LOG = LoggerFactory.getLogger(DataStreamClient.class);
+
+  /** Return Client id. */
+  ClientId getId();
+
+  /** Return Streamer Api instance. */
+  DataStreamApi getDataStreamApi();
+
+  /** Return Network transfer Api instance. */
+  RaftClientStream getNetworkTransferApi();
+
+  /**
+   * send to server via streaming.
+   * Return a completable future.
+   */
+  CompletableFuture<DataStreamReply> sendAsync(DataStreamRequest request);
+
+  /** To build {@link DataStreamClient} objects */
+  class Builder {
+    private ClientId clientId;
+    private RaftClientStream networkTransferApi;
+    private RaftProperties properties;
+    private Parameters parameters;
+
+    private Builder() {}
+
+    public DataStreamClientImpl build(){
+      if (clientId == null) {
+        clientId = ClientId.randomId();
+      }
+      if (properties != null) {
+        if (networkTransferApi == null) {
+          final SupportedDataStreamType streamType = RaftConfigKeys.DataStream.type(properties, LOG::debug);
+          networkTransferApi = DataStreamClientFactory.cast(streamType.newFactory(parameters))
+                                         .newRaftClientStream(clientId, properties);
+        }
+      }
+      return new DataStreamClientImpl(clientId, properties, networkTransferApi);
+    }
+
+    public Builder setClientId(ClientId clientId) {
+      this.clientId = clientId;
+      return this;
+    }
+
+    public Builder setParameters(Parameters parameters) {
+      this.parameters = parameters;
+      return this;
+    }
+
+    public Builder setNetworkTransferApi(RaftClientStream networkTransferApi){

Review comment:
       Please rename all networkTransferApi (and the related method like this one) to raftClientStream.

##########
File path: ratis-common/src/main/java/org/apache/ratis/datastream/RaftDataOutputStream.java
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.datastream;
+
+import org.apache.ratis.datastream.objects.DataStreamReply;
+import java.nio.ByteBuffer;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+public interface RaftDataOutputStream extends AutoCloseable {
+  CompletableFuture<DataStreamReply> sendAsync(ByteBuffer buf, long streamId, long packetId);

Review comment:
       We should not have long streamId, long packetId in this method since these are internal details hidden from user applications.

##########
File path: ratis-client/src/main/java/org/apache/ratis/client/DataStreamClient.java
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.client;
+
+import org.apache.ratis.RaftConfigKeys;
+import org.apache.ratis.datastream.DataStreamApi;
+import org.apache.ratis.client.impl.DataStreamClientImpl;
+import org.apache.ratis.conf.Parameters;
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.datastream.SupportedDataStreamType;
+import org.apache.ratis.datastream.objects.DataStreamReply;
+import org.apache.ratis.datastream.objects.DataStreamRequest;
+import org.apache.ratis.protocol.ClientId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * A client interface that sends request to the streaming pipeline.
+ * Associated with it will be a Netty Client.
+ */
+public interface DataStreamClient {
+
+  Logger LOG = LoggerFactory.getLogger(DataStreamClient.class);
+
+  /** Return Client id. */
+  ClientId getId();
+
+  /** Return Streamer Api instance. */
+  DataStreamApi getDataStreamApi();
+
+  /** Return Network transfer Api instance. */
+  RaftClientStream getNetworkTransferApi();

Review comment:
       DataStreamClient is for user application.  They should not access RaftClientStream directly so that we should remove this method.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org