This has been lying around for a long time here. It implements the basic
inheritedChannel() infrastructure. The default implementation can't do
much more than return null (which is OK, and actually what the JDK does
for me). If a VM can do something more useful here, it would have to
provide its own SelectorProvider. I didn't feel like introducing some
kind of VMXYZ method here, because we already have a fine abstraction
via the SPI.
2007-04-03 Roman Kennke <[EMAIL PROTECTED]>
* java/lang/System.java
(inheritedChannel): New method, wraps
SelectorProvider.inheritedChannel().
* java/nio/channels/spi/SelectorProvider.java
(inheritedChannel): New abstract method.
* gnu/java/nio/SelectorProviderImpl.java
(inheritedChannel): New method, return null as default.
--
http://kennke.org/blog/
Index: java/lang/System.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/System.java,v
retrieving revision 1.60
diff -u -1 -5 -r1.60 System.java
--- java/lang/System.java 23 Feb 2007 15:50:04 -0000 1.60
+++ java/lang/System.java 3 Apr 2007 21:26:17 -0000
@@ -30,32 +30,35 @@
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.lang;
import gnu.classpath.SystemProperties;
import gnu.classpath.VMStackWalker;
+import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
+import java.nio.channels.Channel;
+import java.nio.channels.spi.SelectorProvider;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Properties;
import java.util.PropertyPermission;
/**
* System represents system-wide resources; things that represent the
* general environment. As such, all methods are static.
*
@@ -660,30 +663,49 @@
VMStackWalker.getCallingClassLoader());
}
/**
* Convert a library name to its platform-specific variant.
*
* @param libname the library name, as used in <code>loadLibrary</code>
* @return the platform-specific mangling of the name
* @since 1.2
*/
public static String mapLibraryName(String libname)
{
return VMRuntime.mapLibraryName(libname);
}
+ /**
+ * Returns the inherited channel of the VM.
+ *
+ * This wraps the inheritedChannel() call of the system's default
+ * [EMAIL PROTECTED] SelectorProvider}.
+ *
+ * @return the inherited channel of the VM
+ *
+ * @throws IOException If an I/O error occurs
+ * @throws SecurityException If an installed security manager denies access
+ * to RuntimePermission("inheritedChannel")
+ *
+ * @since 1.5
+ */
+ public static Channel inheritedChannel()
+ throws IOException
+ {
+ return SelectorProvider.provider().inheritedChannel();
+ }
/**
* This is a specialised <code>Collection</code>, providing
* the necessary provisions for the collections used by the
* environment variable map. Namely, it prevents
* querying anything but <code>String</code>s.
*
* @author Andrew John Hughes ([EMAIL PROTECTED])
*/
private static class EnvironmentCollection
extends AbstractCollection<String>
{
/**
* The wrapped collection.
Index: java/nio/channels/spi/SelectorProvider.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/channels/spi/SelectorProvider.java,v
retrieving revision 1.11
diff -u -1 -5 -r1.11 SelectorProvider.java
--- java/nio/channels/spi/SelectorProvider.java 2 Jul 2005 20:32:40 -0000 1.11
+++ java/nio/channels/spi/SelectorProvider.java 3 Apr 2007 21:26:17 -0000
@@ -28,30 +28,31 @@
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.nio.channels.spi;
import gnu.java.nio.SelectorProviderImpl;
import java.io.IOException;
+import java.nio.channels.Channel;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
/**
* @author Michael Koch
* @since 1.4
*/
public abstract class SelectorProvider
{
private static SelectorProvider systemDefaultProvider;
/**
@@ -103,30 +104,43 @@
* @exception IOException if an error occurs
*/
public abstract ServerSocketChannel openServerSocketChannel()
throws IOException;
/**
* Opens a socket channel.
*
* @return a new socket channel object
*
* @exception IOException if an error occurs
*/
public abstract SocketChannel openSocketChannel() throws IOException;
/**
+ * Returns the inherited channel of the VM.
+ *
+ * @return the inherited channel of the VM
+ *
+ * @throws IOException If an I/O error occurs
+ * @throws SecurityException If an installed security manager denies access
+ * to RuntimePermission("inheritedChannel")
+ *
+ * @since 1.5
+ */
+ public abstract Channel inheritedChannel() throws IOException;
+
+ /**
* Returns the system-wide default selector provider for this invocation
* of the Java virtual machine.
*
* @return the default seletor provider
*/
public static synchronized SelectorProvider provider()
{
if (systemDefaultProvider == null)
{
String propertyValue =
System.getProperty("java.nio.channels.spi.SelectorProvider");
if (propertyValue == null || propertyValue.equals(""))
systemDefaultProvider = new SelectorProviderImpl();
else
Index: gnu/java/nio/SelectorProviderImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/nio/SelectorProviderImpl.java,v
retrieving revision 1.10
diff -u -1 -5 -r1.10 SelectorProviderImpl.java
--- gnu/java/nio/SelectorProviderImpl.java 20 Sep 2006 21:39:41 -0000 1.10
+++ gnu/java/nio/SelectorProviderImpl.java 3 Apr 2007 21:26:17 -0000
@@ -29,30 +29,31 @@
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.nio;
import gnu.classpath.SystemProperties;
import java.io.IOException;
+import java.nio.channels.Channel;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.AbstractSelector;
import java.nio.channels.spi.SelectorProvider;
public class SelectorProviderImpl extends SelectorProvider
{
private static final String SELECTOR_IMPL_KQUEUE = "kqueue";
private static final String SELECTOR_IMPL_EPOLL = "epoll";
private static final String SELECTOR_IMPL = "gnu.java.nio.selectorImpl";
private static boolean epoll_failed = false;
public SelectorProviderImpl ()
@@ -105,16 +106,25 @@
return new SelectorImpl (this);
}
public ServerSocketChannel openServerSocketChannel ()
throws IOException
{
return new ServerSocketChannelImpl (this);
}
public SocketChannel openSocketChannel ()
throws IOException
{
return new SocketChannelImpl (this);
}
+
+ public Channel inheritedChannel() throws IOException
+ {
+ // Implementation note: The default implementation can't do much more
+ // than return null. If a VM can provide something more useful it should
+ // install its own SelectorProvider (maybe a subclass of this one) to
+ // return something more useful.
+ return null;
+ }
}