You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/11 12:29:19 UTC

[GitHub] [arrow] lidavidm commented on a diff in pull request #12847: ARROW-15577: [Java][Doc] WIP - Apache Arrow Flight documentation

lidavidm commented on code in PR #12847:
URL: https://github.com/apache/arrow/pull/12847#discussion_r847265336


##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.

Review Comment:
   ```suggestion
   Flight servers implement the `FlightProducer`_ interface. For convenience,
   they can subclass `NoOpFlightProducer`_ instead, which offers default
   implementations of all the RPC methods.
   ```



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+

Review Comment:
   See #12815 where we explain ServerCallContext and errors here.



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 0);
+
+    try(
+        BufferAllocator allocator = new RootAllocator();
+        FlightServer tutorialFlightServer = FlightServer.builder(
+                allocator,
+                location,
+                new TutorialFlightProducer()
+        ).build();
+    ){
+        tutorialFlightServer.start();
+        System.out.println("Server listening on port " + tutorialFlightServer.getPort());
+
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            try {
+                System.out.println("\nExiting command...");
+                AutoCloseables.close(tutorialFlightServer, allocator);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }));
+        tutorialFlightServer.awaitTermination();
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+.. code-block:: shell
+
+    Server listening on port 58104
+
+Using the Flight Client
+=======================
+
+To connect to a Flight service, call `FlightClient.builder` with a location.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58104);
+
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+        // ... Consume operations exposed by Flight Server
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+Cancellation and Timeouts
+=========================
+
+When making a call, clients can optionally provide `CallOptions`. This allows
+clients to set a timeout on calls. Also, some objects returned by client RPC calls
+expose a cancel method which allows terminating a call early.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.CallOptions;
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+
+    import java.util.Iterator;
+    import java.util.concurrent.TimeUnit;
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58609);
+
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+
+        Iterator<Result> resultIterator = tutorialFlightClient.doAction(
+                new Action("test-timeout"),
+                CallOptions.timeout(2, TimeUnit.SECONDS)
+        );
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+On the server side, timeouts are transparent. For cancellation, the server needs to manually poll
+`setOnCancelHandler` or `isCancelled` to check if the client has cancelled the call, and if so,
+break out of any processing the server is currently doing.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import java.nio.charset.StandardCharsets;
+
+    // Client
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58609);
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+        try(FlightStream flightStream = tutorialFlightClient.getStream(new Ticket(
+                FlightDescriptor.path("profiles").getPath().get(0).getBytes(StandardCharsets.UTF_8)))) {

Review Comment:
   Er, just do `new byte[]{}` or something.



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 0);
+
+    try(
+        BufferAllocator allocator = new RootAllocator();
+        FlightServer tutorialFlightServer = FlightServer.builder(
+                allocator,
+                location,
+                new TutorialFlightProducer()
+        ).build();
+    ){
+        tutorialFlightServer.start();
+        System.out.println("Server listening on port " + tutorialFlightServer.getPort());
+
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            try {
+                System.out.println("\nExiting command...");
+                AutoCloseables.close(tutorialFlightServer, allocator);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }));
+        tutorialFlightServer.awaitTermination();
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+.. code-block:: shell
+
+    Server listening on port 58104
+
+Using the Flight Client
+=======================
+
+To connect to a Flight service, call `FlightClient.builder` with a location.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58104);
+
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+        // ... Consume operations exposed by Flight Server
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+Cancellation and Timeouts
+=========================
+
+When making a call, clients can optionally provide `CallOptions`. This allows
+clients to set a timeout on calls. Also, some objects returned by client RPC calls
+expose a cancel method which allows terminating a call early.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.CallOptions;
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+
+    import java.util.Iterator;
+    import java.util.concurrent.TimeUnit;
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58609);
+
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+
+        Iterator<Result> resultIterator = tutorialFlightClient.doAction(
+                new Action("test-timeout"),
+                CallOptions.timeout(2, TimeUnit.SECONDS)
+        );
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+On the server side, timeouts are transparent. For cancellation, the server needs to manually poll
+`setOnCancelHandler` or `isCancelled` to check if the client has cancelled the call, and if so,
+break out of any processing the server is currently doing.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import java.nio.charset.StandardCharsets;
+
+    // Client
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58609);
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+        try(FlightStream flightStream = tutorialFlightClient.getStream(new Ticket(
+                FlightDescriptor.path("profiles").getPath().get(0).getBytes(StandardCharsets.UTF_8)))) {
+            // ...
+            flightStream.cancel("tutorial-cancel", new Exception("Testing cancellation opion!"));
+        }
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+    // Server
+    @Override
+    public void getStream(CallContext context, Ticket ticket, ServerStreamListener listener) {
+        // ...
+        listener.setOnCancelHandler(()->{
+                    // Implement logic to handle cancellation option
+                });
+    }
+
+Enabling TLS
+============
+
+TLS can be enabled when setting up a server by providing a certificate and key pair to `FlightServer.builder.useTls`.
+
+On the client side, use `FlightClient.builder.trustedCertificates`.
+
+Enabling Authentication
+=======================
+
+
+
+Custom Middleware
+=================
+
+Servers and clients support custom middleware (or interceptors) that are called on every
+request and can modify the request in a limited fashion. These can be implemented by implements

