Class Client
java.lang.Object
Client
public class Client
extends java.lang.Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classClient.FileAlreadyExistsExceptionclassClient.FileDoesNotExistExceptionclassClient.NotEnoughDstoresException -
Constructor Summary
Constructors Constructor Description Client(int cport, int timeout, Logger.LoggingType loggintType)This also initialises ClientLogger -
Method Summary
Modifier and Type Method Description voidconnect()Establishes a TCP connection with the Controller.voiddisconnect()java.lang.String[]list()Executes the List operationbyte[]load(java.lang.String filename)Executes the Load operationvoidload(java.lang.String filename, java.io.File fileFolder)Convenience method that callsload(String)method and stores the data received from the Dstore in a newfilenamefile infileFolderfolder.voidremove(java.lang.String filename)Executes the Remove operationvoidsend(java.lang.String message)This is for debug/test purposes.voidstore(java.io.File file)Convenience method that loads the content of the given file and then calls thestore(String, byte[])methodvoidstore(java.lang.String filename, byte[] data)Executes the Store operation
-
Constructor Details
-
Client
public Client(int cport, int timeout, Logger.LoggingType loggintType)This also initialises ClientLogger- Parameters:
cport- Controller porttimeout- timeout to read from sockets, in millisecondsloggintType-
-
-
Method Details
-
connect
public void connect() throws java.io.IOExceptionEstablishes a TCP connection with the Controller. If a connection is already established, it first invokesdisconnect()method- Throws:
java.io.IOException
-
disconnect
public void disconnect() throws java.io.IOException- Throws:
java.io.IOException
-
send
public void send(java.lang.String message)This is for debug/test purposes. It allows to send a custom String message to the Controller.- Parameters:
message-
-
list
Executes the List operation- Returns:
- the list of filenames sent by the Controller
- Throws:
java.io.IOExceptionClient.NotEnoughDstoresException- in case not enough Dstores have joined the Controller
-
store
public void store(java.io.File file) throws java.io.IOException, Client.NotEnoughDstoresException, Client.FileAlreadyExistsExceptionConvenience method that loads the content of the given file and then calls thestore(String, byte[])method- Parameters:
file- the local file to store- Throws:
java.io.IOException- note that an IOException is also thrown if the filename contains any spaceClient.NotEnoughDstoresException- in case not enough Dstore have joined the ControllerClient.FileAlreadyExistsException- if a file with the same filename is stored in the data store
-
store
public void store(java.lang.String filename, byte[] data) throws java.io.IOException, Client.NotEnoughDstoresException, Client.FileAlreadyExistsExceptionExecutes the Store operation- Parameters:
filename-data- the content of the file to store- Throws:
java.io.IOExceptionClient.NotEnoughDstoresException- in case not enough Dstore have joined the ControllerClient.FileAlreadyExistsException- if a file with the same filename is stored in the data store
-
load
public void load(java.lang.String filename, java.io.File fileFolder) throws java.io.IOException, Client.NotEnoughDstoresException, Client.FileDoesNotExistExceptionConvenience method that callsload(String)method and stores the data received from the Dstore in a newfilenamefile infileFolderfolder. Be careful!! This method will load the file from the data store and then store it in the local file system, in the specified folder and with the specified filename, overwriting any file with the same name already stored there. IffileFolderdoes not exist or is not a folder, anIOExceptionis thrown.- Parameters:
filename-fileFolder-- Throws:
java.io.IOExceptionClient.NotEnoughDstoresExceptionClient.FileDoesNotExistException
-
load
public byte[] load(java.lang.String filename) throws java.io.IOException, Client.NotEnoughDstoresException, Client.FileDoesNotExistExceptionExecutes the Load operation- Parameters:
filename-- Returns:
- Throws:
java.io.IOExceptionClient.NotEnoughDstoresExceptionClient.FileDoesNotExistException
-
remove
public void remove(java.lang.String filename) throws java.io.IOException, Client.NotEnoughDstoresException, Client.FileDoesNotExistExceptionExecutes the Remove operation- Parameters:
filename-- Throws:
java.io.IOExceptionClient.NotEnoughDstoresExceptionClient.FileDoesNotExistException
-