Updated Branches:
  refs/heads/javelin 01701b1d9 -> 107fccdf6

Add AsyncCallFuture


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

Branch: refs/heads/javelin
Commit: 107fccdf69076388d7d8aae29d09eb818f65dba3
Parents: 01701b1
Author: Kelven Yang <[email protected]>
Authored: Thu Jan 3 17:24:26 2013 -0800
Committer: Kelven Yang <[email protected]>
Committed: Thu Jan 3 17:24:26 2013 -0800

----------------------------------------------------------------------
 client/pom.xml                                     |    2 +-
 client/tomcatconf/applicationContext.xml.in        |    3 -
 .../engine/datacenter/entity/api/db/HostVO.java    |    4 +-
 .../entity/api/db/dao/ClusterDaoImpl.java          |    5 +-
 .../entity/api/db/dao/DataCenterDaoImpl.java       |    5 +-
 .../entity/api/db/dao/DcDetailsDaoImpl.java        |    2 +
 .../datacenter/entity/api/db/dao/HostDaoImpl.java  |    9 +-
 .../entity/api/db/dao/HostDetailsDaoImpl.java      |    2 +-
 .../entity/api/db/dao/HostPodDaoImpl.java          |    4 +-
 .../entity/api/db/dao/HostTagsDaoImpl.java         |    2 +-
 .../framework/async/AsyncCallFuture.java           |   97 +++++++++++++++
 .../framework/codestyle/AsyncSampleCallee.java     |   14 +-
 12 files changed, 128 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index e62c6a9..e4707c0 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -199,7 +199,7 @@
               <maxIdleTime>60000</maxIdleTime>
             </connector>
           </connectors>
-          <jvmArgs>-XX:MaxPermSize=256m -Xmx2g</jvmArgs>
+          <jvmArgs>-XX:MaxPermSize=512m -Xmx2g</jvmArgs>
           <contextPath>/client</contextPath>
           
<webXml>${basedir}/target/${project.artifactId}-${project.version}/WEB-INF/web.xml</webXml>
           
<webAppSourceDirectory>${basedir}/target/${project.artifactId}-${project.version}</webAppSourceDirectory>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/client/tomcatconf/applicationContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/applicationContext.xml.in 
b/client/tomcatconf/applicationContext.xml.in
index 60e68e0..34bb853 100644
--- a/client/tomcatconf/applicationContext.xml.in
+++ b/client/tomcatconf/applicationContext.xml.in
@@ -19,8 +19,6 @@
   <!--
     @DB support
   -->
-  
-<!--  
   <aop:config proxy-target-class="true">
     <aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
     <aop:pointcut id="captureAnyMethod"
@@ -28,7 +26,6 @@
       <aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod"/> 
     </aop:aspect>
   </aop:config>
--->
 
   <bean id="transactionContextBuilder" 
class="com.cloud.utils.db.TransactionContextBuilder" />
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/HostVO.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/HostVO.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/HostVO.java
index 210ed15..964d7b3 100644
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/HostVO.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/HostVO.java
@@ -720,7 +720,9 @@ public class HostVO implements Host, Identity {
     }
 
        @Override
-       @Transient
+       
+       // TODO, I tempoerary disable it as it breaks GenericSearchBuild when 
@Transient is applied
+       // @Transient
        public Status getState() {
                return status;
        }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
index ff2e911..bd4a5ae 100644
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Map;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 
 import 
org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
 import 
org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
@@ -29,6 +30,7 @@ import 
org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEnti
 import org.apache.cloudstack.engine.datacenter.entity.api.db.ClusterVO;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO;
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -45,6 +47,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 
+@Component(value="EngineClusterDao")
 @Local(value=ClusterDao.class)
 public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements 