Review Comment:
   ```suggestion
   request and can modify the request in a limited fashion. These can be implemented by implementing the
   ```



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 0);
+
+    try(
+        BufferAllocator allocator = new RootAllocator();
+        FlightServer tutorialFlightServer = FlightServer.builder(

Review Comment:
   ```suggestion
           FlightServer server = FlightServer.builder(
   ```



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 0);
+
+    try(
+        BufferAllocator allocator = new RootAllocator();
+        FlightServer tutorialFlightServer = FlightServer.builder(
+                allocator,
+                location,
+                new TutorialFlightProducer()
+        ).build();
+    ){
+        tutorialFlightServer.start();
+        System.out.println("Server listening on port " + tutorialFlightServer.getPort());
+
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            try {
+                System.out.println("\nExiting command...");
+                AutoCloseables.close(tutorialFlightServer, allocator);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }));
+        tutorialFlightServer.awaitTermination();
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+.. code-block:: shell
+
+    Server listening on port 58104
+
+Using the Flight Client
+=======================
+
+To connect to a Flight service, call `FlightClient.builder` with a location.

Review Comment:
   Either use double-backticks or link to the javadocs.



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 0);
+
+    try(
+        BufferAllocator allocator = new RootAllocator();
+        FlightServer tutorialFlightServer = FlightServer.builder(
+                allocator,
+                location,
+                new TutorialFlightProducer()
+        ).build();
+    ){
+        tutorialFlightServer.start();
+        System.out.println("Server listening on port " + tutorialFlightServer.getPort());
+
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            try {
+                System.out.println("\nExiting command...");
+                AutoCloseables.close(tutorialFlightServer, allocator);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }));

Review Comment:
   The server/allocator are in the try-with-resources, why do we need this?



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.

Review Comment:
   ```suggestion
   To start a server, create a `Location`_ to specify where to listen, and then create
   a `FlightServer`_ with an instance of a producer. This will start the server, but
   won't block the rest of the program. Call ``FlightServer.awaitTermination``
   to block until the server stops.
   ```



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }

Review Comment:
   Either we should omit imports consistently, or include imports consistently. It looks like we've been omitting imports so far.



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 0);
+
+    try(
+        BufferAllocator allocator = new RootAllocator();
+        FlightServer tutorialFlightServer = FlightServer.builder(
+                allocator,
+                location,
+                new TutorialFlightProducer()
+        ).build();
+    ){
+        tutorialFlightServer.start();
+        System.out.println("Server listening on port " + tutorialFlightServer.getPort());
+
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            try {
+                System.out.println("\nExiting command...");
+                AutoCloseables.close(tutorialFlightServer, allocator);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }));
+        tutorialFlightServer.awaitTermination();
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+.. code-block:: shell
+
+    Server listening on port 58104
+
+Using the Flight Client
+=======================
+
+To connect to a Flight service, call `FlightClient.builder` with a location.

Review Comment:
   The same goes for below.



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 0);
+
+    try(
+        BufferAllocator allocator = new RootAllocator();
+        FlightServer tutorialFlightServer = FlightServer.builder(
+                allocator,
+                location,
+                new TutorialFlightProducer()
+        ).build();
+    ){
+        tutorialFlightServer.start();
+        System.out.println("Server listening on port " + tutorialFlightServer.getPort());
+
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            try {
+                System.out.println("\nExiting command...");
+                AutoCloseables.close(tutorialFlightServer, allocator);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }));
+        tutorialFlightServer.awaitTermination();
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+.. code-block:: shell
+
+    Server listening on port 58104
+
+Using the Flight Client
+=======================
+
+To connect to a Flight service, call `FlightClient.builder` with a location.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58104);
+
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+        // ... Consume operations exposed by Flight Server
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+Cancellation and Timeouts
+=========================
+
+When making a call, clients can optionally provide `CallOptions`. This allows
+clients to set a timeout on calls. Also, some objects returned by client RPC calls
+expose a cancel method which allows terminating a call early.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.CallOptions;
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+
+    import java.util.Iterator;
+    import java.util.concurrent.TimeUnit;
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58609);
+
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+
+        Iterator<Result> resultIterator = tutorialFlightClient.doAction(
+                new Action("test-timeout"),
+                CallOptions.timeout(2, TimeUnit.SECONDS)
+        );
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+On the server side, timeouts are transparent. For cancellation, the server needs to manually poll
+`setOnCancelHandler` or `isCancelled` to check if the client has cancelled the call, and if so,
+break out of any processing the server is currently doing.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import java.nio.charset.StandardCharsets;
+
+    // Client
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58609);
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+        try(FlightStream flightStream = tutorialFlightClient.getStream(new Ticket(
+                FlightDescriptor.path("profiles").getPath().get(0).getBytes(StandardCharsets.UTF_8)))) {
+            // ...
+            flightStream.cancel("tutorial-cancel", new Exception("Testing cancellation opion!"));
+        }
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+    // Server
+    @Override
+    public void getStream(CallContext context, Ticket ticket, ServerStreamListener listener) {
+        // ...
+        listener.setOnCancelHandler(()->{
+                    // Implement logic to handle cancellation option
+                });
+    }
+
+Enabling TLS
+============
+
+TLS can be enabled when setting up a server by providing a certificate and key pair to `FlightServer.builder.useTls`.
+
+On the client side, use `FlightClient.builder.trustedCertificates`.
+
+Enabling Authentication
+=======================
+
+
+
+Custom Middleware
+=================
+
+Servers and clients support custom middleware (or interceptors) that are called on every
+request and can modify the request in a limited fashion. These can be implemented by implements
+`FlightServerMiddleware` and `FlightClientMiddleware` interface methods.

Review Comment:
   ```suggestion
   `FlightServerMiddleware` and `FlightClientMiddleware` interfaces.
   ```



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 0);
+
+    try(
+        BufferAllocator allocator = new RootAllocator();
+        FlightServer tutorialFlightServer = FlightServer.builder(
+                allocator,
+                location,
+                new TutorialFlightProducer()
+        ).build();
+    ){
+        tutorialFlightServer.start();
+        System.out.println("Server listening on port " + tutorialFlightServer.getPort());
+
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            try {
+                System.out.println("\nExiting command...");
+                AutoCloseables.close(tutorialFlightServer, allocator);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }));
+        tutorialFlightServer.awaitTermination();
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+.. code-block:: shell
+
+    Server listening on port 58104
+
+Using the Flight Client
+=======================
+
+To connect to a Flight service, call `FlightClient.builder` with a location.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58104);
+
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+        // ... Consume operations exposed by Flight Server

Review Comment:
   ```suggestion
           // ... Consume operations exposed by Flight server
   ```



