public class MessageSplitterBuilder extends AbstractParent<CloudhopperBuilder> implements Builder<MessageSplitter>
The splitter will check if the whole message can fit in a single segment. If not the splitter will split the whole message in several segments with a header to indicate splitting information such as number of segments, reference number and current segment number.
Encoder
configured using CloudhopperBuilder.encoder()
is used
to encode each segment.
If automatic guessing of best standard encoder is enabled for Encoder
(using encoder().autoGuess(true)
), and message splitting is enabled,
then standard message splitting is configured such as:
GsmMessageSplitter
is used to
split messages that support this encoding. If whole message can fit in a
single segment of 160 characters. Longer message is split into segments of
either 153 characters or 152 characters (depending on reference number
generation, see ReferenceNumberGenerator
)GsmMessageSplitter
is used to
split messages that support this encoding. If whole message can fit in a
single segment of 140 characters. Longer message is split into segments of
either 134 characters or 133 characters (depending on reference number
generation, see ReferenceNumberGenerator
)GsmMessageSplitter
is used to split
messages that support this encoding. If whole message can fit in a single
segment of 70 characters. Longer message is split into segments of either 67
characters or 66 characters (depending on reference number generation, see
ReferenceNumberGenerator
)Encoder
.
If you don't want standard message splitting based on supported
Encoder
s, you can either disable message splitting or provide a
custom splitter with higher priority.
This builder allows to configure:
.splitter()
.enable()
.properties("${ogham.sms.cloudhopper.split.enable}", "${ogham.sms.split.enable}")
.devaultValue(true)
.and()
.customSplitter(new MyCustomSplitter(), 100000)
.referenceNumber()
.random()
.random(new Random())
.generator(new MyCustomReferenceNumberGenerator())
parent
Constructor and Description |
---|
MessageSplitterBuilder(CloudhopperBuilder parent,
BuildContext buildContext,
ReadableEncoderBuilder encoderBuilder)
Initializes the builder with a parent builder.
|
Modifier and Type | Method and Description |
---|---|
MessageSplitter |
build()
Instantiate and configures the instance.
|
MessageSplitterBuilder |
customSplitter(MessageSplitter splitter)
Register a custom splitter strategy.
|
MessageSplitterBuilder |
customSplitter(MessageSplitter splitter,
int priority)
Register a custom splitter strategy in the chain of splitters.
|
ConfigurationValueBuilder<MessageSplitterBuilder,Boolean> |
enable()
Enable/disable message splitting.
|
MessageSplitterBuilder |
enable(Boolean enable)
Enable/disable message splitting.
|
ReferenceNumberGeneratorBuilder |
referenceNumber()
Configures how Cloudhopper should generate a reference number.
|
and
public MessageSplitterBuilder(CloudhopperBuilder parent, BuildContext buildContext, ReadableEncoderBuilder encoderBuilder)
AbstractParent.and()
method. The EnvironmentBuilder
is
used to evaluate properties when build()
method is called.parent
- the parent builderbuildContext
- for registering instances and property evaluationencoderBuilder
- the encoder builder that is used to configure standard message
splitting based on encoding charsetpublic MessageSplitterBuilder enable(Boolean enable)
The value set using this method takes precedence over any property and
default value configured using enable()
.
.enable(false) .enable() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(true)
.enable(false) .enable() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(true)In both cases,
enable(false)
is used.
If this method is called several times, only the last value is used.
If null
value is set, it is like not setting a value at all. The
property/default value configuration is applied.
enable
- enable or disable message splittingpublic ConfigurationValueBuilder<MessageSplitterBuilder,Boolean> enable()
This method is mainly used by Configurer
s to register some
property keys and/or a default value. The aim is to let developer be able
to externalize its configuration (using system properties, configuration
file or anything else). If the developer doesn't configure any value for
the registered properties, the default value is used (if set).
.enable() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(true)
Non-null value set using enable(Boolean)
takes precedence over
property values and default value.
.enable(false) .enable() .properties("${custom.property.high-priority}", "${custom.property.low-priority}") .defaultValue(true)The value
false
is used regardless of the value of the properties
and default value.
See ConfigurationValueBuilder
for more information.
public ReferenceNumberGeneratorBuilder referenceNumber()
Reference number is used to identify segments that belong to the same message. Every segment of the split message must have the same reference number.
This builder allows to configure:
Random
.referenceNumber()
.random()
.random(new Random())
.generator(new MyCustomReferenceNumberGenerator())
ReferenceNumberGenerator
public MessageSplitterBuilder customSplitter(MessageSplitter splitter)
Using this method totally disable all other features. Only the provided splitter is used.
If this method is called several times, only the last one is used.
If null
value is provided, then custom splitting is disabled.
splitter
- the splitter to usepublic MessageSplitterBuilder customSplitter(MessageSplitter splitter, int priority)
It is possible to register several custom splitters.
The priority is used to indicate in which order the custom splitter must be applied in the chain.
If the custom splitter implements SupportingSplitter
, then the
splitter can indicate if it is able to handle to message to split. If the
splitter can't handle the message, then the next splitter is tried.
If the custom splitter doesn't implement SupportingSplitter
, then
the splitter is considered as able to handle the message. Splitting is
used with this splitter. So if such splitter is registered with a higher
priority than others, no other splitter will be tried.
splitter
- the splitter to registerpriority
- the associated priority (greater value means higher priority)public MessageSplitter build()
Builder
build
in interface Builder<MessageSplitter>
Copyright © 2021. All rights reserved.