jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

Make LifeCycle implement AutoCloseable

Open sbordet opened this issue 6 years ago • 6 comments

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?

sbordet avatar Dec 04 '18 11:12 sbordet

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

gregw avatar Dec 04 '18 11:12 gregw

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[bot] avatar Dec 04 '19 11:12 stale[bot]

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[bot] avatar Dec 04 '20 22:12 stale[bot]

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[bot] avatar Mar 30 '22 00:03 github-actions[bot]

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[bot] avatar Apr 03 '23 00:04 github-actions[bot]

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[bot] avatar Apr 03 '24 00:04 github-actions[bot]

@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 avatar Aug 13 '24 10:08 sbordet