2362N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. 430N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 430N/A * This code is free software; you can redistribute it and/or modify it 430N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 430N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 430N/A * This code is distributed in the hope that it will be useful, but WITHOUT 430N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 430N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 430N/A * version 2 for more details (a copy is included in the LICENSE file that 430N/A * accompanied this code). 430N/A * You should have received a copy of the GNU General Public License version 430N/A * 2 along with this work; if not, write to the Free Software Foundation, 430N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 430N/A * Windows implementation of AsynchronousChannelGroup encapsulating an I/O 430N/A // maps completion key to channel 430N/A // handle to completion port 430N/A // true if port has been closed 430N/A // the set of "stale" OVERLAPPED structures. These OVERLAPPED structures 430N/A // relate to I/O operations where the completion notification was not 430N/A // received in a timely manner after the channel is closed. 430N/A * Channels implements this interface support overlapped I/O and can be 430N/A * associated with a completion port. 430N/A * Returns a reference to the pending I/O result. 430N/A * Indicates if this operating system supports thread agnostic I/O. 430N/A // release all resources * On Windows the close operation will close the socket/file handle * and then wait until all outstanding I/O operations have aborted. * This is necessary as each channel's cache of OVERLAPPED structures * can only be freed once all I/O operations have completed. As I/O * completion requires a lookup of the keyToChannel then we must close * the channels when not holding the write lock. // grab a batch of up to 32 channels for (
int i=
0; i<
count; i++) {
// shutdown all handler threads * Associate the given handle with this group // generate a completion key (if not shutdown) // associate with I/O completion port * Disassociate channel from the group. // last key to be removed so check if group is shutdown * Invoked when a channel associated with this port is closed before * notifications for all outstanding I/O operations have been received. * Checks if the given OVERLAPPED is stale and if so, releases it. * The handler for consuming the result of an asynchronous I/O operation. * Invoked if the I/O operation completes successfully. * Invoked if the I/O operation fails. // Creates IOException for the given I/O error. * Long-running task servicing system-wide or per-file completion port // wait for I/O completion event // A error here is fatal (thread will not be replaced) // handle wakeup to execute task or shutdown // we get here if the OVERLAPPED structure is associated // with an I/O operation on a channel that was closed // but the I/O operation event wasn't read in a timely // manner. Alternatively, it may be related to a // tryLock operation as the OVERLAPPED structures for // these operations are not in the I/O cache. // synchronize on result in case I/O completed immediately // and was handled by initiator // not handled by initiator // invoke I/O result handler // last thread to exit when shutdown releases resources * Container for data returned by GetQueuedCompletionStatus private static native void initIDs();
// thread agnostic I/O on Vista/2008 or newer