Class DefaultChunkedPacketSenderBuilder

java.lang.Object
eu.cloudnetservice.driver.network.chunk.defaults.builder.DefaultChunkedPacketSenderBuilder
All Implemented Interfaces:
ChunkedPacketSender.Builder
Direct Known Subclasses:
FileChunkedPacketSenderBuilder

public abstract class DefaultChunkedPacketSenderBuilder extends Object implements ChunkedPacketSender.Builder
Represents a default abstract implementation of a chunked packet sender builder for other types of transfer to expand.
Since:
4.0
See Also:
  • Field Details

    • DEFAULT_CHUNK_SIZE

      public static final int DEFAULT_CHUNK_SIZE
      See Also:
    • source

      protected InputStream source
    • transferChannel

      protected String transferChannel
    • packetSplitter

      protected Consumer<Packet> packetSplitter
    • chunkSize

      protected int chunkSize
    • sessionUniqueId

      protected UUID sessionUniqueId
    • transferInformation

      protected DataBuf transferInformation
  • Constructor Details

    • DefaultChunkedPacketSenderBuilder

      public DefaultChunkedPacketSenderBuilder()
  • Method Details

    • chunkSize

      @NonNull public ChunkedPacketSender.Builder chunkSize(int chunkSize)
      Sets the size each chunk has except for the last one must have. This defaults to 1 MB. The supplied value must be greater than 0.
      Specified by:
      chunkSize in interface ChunkedPacketSender.Builder
      Parameters:
      chunkSize - the size of each transferred chunk.
      Returns:
      the same builder as used to call the method, for chaining.
    • sessionUniqueId

      Sets the unique id of the session. This defaults to a random id.
      Specified by:
      sessionUniqueId in interface ChunkedPacketSender.Builder
      Parameters:
      uuid - the session id to use.
      Returns:
      the same builder as used to call the method, for chaining.
    • transferChannel

      @NonNull public ChunkedPacketSender.Builder transferChannel(@NonNull @NonNull String transferChannel)
      Sets the name of the transfer channel. This option is required to be set by yourself. The channel role is just identification of the incoming data. There should never be two channels named the same way.
      Specified by:
      transferChannel in interface ChunkedPacketSender.Builder
      Parameters:
      transferChannel - the transfer channel name to use.
      Returns:
      the same builder as used to call the method, for chaining.
    • source

      Sets the source of this data transfer. This option is required to be set by yourself. The source stream should not be closed by you, it will be closed when the transfer finished successfully.
      Specified by:
      source in interface ChunkedPacketSender.Builder
      Parameters:
      source - the data source of the transfer.
      Returns:
      the same builder as used to call the method, for chaining.
    • toChannels

      @NonNull public ChunkedPacketSender.Builder toChannels(NetworkChannel @NonNull ... channels)
      Sends each chunk data packet to all the provided channels. You need to call one of these methods:
      • toChannels(NetworkChannel...)
      • toChannels(Collection)
      • packetSplitter(Consumer)
      to set the packet splitter of this sender which is required.
      Specified by:
      toChannels in interface ChunkedPacketSender.Builder
      Parameters:
      channels - the channels to send the packet to.
      Returns:
      the same builder as used to call the method, for chaining.
    • toChannels

      Sends each chunk data packet to all the provided channels. You need to call one of these methods:
      • toChannels(NetworkChannel...)
      • toChannels(Collection)
      • packetSplitter(Consumer)
      to set the packet splitter of this sender which is required.
      Specified by:
      toChannels in interface ChunkedPacketSender.Builder
      Parameters:
      channels - the channels to send the packet to.
      Returns:
      the same builder as used to call the method, for chaining.
    • packetSplitter

      Sets the handler and processor of each packet which will be sent during the chunked data transfer. You need to call one of these methods:
      • toChannels(NetworkChannel...)
      • toChannels(Collection)
      • packetSplitter(Consumer)
      to set the packet splitter of this sender which is required.
      Specified by:
      packetSplitter in interface ChunkedPacketSender.Builder
      Parameters:
      splitter - the custom packet splitter to use.
      Returns:
      the same builder as used to call the method, for chaining.
    • withExtraData

      @NonNull public ChunkedPacketSender.Builder withExtraData(@NonNull @NonNull DataBuf extraData)
      Sets the extra information provided to each target component when opening a chunked session. The data is mainly used for identifying specific parts of the transfer, for example the target file name might be a use case. This defaults to an empty buffer.
      Specified by:
      withExtraData in interface ChunkedPacketSender.Builder
      Parameters:
      extraData - the extra data to sent initially.
      Returns:
      the same builder as used to call the method, for chaining.
    • build

      Builds the chunked packet sender based on the supplied information in this builder.
      Specified by:
      build in interface ChunkedPacketSender.Builder
      Returns:
      the instance build from the information.
    • doBuild

      @NonNull protected abstract @NonNull ChunkedPacketSender doBuild()
      Delegate method which must get overridden by any class which extends from this builder. The method is used to actually build the sender while being sure that there are no violations to the build contract (the delegation method should, but must not be assertion free).
      Returns:
      the sender instance build based on the information supplied to this builder.
      Throws:
      NullPointerException - if any assertions must be made separately and fails.