< prev index next >

src/jdk.net/linux/classes/jdk/internal/net/rdma/RdmaSocketImpl.java

Print this page

        

@@ -45,11 +45,11 @@
 import java.security.PrivilegedAction;
 import java.util.Set;
 import sun.net.ConnectionResetException;
 import sun.net.ext.RdmaSocketOptions;
 
-public class RdmaSocketImpl extends SocketImpl
+public abstract class RdmaSocketImpl extends SocketImpl
 {
     Socket socket = null;
     ServerSocket serverSocket = null;
 
     int timeout;   // timeout in millisec

@@ -86,10 +86,25 @@
 
     boolean isRdmaAvailable() {
         return platformRdmaSocketImpl.isRdmaAvailable();
     }
 
+    private static final Void checkSupported() {
+        if (PlatformRdmaSocketImpl.unsupported != null) {
+            Exception e = PlatformRdmaSocketImpl.unsupported;
+            throw new UnsupportedOperationException(e.getMessage(), e);
+        } else {
+            return null;
+        }
+    }
+
+    public RdmaSocketImpl() {
+        this(checkSupported());
+    }
+
+    private RdmaSocketImpl(Void unused) { }
+
     void setSocket(Socket soc) {
         this.socket = soc;
     }
 
     Socket getSocket() {

@@ -103,11 +118,11 @@
     ServerSocket getServerSocket() {
         return serverSocket;
     }
 
     @Override
-    protected Set<SocketOption<?>> supportedOptions() { return null; }
+    protected abstract Set<SocketOption<?>> supportedOptions();
 
     protected synchronized void create(boolean stream) throws IOException {
         fd = new FileDescriptor();
         platformRdmaSocketImpl.rdmaSocketCreate(this);
     }

@@ -177,17 +192,17 @@
             doConnect(address, port, timeout);
         }
     }
 
     @Override
-    protected <T> void setOption(SocketOption<T> name, T value)
-        throws IOException {}
+    protected abstract <T> void setOption(SocketOption<T> name, T value)
+        throws IOException;
 
     @SuppressWarnings("unchecked")
     @Override
-    protected <T> T getOption(SocketOption<T> name)
-        throws IOException { return null; }
+    protected abstract <T> T getOption(SocketOption<T> name)
+        throws IOException;
 
     public void setOption(int opt, Object val) throws SocketException {
         if (isClosedOrPending()) {
             throw new SocketException("Socket Closed");
         }

@@ -534,18 +549,21 @@
 
     public static final int SHUT_RD = 0;
     public static final int SHUT_WR = 1;
 
     static class PlatformRdmaSocketImpl {
+        private static UnsupportedOperationException unsupported;
 
         @SuppressWarnings("unchecked")
         private static PlatformRdmaSocketImpl newInstance(String cn) {
             Class<PlatformRdmaSocketImpl> c;
             try {
                 c = (Class<PlatformRdmaSocketImpl>)Class.forName(cn);
                 return c.getConstructor(new Class<?>[] {}).newInstance();
             } catch (ReflectiveOperationException x) {
+                if (x.getCause() instanceof UnsupportedOperationException)
+                    throw (UnsupportedOperationException)x.getCause();
                 throw new AssertionError(x);
             }
         }
 
         private static PlatformRdmaSocketImpl create() {

@@ -553,13 +571,24 @@
                     new PrivilegedAction<String>() {
                         public String run() {
                             return System.getProperty("os.name");
                         }
                     });
-            if ("Linux".equals(osname))
-                return newInstance("jdk.internal.net.rdma.LinuxRdmaSocketImpl");
-            return new PlatformRdmaSocketImpl();
+            PlatformRdmaSocketImpl impl;
+            UnsupportedOperationException uoe = null;
+            if ("Linux".equals(osname)) {
+                try {
+                    impl = newInstance("jdk.internal.net.rdma.LinuxRdmaSocketImpl");
+                } catch (UnsupportedOperationException e) {
+                    uoe = e;
+                    impl = new PlatformRdmaSocketImpl();
+                }
+            } else {
+                impl = new PlatformRdmaSocketImpl();
+            }
+            unsupported = uoe;
+            return impl;
         }
 
         private static final PlatformRdmaSocketImpl instance = create();
 
         static PlatformRdmaSocketImpl get() {
< prev index next >