Skip to content

Expose batch-module as a supported standalone Jakarta Mail orchestration API #698

Closed

Description

@bbottema

Context

org.simplejavamail:batch-module is a separately published artifact and depends only on core-module and smtp-connection-pool, but it currently has no supported standalone API.

Its usable types are under org.simplejavamail.internal... or org.simplejavamail.api.internal..., registerToCluster(...) requires the Mailer-wide OperationalConfig, and the module Javadoc explicitly says that it has no public API by itself.

This leaves a useful middle path between:

  1. direct low-level use of smtp-connection-pool, where callers manually claim, release, invalidate, and shut down resources;
  2. full Simple Java Mail EmailBuilder / Mailer usage; and
  3. the standard Jakarta Mail smtppool provider proposed in smtp-connection-pool #10.

Goal

Expose a supported API for applications that create their own Jakarta Mail Session and MimeMessage objects but want batch-module's asynchronous execution, clustered connection pooling, safe transport lifecycle, and deterministic shutdown. This additive API targets Simple Java Mail 9.3.0, not 10.0.0.

The provider and batch-module APIs are parallel choices. The batch API must not wrap or recursively select the pooled Jakarta Mail provider.

Simple Java Mail itself remains a direct smtp-connection-pool integration because it needs clustering/sticky selection, the actual Session/Transport, receipt handling, precise failure behavior, and deterministic shutdown. It should reuse the shared upstream transport-lease contract, not route its Mailer through PooledTransport.

Proposed API direction

Add a public org.simplejavamail.batch facade centered on:

  • BatchTransportExecutor<K> and its builder;
  • dedicated global and per-cluster configuration;
  • registration of Jakarta Mail Sessions under cluster keys;
  • separate cluster-selected and session-sticky operations;
  • a callback that receives the selected Session and Transport, releases automatically on success, and invalidates automatically on failure;
  • optional asynchronous submission returning CompletableFuture; and
  • explicit, deterministic lifecycle through AutoCloseable.

Keep the raw upstream lease internal to this facade so callers cannot accidentally leak it. Keep the existing internal BatchModule reflection boundary as a compatibility adapter for the full Simple Java Mail Mailer integration. Both public and internal paths should delegate to one engine.

Acceptance criteria

  • A consumer can compile and run using only org.simplejavamail:batch-module and its transitive dependencies; the main simple-java-mail artifact is not required.
  • The documented consumer example imports no org.simplejavamail.internal... or org.simplejavamail.api.internal... types.
  • Public configuration covers core size, maximum size, claim timeout, expiry, load-balancing strategy, and per-cluster overrides without requiring OperationalConfig.
  • Callers can register one or more Jakarta Mail Sessions under a cluster key.
  • Public operations support both cluster-selected and session-sticky use and expose the actual selected Session alongside its Transport.
  • The callback API releases after success and invalidates after failure without exposing or leaking a claimed lease.
  • Public failures retain useful causes without exposing credentials or OAuth2 tokens.
  • Fixed OAuth2 tokens and refresh-aware token suppliers are resolved from the actually selected registered Session at the physical connection or reconnection boundary.
  • Default executors are module-owned, supplied executors remain caller-owned, and ownership is documented and tested.
  • close()/shutdown is idempotent, closes registered pools, waits according to documented semantics, and prevents new acquisitions.
  • Existing Mailer behavior remains compatible and delegates to the shared engine.
  • The batch path never recursively selects smtppool or creates a pool over a provider-owned pool.
  • Public API compile, single-pool, multi-session cluster, sticky selection, failure invalidation, OAuth2, executor ownership, shutdown, and module-path tests are present.
  • Generated Javadocs replace the current static “no public API” page.
  • Java 8 compatibility and the org.simplejavamail.batch automatic module name are preserved.
  • Simple Java Mail release notes add a Supporting Libraries entry for the required upstream release.

Website

After the public API exists, add:

  • source: simplejavamail.org/src/pages/smtp-connection-pooling.hbs;
  • route: /smtp-connection-pooling.html, as a child of /modules.html;
  • a complete Session/MimeMessage callback example and lifecycle guidance;
  • links from the batch section in modules.hbs and the existing batch/pooling sections in configuration.hbs; and
  • a comparison matrix covering no pool, Mailer + batch-module, standalone batch-module, direct smtp-connection-pool, Jakarta/Spring smtppool, and Camel; and
  • an explicit one-pool-owner rule so batch/direct orchestration is never stacked over smtppool.

Do not publish the direct-use guide before the public API exists. Validate with npm run check, npm run verifyLinks:internal, and npm run build.

Non-goals

  • Implementing the Jakarta Mail smtppool provider itself; that belongs to smtp-connection-pool Unicode in local part of email address fails #10.
  • Replacing or weakening the full Simple Java Mail EmailBuilder and Mailer APIs.
  • Adding automatic retries, transparent failover, server quarantine, circuit breaking, or message construction.
  • Making Spring JavaMailSender depend on this facade; Spring should use the standard provider path.
  • Stacking the batch-owned pool over smtppool.

Coordination

  • Consume the compatible lease contract from smtp-connection-pool #10 through the JPMS-fixed 4.0.1 follow-up tracked in smtp-connection-pool #11.
  • Update modules/batch-module/pom.xml only after that upstream release is available.
  • Land website documentation in the separate simple-java-mail/simplejavamail.org repository, then update the website submodule revision in this repository.
  • Assign a Simple Java Mail milestone only after its concrete release target is accepted.

