iamsmkr commented on issue #218:
URL: https://github.com/apache/arrow-cookbook/issues/218#issuecomment-1138664719
@lidavidm This is how I create the server. Anything suspicious here?
```java
package com.iamsmkr.arrowflight;
import org.apache.arrow.flight.FlightServer;
import org.apache.arrow.flight.Location;
import org.apache.arrow.memory.BufferAllocator;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ArrowFlightServer {
private final BufferAllocator allocator;
private final FlightServer flightServer;
volatile private boolean started = false;
public ArrowFlightServer(String address, int port, BufferAllocator
allocator) {
Location location = Location.forGrpcInsecure(address, port);
this.allocator = allocator;
this.flightServer =
FlightServer.builder(
allocator,
location,
new ArrowFlightProducer(allocator, location)
).build();
ExecutorService service = Executors.newCachedThreadPool();
service.submit(() -> {
try {
synchronized (flightServer) {
flightServer.start();
started = true;
System.out.println("ArrowFlight server started.
Listening on port " + flightServer.getPort());
flightServer.notify();
}
flightServer.awaitTermination();
} catch (IOException e) {
System.out.println("Failed to start ArrowFlight server! " +
e.getMessage());
e.printStackTrace();
} catch (InterruptedException e) {
// e.printStackTrace();
} finally {
close();
}
});
}
public void waitForServerToStart() {
synchronized (flightServer) {
while (!started) {
try {
flightServer.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public void close() {
try {
flightServer.shutdown();
allocator.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]