##########
docs/source/java/flight.rst:
##########
@@ -0,0 +1,302 @@
+.. 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.
+
+================
+Arrow Flight RPC
+================
+
+Arrow Flight is an RPC framework for efficient transfer of Flight data
+over the network.
+
+.. contents::
+
+.. seealso::
+
+   :doc:`Flight protocol documentation <../format/Flight>`
+        Documentation of the Flight protocol, including how to use
+        Flight conceptually.
+
+   `Java Cookbook <https://arrow.apache.org/cookbook/java/flight.html>`_
+        Recipes for using Arrow Flight in Java.
+
+Writing a Flight Service
+========================
+
+Arrow Flight is a development framework to offer to us the building blocks
+to implement applications base on our needs.
+
+In this journey, you need to implement how do you are planning to expose
+your business operations in base of RPC Methods and Request Patterns
+provided by Flight.
+
+For Flight Server side operations you need to implement FlightProducer interface
+methods.
+
+.. code-block:: Java
+
+    public class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+Also you need to specify where to listen for, let's combine producer and location
+to create and start the Flight Server. This will start the server, but won't block
+the rest of the program. Call `FlightServer.awaitTermination` to block until the
+server stops.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.ActionType;
+    import org.apache.arrow.flight.Criteria;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightInfo;
+    import org.apache.arrow.flight.FlightProducer;
+    import org.apache.arrow.flight.FlightServer;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.PutResult;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.flight.SchemaResult;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.util.AutoCloseables;
+
+    class TutorialFlightProducer implements FlightProducer {
+        @Override
+        // Override methods or use NoOpFlightProducer for only methods needed
+    }
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 0);
+
+    try(
+        BufferAllocator allocator = new RootAllocator();
+        FlightServer tutorialFlightServer = FlightServer.builder(
+                allocator,
+                location,
+                new TutorialFlightProducer()
+        ).build();
+    ){
+        tutorialFlightServer.start();
+        System.out.println("Server listening on port " + tutorialFlightServer.getPort());
+
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            try {
+                System.out.println("\nExiting command...");
+                AutoCloseables.close(tutorialFlightServer, allocator);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }));
+        tutorialFlightServer.awaitTermination();
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+.. code-block:: shell
+
+    Server listening on port 58104
+
+Using the Flight Client
+=======================
+
+To connect to a Flight service, call `FlightClient.builder` with a location.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58104);
+
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+        // ... Consume operations exposed by Flight Server
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+Cancellation and Timeouts
+=========================
+
+When making a call, clients can optionally provide `CallOptions`. This allows
+clients to set a timeout on calls. Also, some objects returned by client RPC calls
+expose a cancel method which allows terminating a call early.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.Action;
+    import org.apache.arrow.flight.CallOptions;
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.Result;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+
+    import java.util.Iterator;
+    import java.util.concurrent.TimeUnit;
+
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58609);
+
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+
+        Iterator<Result> resultIterator = tutorialFlightClient.doAction(
+                new Action("test-timeout"),
+                CallOptions.timeout(2, TimeUnit.SECONDS)
+        );
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+
+On the server side, timeouts are transparent. For cancellation, the server needs to manually poll
+`setOnCancelHandler` or `isCancelled` to check if the client has cancelled the call, and if so,
+break out of any processing the server is currently doing.
+
+.. code-block:: Java
+
+    import org.apache.arrow.flight.FlightClient;
+    import org.apache.arrow.flight.FlightDescriptor;
+    import org.apache.arrow.flight.FlightStream;
+    import org.apache.arrow.flight.Location;
+    import org.apache.arrow.flight.Ticket;
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import java.nio.charset.StandardCharsets;
+
+    // Client
+    Location location = Location.forGrpcInsecure("0.0.0.0", 58609);
+    try(BufferAllocator allocator = new RootAllocator();
+        FlightClient tutorialFlightClient = FlightClient.builder(allocator, location).build()){
+        try(FlightStream flightStream = tutorialFlightClient.getStream(new Ticket(
+                FlightDescriptor.path("profiles").getPath().get(0).getBytes(StandardCharsets.UTF_8)))) {
+            // ...
+            flightStream.cancel("tutorial-cancel", new Exception("Testing cancellation opion!"));
+        }
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+    // Server
+    @Override
+    public void getStream(CallContext context, Ticket ticket, ServerStreamListener listener) {
+        // ...
+        listener.setOnCancelHandler(()->{
+                    // Implement logic to handle cancellation option
+                });
+    }
+
+Enabling TLS
+============
+
+TLS can be enabled when setting up a server by providing a certificate and key pair to `FlightServer.builder.useTls`.
+
+On the client side, use `FlightClient.builder.trustedCertificates`.
+
+Enabling Authentication
+=======================
+
+
+
+Custom Middleware
+=================
+
+Servers and clients support custom middleware (or interceptors) that are called on every
+request and can modify the request in a limited fashion. These can be implemented by implements
+`FlightServerMiddleware` and `FlightClientMiddleware` interface methods.
+
+Middleware are fairly limited, but they can add headers to a request/response.
+
+Example: Need to intercept Flight server headers at request and print values also for the response

Review Comment:
   We don't really add examples for this in the other docs, this would be better off in the cookbook



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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