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 Summary
FieldsModifier and TypeFieldDescriptionprotected intstatic final intprotected UUIDprotected InputStreamprotected Stringprotected DataBuf -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the chunked packet sender based on the supplied information in this builder.chunkSize(int chunkSize) Sets the size each chunk has except for the last one must have.protected abstract @NonNull ChunkedPacketSenderdoBuild()Delegate method which must get overridden by any class which extends from this builder.packetSplitter(@NonNull Consumer<Packet> splitter) Sets the handler and processor of each packet which will be sent during the chunked data transfer.sessionUniqueId(@NonNull UUID uuid) Sets the unique id of the session.source(@NonNull InputStream source) Sets the source of this data transfer.toChannels(NetworkChannel @NonNull ... channels) Sends each chunk data packet to all the provided channels.toChannels(@NonNull Collection<NetworkChannel> channels) Sends each chunk data packet to all the provided channels.transferChannel(@NonNull String transferChannel) Sets the name of the transfer channel.withExtraData(@NonNull DataBuf extraData) Sets the extra information provided to each target component when opening a chunked session.
-
Field Details
-
DEFAULT_CHUNK_SIZE
public static final int DEFAULT_CHUNK_SIZE- See Also:
-
source
-
transferChannel
-
packetSplitter
-
chunkSize
protected int chunkSize -
sessionUniqueId
-
transferInformation
-
-
Constructor Details
-
DefaultChunkedPacketSenderBuilder
public DefaultChunkedPacketSenderBuilder()
-
-
Method Details
-
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:
chunkSizein interfaceChunkedPacketSender.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:
sessionUniqueIdin interfaceChunkedPacketSender.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:
transferChannelin interfaceChunkedPacketSender.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:
sourcein interfaceChunkedPacketSender.Builder- Parameters:
source- the data source of the transfer.- 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)
- Specified by:
toChannelsin interfaceChunkedPacketSender.Builder- Parameters:
channels- the channels to send the packet to.- Returns:
- the same builder as used to call the method, for chaining.
-
toChannels
@NonNull public ChunkedPacketSender.Builder toChannels(@NonNull @NonNull Collection<NetworkChannel> 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)
- Specified by:
toChannelsin interfaceChunkedPacketSender.Builder- Parameters:
channels- the channels to send the packet to.- Returns:
- the same builder as used to call the method, for chaining.
-
packetSplitter
@NonNull public ChunkedPacketSender.Builder packetSplitter(@NonNull @NonNull Consumer<Packet> splitter) 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)
- Specified by:
packetSplitterin interfaceChunkedPacketSender.Builder- Parameters:
splitter- the custom packet splitter to use.- Returns:
- the same builder as used to call the method, for chaining.
-
withExtraData
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:
withExtraDatain interfaceChunkedPacketSender.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:
buildin interfaceChunkedPacketSender.Builder- Returns:
- the instance build from the information.
-
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.
-