mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-15 18:12:35 +01:00
Add AsyncCallFuture
This commit is contained in:
parent
01701b1d9c
commit
107fccdf69
@ -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>
|
||||
|
||||
@ -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" />
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user