Skip to content

PIP-468: V5 policy options use builder pattern#25657

Merged
merlimat merged 3 commits into
apache:masterfrom
merlimat:st-v5-policy-builder
May 3, 2026
Merged

PIP-468: V5 policy options use builder pattern#25657
merlimat merged 3 commits into
apache:masterfrom
merlimat:st-v5-policy-builder

Conversation

@merlimat
Copy link
Copy Markdown
Contributor

@merlimat merlimat commented May 3, 2026

Summary

Convert the V5 client policy options from records (with public canonical constructors) into final classes whose only construction paths are an explicit Builder and a small set of named factory methods. This keeps the public surface to deliberate, documented combinations and lets the classes evolve without breaking source compatibility every time a new field is added.

Refactored: BackoffPolicy, BatchingPolicy, ChunkingPolicy, CompressionPolicy, ConnectionPolicy, DeadLetterPolicy, EncryptionPolicy, ProcessingTimeoutPolicy, TlsPolicy, TransactionPolicy.

Each now has:

  • Private constructor.
  • private final fields with record-style accessors (foo() — backward compatible with existing callers).
  • A static builder() plus a fluent inner Builder with javadoc on each knob.
  • Small, opinionated factories where there's an obvious dominant case (e.g. CompressionPolicy.disabled(), TlsPolicy.ofInsecure(), BatchingPolicy.ofDisabled(), BackoffPolicy.fixed/exponential(initial, max), ProcessingTimeoutPolicy.of(timeout), EncryptionPolicy.forProducer/forConsumer).
  • Lombok @EqualsAndHashCode + @ToString to preserve value-type semantics.

Updated callers — Examples.java, V5DeadLetterPolicyTest, V5TransactionTest, V5ProducerBatchingTest — to use the builder/factory entry points.

Test plan

  • pulsar-client-api-v5 and pulsar-broker checkstyle clean.
  • V5 affected tests pass: V5DeadLetterPolicyTest, V5TransactionTest, V5ProducerBatchingTest, V5ProcessingTimeoutTest.

merlimat added 3 commits May 3, 2026 08:36
Convert the V5 client policy options from records (with public canonical
constructors) into final classes whose only construction paths are an
explicit Builder and a small set of named factory methods. This keeps the
public surface to the deliberate, documented combinations and lets the
classes evolve without breaking source compatibility on every new field.

Refactored: BackoffPolicy, BatchingPolicy, ChunkingPolicy, CompressionPolicy,
ConnectionPolicy, DeadLetterPolicy, EncryptionPolicy, ProcessingTimeoutPolicy,
TlsPolicy, TransactionPolicy. Each now exposes:

- Private constructor.
- private final fields with record-style accessors (foo() — backward
  compatible with existing callers).
- A static `builder()` plus a fluent inner `Builder` with javadoc per knob.
- Small, opinionated factories where there's an obvious dominant case
  (e.g. CompressionPolicy.disabled(), TlsPolicy.ofInsecure(),
  BatchingPolicy.ofDisabled(), BackoffPolicy.fixed(),
  BackoffPolicy.exponential(initial, max), ProcessingTimeoutPolicy.of(timeout),
  EncryptionPolicy.forProducer / forConsumer).
- Lombok @EqualsAndHashCode + @tostring to preserve value-type semantics.

Updated callers (Examples.java, V5DeadLetterPolicyTest, V5TransactionTest,
V5ProducerBatchingTest) to use the builder.
Copy link
Copy Markdown
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one unrelated question about BackoffPolicy.

@merlimat merlimat merged commit 12d5f26 into apache:master May 3, 2026
43 checks passed
@merlimat merlimat deleted the st-v5-policy-builder branch May 3, 2026 17:24
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants