Bug 542765 - private close variable not exposed to check if AsyncFile is already closed
Summary: private close variable not exposed to check if AsyncFile is already closed
Status: NEW
Alias: None
Product: Vertx
Classification: RT
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal
Target Milestone: Unknown   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-13 09:28 EST by Salathiel Bogle CLA
Modified: 2018-12-13 09:28 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Salathiel Bogle CLA 2018-12-13 09:28:13 EST
There is no way to check if an Async file handle has already been closed prior to calling close() because there is no readonly method to determine this value safely. Upon executing multiple calls to close an expected exception is thrown. 

Use case:
 multiple threads/consumers performing work from data read from AsyncFile file, and fatal error in file records for processing exists and is reported at point t(n) by thread or consumer. File processing is required to be terminated where hundreds of thousands of lines are left to be processed. There is no way to check if file is already closed and gracefully terminate without exception below if file is already partially completed. 

Current work around is using AtomicBoolean variable to determine if file is closed before calling close or end in both endHandler and while terminating regular execution within file processing handlers.

Possible solution, expose close state as threadsafe and readonly to avoid clumsy or expensive exception handling in multiple file termination paths with different handler events

    private void checkClosed() {
        if (this.closed) {
            throw new IllegalStateException("File handle is closed");
        }
    }