Package com.cloud.clientpak.services
Class FileWorker
java.lang.Object
com.cloud.clientpak.services.FileWorker
The class responsible for sending files to the cloud. When
sending a message with file data (size does not exceed 10 mb.), the file
cut into equal parts of 10 mb. and it is sent over the network in parts.
How many parts the file was cut into, the same number of messages will be
sequentially sent to the network. An important point of compliance with the order
sending such messages is synchronized in the sync() method.
ChannelFuture-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe maximum size of the transmitted message is 10 mb.private ConnectionNetwork connection.private ExecutorServiceThread pool.private longContains the number of bytes that the cloud is filled with.private booleanCheck whether the file needs to be overwritten. -
Constructor Summary
ConstructorsConstructorDescriptionThe constructor determines from the thread pool 1 the next thread to send messages, one thread is required due to the asynchronous nature of sending messages. -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckAddFile(File file, ChangeInterface changeInterface, boolean reWrite) Checks the file for availability in the cloud, if there is, then checks with the user whether it needs to be overwritten.voidsend(File file, ChangeInterface changeInterface) If the file is larger than 10 mb, it cuts it into pieces and sends it to the network.voidstop()
-
Field Details
-
BUFFER_SIZE
private final int BUFFER_SIZEThe maximum size of the transmitted message is 10 mb.- See Also:
-
reWriteFileCheck
private boolean reWriteFileCheckCheck whether the file needs to be overwritten. -
lastLoadSizeFiles
private long lastLoadSizeFilesContains the number of bytes that the cloud is filled with. -
connection
Network connection. -
executorService
Thread pool.
-
-
Constructor Details
-
FileWorker
public FileWorker()The constructor determines from the thread pool 1 the next thread to send messages, one thread is required due to the asynchronous nature of sending messages. If 2 or more parallel threads work, the principle will be violated asynchronous operation at Netty. And there will be confusion in the messages, which to which file it belongs to.- See Also:
-
-
Method Details
-
checkAddFile
Checks the file for availability in the cloud, if there is, then checks with the user whether it needs to be overwritten. Checks whether the storage limit will be exceeded data in the cloud after writing a file (If there is not enough space, it issues a message to the user about the lack of space).- Parameters:
file- a link to the file to be transferred to the cloud.changeInterface- CallBack for the user's GUI.reWrite- tells whether the file will be overwritten in the cloud.
-
send
If the file is larger than 10 mb, it cuts it into pieces and sends it to the network. After sending each message, CallBack is called to change the user's GUI.- Parameters:
file- a link to the file to be transferred to the cloud.changeInterface- CallBack for the user's GUI.
-
stop
public void stop()
-