Skip to content

AblyRealtime should implement Autocloseable #514

@amihaiemil

Description

@amihaiemil

I noticed all or most of our tests for AblyRealtime have the try-catch-finally pattern, becuase the instantiated AblyRealtime objects need to be closed. I suspect that also in "real" usage, the object has to be closed when its no longer needed.

In order to simplify things, this class should implement Autocloseable and be used in try-with-resources, which was introduced in Java 7. Then, the code can be simplified a lot for our clients and also in our tests. Instead of this:

try {
    AblyRealtime ably = ...
} catch (AblyException ex) {
    fail(...);
} finally {
    ably.close();
}

we will have this:

try (AblyRealtime ably = ...) {
    ...
} // we don't care about the exception anymore
//since the test will fail automatically and log
//the exception anyway, if it is thrown.

Note that this change will not affect backwards compatibility!

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