Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make LifeCycle implement AutoCloseable #3184

Closed
sbordet opened this issue Dec 4, 2018 · 7 comments · Fixed by #12161
Closed

Make LifeCycle implement AutoCloseable #3184

sbordet opened this issue Dec 4, 2018 · 7 comments · Fixed by #12161

Comments

@sbordet
Copy link
Contributor

sbordet commented Dec 4, 2018

It is so handy in tests to be able to create a LifeCycle in a test method and use it with try-with-resources.

public interface LifeCycle extends AutoCloseable
{
    ...
    @Override
    public default void close() throws Exception
    {
        stop();
    }
}

Thoughts?

@gregw
Copy link
Contributor

gregw commented Dec 4, 2018

We certainly can do:

public interface LifeCycle
{
    ...
    interface Closeable extends LifeCycle, AutoCloseable
    {
        @Override
        default void close() throws Exception
        {
            stop();
        }
    }
}

Not sure about making all LifeCycles autocloseable

@stale
Copy link

stale bot commented Dec 4, 2019

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale For auto-closed stale issues and pull requests label Dec 4, 2019
@sbordet sbordet removed the Stale For auto-closed stale issues and pull requests label Dec 4, 2019
@stale
Copy link

stale bot commented Dec 4, 2020

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale For auto-closed stale issues and pull requests label Dec 4, 2020
@sbordet sbordet removed the Stale For auto-closed stale issues and pull requests label Dec 4, 2020
@github-actions
Copy link

This issue has been automatically marked as stale because it has been a
full year without activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@github-actions github-actions bot added the Stale For auto-closed stale issues and pull requests label Mar 30, 2022
@joakime joakime removed the Stale For auto-closed stale issues and pull requests label Mar 30, 2022
@github-actions
Copy link

github-actions bot commented Apr 3, 2023

This issue has been automatically marked as stale because it has been a
full year without activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@github-actions github-actions bot added the Stale For auto-closed stale issues and pull requests label Apr 3, 2023
@sbordet sbordet removed the Stale For auto-closed stale issues and pull requests label Apr 3, 2023
Copy link

github-actions bot commented Apr 3, 2024

This issue has been automatically marked as stale because it has been a
full year without activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@github-actions github-actions bot added the Stale For auto-closed stale issues and pull requests label Apr 3, 2024
@sbordet sbordet removed the Stale For auto-closed stale issues and pull requests label Apr 3, 2024
@sbordet sbordet self-assigned this Apr 3, 2024
sbordet added a commit that referenced this issue Aug 13, 2024
Rather than making LifeCycle AutoCloseable, just implement AutoCloseable in the client components.

Update tests to use try-with-resources accordingly.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@sbordet sbordet linked a pull request Aug 13, 2024 that will close this issue
@sbordet
Copy link
Contributor Author

sbordet commented Aug 13, 2024

@gregw

I agree that making all LifeCycle also AutoCloseable may be a bit too much, although all LifeCycle have already a stop() method so they kind of are already stoppable/closeable.

I think introducing LifeCycle.AutoCloseable is a bit of duplication, since components can just implement directly AutoCloseable directly and just implement close() as a one-liner calling stop().

@sbordet sbordet moved this to 🏗 In progress in Jetty 12.0.13 - FROZEN Aug 13, 2024
sbordet added a commit that referenced this issue Aug 14, 2024
Rather than making LifeCycle AutoCloseable, just implement AutoCloseable in the client components.

Update tests to use try-with-resources accordingly.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Jetty 12.0.13 - FROZEN Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants