Skip to content

Simple pattern for per-bundle and per-DoFn Closeable resources #17926

@damccorm

Description

@damccorm

Dealing with Closeable resources inside a processElement call is easy: simply use try-with-resources.

However, bundle- or DoFn-scoped resources, such as long-lived database connections, are less convenient to deal with: you have to open them in startBundle and conditionally close in finishBundle (likewise setup/teardown), taking special care if there's multiple resources to close all of them.

Perhaps we should provide something like Guava's Closer to DoFn's https://github.com/google/guava/wiki/ClosingResourcesExplained. Ideally, the user would need to only write a startBundle() or setup() method, but not write finishBundle() or teardown() - resources would be closed automatically.

Imported from Jira BEAM-702. Original Jira may contain additional context.
Reported by: jkff.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions