changeset 75:9a36714478e0

8067807: Instead of UnsupportedOperationException, DeviceNotFoundException is thrown when registering PWMChannel. Summary: Added check for platfrom ability to make registration Reviewed-by: snazarki Contributed-by: alexey.mironov@oracle.com
author snazarki
date Fri, 19 Dec 2014 14:38:32 +0400
parents 591e95d602be
children 0d0d2c265612
files src/se/classes/com/oracle/dio/registry/RegistryImpl.java src/share/classes/com/oracle/dio/registry/Registry.java src/share/classes/jdk/dio/DeviceManager.java
diffstat 3 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/se/classes/com/oracle/dio/registry/RegistryImpl.java	Fri Dec 19 14:30:00 2014 +0400
+++ b/src/se/classes/com/oracle/dio/registry/RegistryImpl.java	Fri Dec 19 14:38:32 2014 +0400
@@ -50,6 +50,8 @@
     private static final String REGISTRY_FILE_PATH = "jdk.dio.registry";
     private static final String PREDEFINED = "predefined";
 
+    protected static final boolean canRegister = true;
+
     private WeakReference<Properties> registryCache;
     private WeakReference<RegistryContent> contentCache;
 
--- a/src/share/classes/com/oracle/dio/registry/Registry.java	Fri Dec 19 14:30:00 2014 +0400
+++ b/src/share/classes/com/oracle/dio/registry/Registry.java	Fri Dec 19 14:38:32 2014 +0400
@@ -50,6 +50,13 @@
     }
 
     /**
+     * Indicates if registration of a new device is possible.
+     *         false  if "register" operation is not supported by platform (i.e. closed topology)
+     *         true   otherwise
+     */
+    public static final boolean canRegister = RegistryImpl.canRegister;
+
+    /**
      *
      * @return DeviceConfig instance
      *
@@ -79,7 +86,7 @@
      *
      * @return new Periprheal ID
      * @throw  UnsupportedOperationException if operation is not
-     *         supported by platfrom
+     *         supported by platform
      * @see jdk.dio.DeviceManager#register(int,
      *      Class, DeviceConfig, String, String...)
      */
@@ -90,13 +97,14 @@
     throws UnsupportedOperationException, IOException;
 
     /**
-    * @see
-    *      jdk.dio.DeviceManager#unregister(int)
-    *
-    * To avoid double heavy calls for storage getters we can pass
-    * preUnregister method to invoke security checks right
-    * after DeviceDecriptor getting but before deleting.
-    * @see UnregisterProcessor */
+     * @see
+     *      jdk.dio.DeviceManager#unregister(int)
+     *
+     * To avoid double heavy calls for storage getters we can pass
+     * preUnregister method to invoke security checks right
+     * after DeviceDecriptor getting but before deleting.
+     * @see UnregisterProcessor
+     */
     public abstract DeviceDescriptor unregister(int id, UnregisterProcessor p);
 
     /**
--- a/src/share/classes/jdk/dio/DeviceManager.java	Fri Dec 19 14:30:00 2014 +0400
+++ b/src/share/classes/jdk/dio/DeviceManager.java	Fri Dec 19 14:38:32 2014 +0400
@@ -890,13 +890,17 @@
                                                                       final String name, final String... properties)
     throws IOException, UnsupportedDeviceTypeException, InvalidDeviceConfigException, DeviceNotFoundException, DeviceAlreadyExistsException {
 
-         int new_id = PrivilegeController.doPrivileged(new PrivilegedAction<Integer>() {
+        if (!Registry.canRegister) {
+            throw new UnsupportedOperationException();
+        }
+
+        int new_id = PrivilegeController.doPrivileged(new PrivilegedAction<Integer>() {
                 public Integer run() throws IOException {
                     Random rnd = new Random();
                     int new_id = id;
 
                     do {
-                        if (id == -1) {
+                        if (id == UNSPECIFIED_ID) {
                             //  verify generated ID
                             new_id = rnd.nextInt();
                             if (new_id < 1) {