CompletionHandler
Stay organized with collections
Save and categorize content based on your preferences.
A handler for consuming the result of an asynchronous I/O operation.
The asynchronous channels defined in this package allow a completion
handler to be specified to consume the result of an asynchronous operation.
The completed
method is invoked when the I/O operation
completes successfully. The failed
method is invoked if the
I/O operations fails. The implementations of these methods should complete
in a timely manner so as to avoid keeping the invoking thread from dispatching
to other completion handlers.
Public Method Summary
abstract
void
|
completed(V result, A attachment)
Invoked when an operation has completed.
|
abstract
void
|
|
Public Methods
public
abstract
void
completed
(V result, A attachment)
Invoked when an operation has completed.
Parameters
result |
The result of the I/O operation. |
attachment |
The object attached to the I/O operation when it was initiated.
|
public
abstract
void
failed
(Throwable exc, A attachment)
Invoked when an operation fails.
Parameters
exc |
The exception to indicate why the I/O operation failed |
attachment |
The object attached to the I/O operation when it was initiated.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eCompletionHandler\u003c/code\u003e is an interface used for handling the results of asynchronous I/O operations in Java NIO.\u003c/p\u003e\n"],["\u003cp\u003eIt provides two methods: \u003ccode\u003ecompleted\u003c/code\u003e, invoked upon successful operation completion, and \u003ccode\u003efailed\u003c/code\u003e, invoked when an operation fails.\u003c/p\u003e\n"],["\u003cp\u003eImplementations of these methods should be designed for quick execution to avoid blocking the invoking thread.\u003c/p\u003e\n"],["\u003cp\u003eBoth methods receive an attachment object that was associated with the I/O operation when it was initiated.\u003c/p\u003e\n"]]],[],null,["public interface **CompletionHandler** \nA handler for consuming the result of an asynchronous I/O operation.\n\nThe asynchronous channels defined in this package allow a completion\nhandler to be specified to consume the result of an asynchronous operation.\nThe [completed](../../../../reference/java/nio/channels/CompletionHandler.html#completed(V,%20A)) method is invoked when the I/O operation\ncompletes successfully. The [failed](../../../../reference/java/nio/channels/CompletionHandler.html#failed(java.lang.Throwable,%20A)) method is invoked if the\nI/O operations fails. The implementations of these methods should complete\nin a timely manner so as to avoid keeping the invoking thread from dispatching\nto other completion handlers. \n\nPublic Method Summary\n\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [completed](../../../../reference/java/nio/channels/CompletionHandler.html#completed(V,%20A))(V result, A attachment) Invoked when an operation has completed. |\n| abstract void | [failed](../../../../reference/java/nio/channels/CompletionHandler.html#failed(java.lang.Throwable,%20A))([Throwable](../../../../reference/java/lang/Throwable.html) exc, A attachment) Invoked when an operation fails. |\n\nPublic Methods \n\npublic abstract void\n**completed**\n(V result, A attachment) \nInvoked when an operation has completed. \n\nParameters\n\n| result | The result of the I/O operation. |\n| attachment | The object attached to the I/O operation when it was initiated. |\n|------------|-----------------------------------------------------------------|\n\npublic abstract void\n**failed**\n([Throwable](../../../../reference/java/lang/Throwable.html) exc, A attachment) \nInvoked when an operation fails. \n\nParameters\n\n| exc | The exception to indicate why the I/O operation failed |\n| attachment | The object attached to the I/O operation when it was initiated. |\n|------------|-----------------------------------------------------------------|"]]