Path: blob/master/src/java.base/share/classes/java/nio/channels/CompletionHandler.java
41159 views
/*1* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.nio.channels;2627/**28* A handler for consuming the result of an asynchronous I/O operation.29*30* <p> The asynchronous channels defined in this package allow a completion31* handler to be specified to consume the result of an asynchronous operation.32* The {@link #completed completed} method is invoked when the I/O operation33* completes successfully. The {@link #failed failed} method is invoked if the34* I/O operations fails. The implementations of these methods should complete35* in a timely manner so as to avoid keeping the invoking thread from dispatching36* to other completion handlers.37*38* @param <V> The result type of the I/O operation39* @param <A> The type of the object attached to the I/O operation40*41* @since 1.742*/4344public interface CompletionHandler<V,A> {4546/**47* Invoked when an operation has completed.48*49* @param result50* The result of the I/O operation.51* @param attachment52* The object attached to the I/O operation when it was initiated.53*/54void completed(V result, A attachment);5556/**57* Invoked when an operation fails.58*59* @param exc60* The exception to indicate why the I/O operation failed61* @param attachment62* The object attached to the I/O operation when it was initiated.63*/64void failed(Throwable exc, A attachment);65}666768