Class FileWorker

java.lang.Object
com.cloud.clientpak.services.FileWorker

public class FileWorker extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private final int
    The maximum size of the transmitted message is 10 mb.
    private Connection
    Network connection.
    Thread pool.
    private long
    Contains the number of bytes that the cloud is filled with.
    private boolean
    Check whether the file needs to be overwritten.
  • Constructor Summary

    Constructors
    Constructor
    Description
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    checkAddFile(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.
    void
    send(File file, ChangeInterface changeInterface)
    If the file is larger than 10 mb, it cuts it into pieces and sends it to the network.
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BUFFER_SIZE

      private final int BUFFER_SIZE
      The maximum size of the transmitted message is 10 mb.
      See Also:
    • reWriteFileCheck

      private boolean reWriteFileCheck
      Check whether the file needs to be overwritten.
    • lastLoadSizeFiles

      private long lastLoadSizeFiles
      Contains the number of bytes that the cloud is filled with.
    • connection

      private Connection connection
      Network connection.
    • executorService

      private ExecutorService 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

      public void checkAddFile(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. 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

      public void send(File file, ChangeInterface changeInterface)
      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()