You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2012/12/22 04:06:33 UTC

[3/3] git commit: api: Use Identity interface instead of java reflect to getId

api: Use Identity interface instead of java reflect to getId

- Add new interface method to getId
- Fix method definition in AsyncJob
- Get rid of mechanism to getId using reflect, use Identity interface

Signed-off-by: Rohit Yadav <bh...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/024f0d95
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/024f0d95
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/024f0d95

Branch: refs/heads/api_refactoring
Commit: 024f0d95dd4526f210d0dfff64f789107cdb4c49
Parents: 3209a3a
Author: Rohit Yadav <bh...@apache.org>
Authored: Fri Dec 21 19:03:49 2012 -0800
Committer: Rohit Yadav <bh...@apache.org>
Committed: Fri Dec 21 19:05:45 2012 -0800

----------------------------------------------------------------------
 api/src/com/cloud/async/AsyncJob.java           |    2 +-
 api/src/org/apache/cloudstack/api/Identity.java |    1 +
 core/src/com/cloud/async/AsyncJobVO.java        |    2 +-
 server/src/com/cloud/api/ApiDispatcher.java     |   16 ++--------------
 4 files changed, 5 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/024f0d95/api/src/com/cloud/async/AsyncJob.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/async/AsyncJob.java b/api/src/com/cloud/async/AsyncJob.java
index 50ca906..bea3e13 100644
--- a/api/src/com/cloud/async/AsyncJob.java
+++ b/api/src/com/cloud/async/AsyncJob.java
@@ -50,7 +50,7 @@ public interface AsyncJob extends Identity {
         AutoScaleVmGroup
     }
 
-    Long getId();
+    long getId();
 
     long getUserId();
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/024f0d95/api/src/org/apache/cloudstack/api/Identity.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/Identity.java b/api/src/org/apache/cloudstack/api/Identity.java
index 22d23b7..3136729 100644
--- a/api/src/org/apache/cloudstack/api/Identity.java
+++ b/api/src/org/apache/cloudstack/api/Identity.java
@@ -18,4 +18,5 @@ package org.apache.cloudstack.api;
 
 public interface Identity {
     String getUuid();
+    long getId();
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/024f0d95/core/src/com/cloud/async/AsyncJobVO.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/async/AsyncJobVO.java b/core/src/com/cloud/async/AsyncJobVO.java
index 7426313..769d9a9 100644
--- a/core/src/com/cloud/async/AsyncJobVO.java
+++ b/core/src/com/cloud/async/AsyncJobVO.java
@@ -145,7 +145,7 @@ public class AsyncJobVO implements AsyncJob {
 
 
     @Override
-    public Long getId() {
+    public long getId() {
 		return id;
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/024f0d95/server/src/com/cloud/api/ApiDispatcher.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java
index 839073e..54a498b 100755
--- a/server/src/com/cloud/api/ApiDispatcher.java
+++ b/server/src/com/cloud/api/ApiDispatcher.java
@@ -17,8 +17,6 @@
 package com.cloud.api;
 
 import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -48,7 +46,6 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.PermissionDeniedException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.server.ManagementServer;
 import com.cloud.storage.dao.VMTemplateDao;
@@ -635,21 +632,12 @@ public class ApiDispatcher {
                     if (objVO == null) {
                         continue;
                     }
-                    Method method = null;
-                    try {
-                        method = objVO.getClass().getMethod("getId", null);
-                    } catch (NoSuchMethodException e) {
-                        continue;
-                    } catch (SecurityException e) {
-                        continue;
-                    }
                     // Invoke the getId method, get the internal long ID
                     // If that fails hide exceptions as the uuid may not exist
                     try {
-                        id = (Long) method.invoke(objVO);
-                    } catch (InvocationTargetException e) {
+                        id = (Long) ((Identity)objVO).getId();
                     } catch (IllegalArgumentException e) {
-                    } catch (IllegalAccessException e) {
+                    } catch (NullPointerException e) {
                     }
                     // Return on first non-null Id for the uuid entity
                     if (id != null)