2362N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. 893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 893N/A * This code is free software; you can redistribute it and/or modify it 893N/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 893N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 893N/A * This code is distributed in the hope that it will be useful, but WITHOUT 893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 893N/A * version 2 for more details (a copy is included in the LICENSE file that 893N/A * accompanied this code). 893N/A * You should have received a copy of the GNU General Public License version 893N/A * 2 along with this work; if not, write to the Free Software Foundation, 893N/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 893N/A * AsynchronousChannelGroup implementation based on the Linux epoll facility. 893N/A // maximum number of events to poll at a time 893N/A // epoll file descriptor 893N/A // true if epoll closed 893N/A // socket pair used for wakeup 893N/A // number of wakeups pending 893N/A // address of the poll array passed to epoll_wait 893N/A // encapsulates an event for a channel 893N/A // queue of events for cases that a polling thread dequeues more than one 893N/A // create socket pair for wakeup mechanism 893N/A // register one end with epoll 893N/A // allocate the poll array 893N/A // create the queue and offer the special event to ensure that the first 893N/A * Release all resources 893N/A // write byte to socketpair to force wakeup 893N/A * If no tasks are running then just release resources; otherwise 893N/A * write to the one end of the socketpair to wakeup any polling threads. 893N/A // send interrupt to each thread 893N/A // invoke by clients to register a file descriptor 893N/A // update events (or add to epoll on first usage) 893N/A * Task to process events from epoll and dispatch to the channel's 893N/A * Events are retreived from epoll in batch and offered to a BlockingQueue 893N/A * where they are consumed by handler threads. A special "NEED_TO_POLL" 893N/A * event is used to signal one consumer to re-poll when all events have 893N/A * 'n' events have been read. Here we map them to their 893N/A * corresponding channel in batch and queue n-1 so that 893N/A * they can be handled by other handler threads. The last 893N/A * event is handled by this thread (and so is not queued). 893N/A // no more wakeups so drain pipe 893N/A // queue special event if there are more events 893N/A // n-1 events are queued; This thread handles 893N/A // the last one except for the wakeup 893N/A // to ensure that some thread will poll when all events have 893N/A // no events and this thread has been "selected" to 893N/A // handle wakeup to execute task or shutdown 893N/A // last handler to exit when shutdown releases resources 893N/A // -- Native methods --