Activity

  1. added this to the 10.0.0 milestone on Aug 9, 2026
  2. removed this from the 10.0.0 milestone on Aug 9, 2026
  3. changed the title [-]Expose the batch module as a supported API and document the SMTP pooling paths[/-] [+]Expose batch-module as a supported standalone Jakarta Mail pooling API[/+] on Aug 9, 2026
  4. bbottema commented on Aug 10, 2026

    @bbottema
    OwnerAuthor

    The upstream module-path chain is now complete and available from Maven Central:

    Requirements for the Simple Java Mail 9.3.0 work are:

    • Simple Java Mail itself stays on the pool's direct integration path and adopts SmtpTransportLease; it does not route its rich Mailer lifecycle through the smtppool PooledTransport facade.
    • The supported standalone batch-module API keeps the raw lease internal, exposes a safe callback around the selected Jakarta Session / Transport, releases on success, and invalidates on broken or uncertain failure.
    • The facade remains transport-neutral for Support negotiated SMTP PIPELINING and CHUNKING through a pluggable transport #699: no Angus or proposed custom-transport type appears in the public API. A future Jakarta Transport implementation can be selected beneath the pool; a CustomMailer implementation instead owns a separate lifecycle and must not be nested with the batch pool.
    • The one-pooling-owner rule and deterministic graceful/forced shutdown semantics remain explicit.
    • The upstream standalone path-2 demo is deferred only until Simple Java Mail 9.3.0 publishes this facade; the canonical website guide can then link the runnable example.

    No Angus change is required for #698. The released core/provider artifacts remain Java 8 compatible; the optional Camel adapter remains isolated at Java 17 / Camel 4.21.x.

  5. added this to the 9.3.0 milestone on Aug 10, 2026
  6. changed the title [-]Expose batch-module as a supported standalone Jakarta Mail pooling API[/-] [+]Expose batch-module as a supported standalone Jakarta Mail orchestration API[/+] on Aug 11, 2026
  7. bbottema commented on Aug 11, 2026

    @bbottema
    OwnerAuthor

    Available in Simple Java Mail 9.3.0.

    Add org.simplejavamail:batch-module:9.3.0, then register a Jakarta Mail Session and run message work inside the callback:

    try (BatchTransportExecutor<String> batch =
             BatchTransportExecutor.<String>builder().build()) {
        batch.registerSession("outbound", session);
        batch.execute("outbound", (selectedSession, transport) -> {
            MimeMessage message = new MimeMessage(selectedSession);
            // populate the message
            transport.sendMessage(message, message.getAllRecipients());
            return null;
        });
    }

    The facade also supports exact-Session callbacks, CompletableFuture submission, per-cluster pool configuration, selected-Session OAuth2 resolution, injected executor ownership, and graceful or forced shutdown. It keeps SmtpTransportLease private, releases on success, invalidates on failure, and rejects recursive use over smtppool.

    See the comparison and orchestration guide and the runnable BatchModuleDemo.

    No Angus change was needed for this issue; #699 remains the separate transport initiative.

  8. bbottema commented on Sep 7, 2026

    @bbottema
    OwnerAuthor

    The waiting-claim recovery fix is now available in Simple Java Mail 9.3.4, through SMTP Connection Pool 4.0.2. Upgrade Simple Java Mail and any separately declared batch-module dependency to 9.3.4; the standalone batch API remains unchanged. Details: #724.

  9. bbottema commented on Sep 17, 2026

    @bbottema
    OwnerAuthor

    SMTP Connection Pool 4.2.0 is now available on Maven Central, using clustered-object-pool 4.1.1 and generic-object-pool 2.5.1.

    The provider/Camel path gains optional creation-age expiration, and the upstream fix keeps creation-age and last-claim policies distinct even when their thresholds match. Details: SMTP #33 and PR #34.

    Simple Java Mail and standalone batch-module still need a separate 9.x patch to expose this through their builders, properties, per-cluster settings, Spring and CLI support. They construct their own policies through the direct pool API, so a dependency update alone does not expose the new option. That follow-up will retain the direct integration and disabled-by-default behavior; it will not stack batch pooling over the Jakarta smtppool provider.

    Creation age makes available transports eligible for background retirement; it does not interrupt active leases or impose a strict maximum lifetime. The 9.x integration is the next task and is not yet released.

  10. bbottema commented on Oct 12, 2026

    @bbottema
    OwnerAuthor

    Supporting-library follow-up: SMTP Connection Pool 4.4.0 is available, using Clustered Object Pool 4.3.0 and Generic Object Pool 2.6.0. Existing acquisition APIs and provider/Camel configuration remain compatible. The new direct-pool selection and observation hooks support the ongoing coordinated failover work in #755; no email retry behavior is added by the pool itself.

  11. bbottema commented on Nov 5, 2026

    @bbottema
    OwnerAuthor

    SMTP Connection Pool 4.4.1 is available. OAuth connections keep the selected Jakarta Mail provider's username resolution, so an SMTPS Session can retain a different unused SMTP username without selecting that account. Existing fixed-token and supplier configuration stays supported. The matching dependency update for the 10.0.0 development branch is tracked in #966.

  12. bbottema commented on Nov 5, 2026

    @bbottema
    OwnerAuthor

    SMTP Connection Pool 4.5.0 adds an optional token supplier on the existing per-Session registerResourcePool API. Existing registration/property callers remain supported. The matching unreleased SJM 10.0.0 integration is tracked in #967; it keeps the standalone facade's documented credential inputs while removing the additional property copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions