1e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera/*
2e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
3e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera *
5e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * This code is free software; you can redistribute it and/or modify it
6e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * under the terms of the GNU General Public License version 2 only, as
7e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * published by the Free Software Foundation.  Oracle designates this
8e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * particular file as subject to the "Classpath" exception as provided
9e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * by Oracle in the LICENSE file that accompanied this code.
10e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera *
11e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * This code is distributed in the hope that it will be useful, but WITHOUT
12e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * version 2 for more details (a copy is included in the LICENSE file that
15e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * accompanied this code).
16e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera *
17e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * You should have received a copy of the GNU General Public License version
18e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * 2 along with this work; if not, write to the Free Software Foundation,
19e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera *
21e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * or visit www.oracle.com if you need additional information or have any
23e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * questions.
24e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera */
25e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera
26e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmerapackage java.nio.channels;
27e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera
28e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera/**
29e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * A handler for consuming the result of an asynchronous I/O operation.
30e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera *
31e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * <p> The asynchronous channels defined in this package allow a completion
32e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * handler to be specified to consume the result of an asynchronous operation.
33e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * The {@link #completed completed} method is invoked when the I/O operation
34e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * completes successfully. The {@link #failed failed} method is invoked if the
35e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * I/O operations fails. The implementations of these methods should complete
36e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * in a timely manner so as to avoid keeping the invoking thread from dispatching
37e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * to other completion handlers.
38e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera *
39e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * @param   <V>     The result type of the I/O operation
40e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * @param   <A>     The type of the object attached to the I/O operation
41e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera *
42e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera * @since 1.7
43e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera */
44e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera
45e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmerapublic interface CompletionHandler<V,A> {
46e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera
47e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera    /**
48e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     * Invoked when an operation has completed.
49e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     *
50e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     * @param   result
51e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     *          The result of the I/O operation.
52e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     * @param   attachment
53e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     *          The object attached to the I/O operation when it was initiated.
54e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     */
55e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera    void completed(V result, A attachment);
56e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera
57e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera    /**
58e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     * Invoked when an operation fails.
59e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     *
60e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     * @param   exc
61e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     *          The exception to indicate why the I/O operation failed
62e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     * @param   attachment
63e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     *          The object attached to the I/O operation when it was initiated.
64e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera     */
65e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera    void failed(Throwable exc, A attachment);
66e318a0eaa02b186f9f135016e95a6282fe9a83cbShubham Ajmera}
67