Client-Side Implementation of Unary RPC
Write the client implementation of the deleteFile method.
When a user wants to delete a file, they pass the name of the file and the address of the server where the file is stored as command line arguments. On the client-side, we will parse the arguments and, if certain conditions are met, call the deleteFile
method of the SampleCLIClient
class. This method will call the deleteFile
method of the FTPServiceClient
class. In this lesson we show the client side implementation of the unary deleteFile
RPC. The client side is implemented in the ftp-service-client
module and it is called using the ftp-service-cli-client
module.
Client side implementation of deleteFile
method
The ftp-service-client
module contains the client implementation of the FTP service. Open the FTPServiceClient
class from the src/main/java/io/datajek/ftpservice/client
package. We will create a deleteFile
method as follows:
public class FTPServiceClient implements AutoCloseable {//...public void deleteFile(String filenameToDelete, StreamObserver<Result> resultStreamObserver) {}}
The deleteFile
method deletes a file from the server’s destination directory. The client sends a request to the server with the filename to delete. The server responds with the result of the operation.
The method takes two input parameters:
filenameToDelete
: This parameter is a string that represents the name of the file we want to delete on the server.resultStreamObserver
: It is aStreamObserver
that allows the client to receive asynchronous responses from the server. In this case, it’s used to handle the server’s response to the delete file request.
Inside the deleteFile
method, we will send the file name to delete as a MetaData
message. The message is created as follows:
MetaData.newBuilder()
creates a new builder instance for theMetaData
message....