Server-Side Implementation of Unary RPC
Understand how to implement a unary RPC method on the server side in gRPC to handle file deletion requests. This lesson covers verifying file existence, preventing directory deletion, executing file removal, sending appropriate responses, and logging each step in Java.
In this lesson, we show the server-side implementation of the unary deleteFile RPC. The server side is implemented in the ftp-service module. Open the FTPService class from the src/main/java/io/datajek/ftpservice/server package. This class implements the FTP service defined in the proto file. In the FTPService class defined in the Setting up a gRPC Service lesson, we have defined the deleteFile method as follows:
@Overridepublic void deleteFile(MetaData request, StreamObserver<Result> responseObserver) {}
Flowchart of deleteFile method
The deleteFile method handles the deletion of a file from the server’s destination directory. It performs checks for the file’s existence and type, attempts the deletion, sends the appropriate response to the client, and logs relevant information during the delete process. The flow chart of the method is shown below.
deleteFile method
On the ...