/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Provides an AsynchronousChannelGroup implementation based on the Solaris 10
* event port framework and also provides direct access to that framework.
*/
class SolarisEventPort
extends Port
{
}
/*
* typedef struct port_event {
* int portev_events;
* ushort_t portev_source;
* ushort_t portev_pad;
* uintptr_t portev_object;
* void *portev_user;
* } port_event_t;
*/
// port sources
// file descriptor to event port.
private final int port;
// true when port is closed
private boolean closed;
throws IOException
{
// create event port
this.port = port_create();
}
startThreads(new EventHandlerTask());
return this;
}
// releass resources
private void implClose() {
synchronized (this) {
if (closed)
return;
closed = true;
}
}
private void wakeup() {
try {
} catch (IOException x) {
throw new AssertionError(x);
}
}
synchronized (this) {
if (closed)
throw new RejectedExecutionException();
wakeup();
}
}
void shutdownHandlerTasks() {
/*
* If no tasks are running then just release resources; otherwise
* write to the one end of the socketpair to wakeup any polling threads..
*/
int nThreads = threadCount();
if (nThreads == 0) {
implClose();
} else {
// send user event to wakeup each thread
while (nThreads-- > 0) {
try {
} catch (IOException x) {
throw new AssertionError(x);
}
}
}
}
// (re-)associate file descriptor
// no need to translate events
try {
} catch (IOException x) {
throw new AssertionError(); // should not happen
}
}
/*
* Task to read a single event from the port and dispatch it to the
* channel's onEvent handler.
*/
public void run() {
boolean replaceMe = false;
try {
for (;;) {
// reset invoke count
if (isPooledThread)
// wait for I/O completion event
// A error here is fatal (thread will not be replaced)
replaceMe = false;
try {
} catch (IOException x) {
x.printStackTrace();
return;
}
// event source
if (source != PORT_SOURCE_FD) {
// user event is trigger to invoke task or shutdown
if (source == PORT_SOURCE_USER) {
// shutdown request
return;
}
replaceMe = true;
}
// ignore
continue;
}
// pe->portev_object is file descriptor
// pe->portev_events
// lookup channel
try {
} finally {
}
// notify channel
replaceMe = true;
// no need to translate events
}
}
} finally {
// free per-thread resources
// last task to exit when shutdown release resources
implClose();
}
}
}
/**
* Creates an event port
*/
/**
* Associates specific events of a given object with a port
*/
throws IOException;
/**
* Removes the association of an object with a port.
*/
throws IOException;
/**
* Retrieves a single event from a port
*/
/**
* Retrieves at most {@code max} events from a port.
*/
throws IOException;
/**
* Sends a user-defined eventto a specified port.
*/
/**
* Closes a port.
*/
static {
}
}