ClusterDao {
        private static final Logger s_logger = 
Logger.getLogger(ClusterDaoImpl.class);
@@ -60,7 +63,7 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, 
Long> implements C
     private static final String GET_POD_CLUSTER_MAP_PREFIX = "SELECT pod_id, 
id FROM cloud.cluster WHERE cluster.id IN( ";
     private static final String GET_POD_CLUSTER_MAP_SUFFIX = " )";
     
-    protected final HostPodDaoImpl _hostPodDao = 
ComponentLocator.inject(HostPodDaoImpl.class);
+    @Inject protected HostPodDao _hostPodDao;
     
     protected ClusterDaoImpl() {
         super();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java
index a25b375..61a4bb3 100644
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java
@@ -18,6 +18,7 @@ import java.util.Map;
 import java.util.Random;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 import javax.persistence.TableGenerator;
 
@@ -27,6 +28,7 @@ import 
org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEnti
 import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.org.Grouping;
 import com.cloud.utils.NumbersUtil;
@@ -48,6 +50,7 @@ import com.cloud.utils.net.NetUtils;
  *    || mac.address.prefix | prefix to attach to all public and private mac 
addresses | number | 06 ||
  *  }
  **/
+@Component(value="EngineDataCenterDao")
 @Local(value={DataCenterDao.class})
 public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> 
implements DataCenterDao {
     private static final Logger s_logger = 
Logger.getLogger(DataCenterDaoImpl.class);
@@ -65,7 +68,7 @@ public class DataCenterDaoImpl extends 
GenericDaoBase<DataCenterVO, Long> implem
     protected Random _rand = new Random(System.currentTimeMillis());
     protected TableGenerator _tgMacAddress;
     
-    protected final DcDetailsDaoImpl _detailsDao = 
ComponentLocator.inject(DcDetailsDaoImpl.class);
+    @Inject protected DcDetailsDao _detailsDao;
 
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DcDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DcDetailsDaoImpl.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DcDetailsDaoImpl.java
index 4092786..60eec4c 100644
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DcDetailsDaoImpl.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DcDetailsDaoImpl.java
@@ -19,6 +19,7 @@ import java.util.Map;
 import javax.ejb.Local;
 
 import org.apache.cloudstack.engine.datacenter.entity.api.db.DcDetailVO;
+import org.springframework.stereotype.Component;
 
 
 import com.cloud.utils.db.GenericDaoBase;
@@ -26,6 +27,7 @@ import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
 
+@Component(value="EngineDcDetailsDao")
 @Local(value=DcDetailsDao.class)
 public class DcDetailsDaoImpl extends GenericDaoBase<DcDetailVO, Long> 
implements DcDetailsDao {
     protected final SearchBuilder<DcDetailVO> DcSearch;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java
index ede5d8c..41e6785 100644
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.TimeZone;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.persistence.TableGenerator;
 
 import 
org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
@@ -62,7 +63,7 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.db.UpdateBuilder;
 import com.cloud.utils.exception.CloudRuntimeException;
 
-
+@Component(value="EngineHostDao")
 @Local(value = { HostDao.class })
 @DB(txn = false)
 @TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", 
valueColumnName = "sequence", allocationSize = 1)
@@ -115,9 +116,9 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, 
Long> implements HostDao
     protected final Attribute _msIdAttr;
     protected final Attribute _pingTimeAttr;
 
-    protected final HostDetailsDaoImpl _detailsDao = 
ComponentLocator.inject(HostDetailsDaoImpl.class);
-    protected final HostTagsDaoImpl _hostTagsDao = 
ComponentLocator.inject(HostTagsDaoImpl.class);
-    protected final ClusterDaoImpl _clusterDao = 
ComponentLocator.inject(ClusterDaoImpl.class);
+    @Inject protected HostDetailsDao _detailsDao;
+    @Inject protected HostTagsDao _hostTagsDao;
+    @Inject protected ClusterDao _clusterDao;
     
 
     public HostDaoImpl() {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java
index 93e728d..87d516b 100644
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java
@@ -31,7 +31,7 @@ import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
 
-@Component
+//@Component(value="EngineHostDetailsDao")
 @Local(value=HostDetailsDao.class)
 public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> 
implements HostDetailsDao {
     protected final SearchBuilder<DetailVO> HostSearch;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
index df52ed6..b39fdc3 100644
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
@@ -27,6 +27,7 @@ import 
org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEnti
 import 
org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO;
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 
 import com.cloud.org.Grouping;
@@ -37,7 +38,8 @@ import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.UpdateBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.Transaction;
-
+
+@Component(value="EngineHostPodDao")
 @Local(value={HostPodDao.class})
 public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements 
HostPodDao {
     private static final Logger s_logger = 
Logger.getLogger(HostPodDaoImpl.class);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java
index 2ad3631..a70b7d1 100644
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java
@@ -29,7 +29,7 @@ import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
 
-@Component
+@Component(value="EngineHostTagsDao")
 @Local(value=HostTagsDao.class)
 public class HostTagsDaoImpl extends GenericDaoBase<HostTagVO, Long> 
implements HostTagsDao {
     protected final SearchBuilder<HostTagVO> HostSearch;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/framework/ipc/src/org/apache/cloudstack/framework/async/AsyncCallFuture.java
----------------------------------------------------------------------
diff --git 
a/framework/ipc/src/org/apache/cloudstack/framework/async/AsyncCallFuture.java 
b/framework/ipc/src/org/apache/cloudstack/framework/async/AsyncCallFuture.java
new file mode 100644
index 0000000..e9635de
--- /dev/null
+++ 
b/framework/ipc/src/org/apache/cloudstack/framework/async/AsyncCallFuture.java
@@ -0,0 +1,97 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.framework.async;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+public class AsyncCallFuture<T> implements Future<T>, 
AsyncCompletionCallback<T> {
+
+       AsyncCompletionCallback <T> _callback;
+
+       Object _completed = new Object();
+       boolean _done = false;
+       T _resultObject;                // we will store a copy of the result 
object
+       
+       public AsyncCallFuture(AsyncCompletionCallback <T> callback) {
+               _callback = callback;
+       }
+       
+       @Override
+       public boolean cancel(boolean mayInterruptIfRunning) {
+               // TODO we don't support cancel yet
+               return false;
+       }
+
+       @Override
+       public T get() throws InterruptedException, ExecutionException {
+               synchronized(_completed) {
+                       if(!_done)
+                               _completed.wait();
+               }
+               
+               return _resultObject;
+       }
+
+       @Override
+       public T get(long timeout, TimeUnit timeUnit) throws 
InterruptedException,
+                       ExecutionException, TimeoutException {
+
+               TimeUnit milliSecondsUnit = TimeUnit.MILLISECONDS;
+               
+               synchronized(_completed) {
+                       if(!_done)
+                               
_completed.wait(milliSecondsUnit.convert(timeout, timeUnit));
+               }
+               
+               return _resultObject;
+       }
+
+       @Override
+       public boolean isCancelled() {
+               // TODO we don't support cancel yet
+               return false;
+       }
+
+       @Override
+       public boolean isDone() {
+               return _done;
+       }
+
+       @Override
+       public void complete(T resultObject) {
+               _resultObject = resultObject;
+               synchronized(_completed) {
+                       _done = true;
+                       _completed.notifyAll();
+               }
+               
+               _callback.complete(resultObject);
+       }
+       
+       public void inplaceComplete(T resultObject) {
+               _resultObject = resultObject;
+               synchronized(_completed) {
+                       _done = true;
+                       _completed.notifyAll();
+               }
+       }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/107fccdf/framework/ipc/test/org/apache/cloudstack/framework/codestyle/AsyncSampleCallee.java
----------------------------------------------------------------------
diff --git 
a/framework/ipc/test/org/apache/cloudstack/framework/codestyle/AsyncSampleCallee.java
 
b/framework/ipc/test/org/apache/cloudstack/framework/codestyle/AsyncSampleCallee.java
index 71afd10..59461a4 100644
--- 
a/framework/ipc/test/org/apache/cloudstack/framework/codestyle/AsyncSampleCallee.java
+++ 
b/framework/ipc/test/org/apache/cloudstack/framework/codestyle/AsyncSampleCallee.java
@@ -18,19 +18,19 @@
  */
 package org.apache.cloudstack.framework.codestyle;
 
+import org.apache.cloudstack.framework.async.AsyncCallFuture;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 
 public class AsyncSampleCallee {
        AsyncSampleCallee _driver;
 
-       public void createVolume(Object realParam, 
AsyncCompletionCallback<String> callback) {
+       public AsyncCallFuture<String> createVolume(Object realParam, 
AsyncCompletionCallback<String> callback) {
                
-               // async executed logic
-               {
-                       
-               String resultObject = new String();
-               callback.complete(resultObject);
+               String result = "result object";
+               AsyncCallFuture<String> call = new 
AsyncCallFuture<String>(callback);
                
-               }
+               call.inplaceComplete(result);
+               return call;
        }
 }
+

Reply via email to