本文整理汇总了Java中org.springframework.scheduling.annotation.AsyncResult类的典型用法代码示例。如果您正苦于以下问题:Java AsyncResult类的具体用法?Java AsyncResult怎么用?Java AsyncResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsyncResult类属于org.springframework.scheduling.annotation包,在下文中一共展示了AsyncResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleItems
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Async
@Override
public Future<List<GetPrizeDTO>> scheduleItems(ScheduleItem item) throws InterruptedException {
log.info("Start Schedule with : " +item.getRecipientID());
log.info("query Type " + item.getQueryType());
Future<List<GetPrizeDTO>> result = new AsyncResult<>(new ArrayList<>());
if(item.getQueryType() == ConstantUtil.NORMAL_QUERY) {
result = new AsyncResult<>(resultService.findPrizeByResultType(item.getLotteryType(), item.getParam().toArray(new String[]{})));
} else if(item.getQueryType() == ConstantUtil.CODE_RANGE_QUERY) {
result = new AsyncResult<>(resultService.findPrizesByCode(item.getParam().get(0), item.getParam().get(1), item.getParam().get(2), item.getLotteryType()));
} else if(item.getQueryType() == ConstantUtil.POINT_RANGE_QUERY) {
result = new AsyncResult<>(resultService.findPrizesByPoints(item.getParam().get(0), item.getParam().get(1), item.getParam().get(2), item.getLotteryType()));
}
// remove from db after finding result.
deleteScheduleItem(item.getRecipientID());
return result;
}
示例2: userStatusReq
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
/**
* 查询用户在线状态
*
* @param fromUserId 用户ID
* @param userIdList 查询列表
* @return
* @since 1.0
*/
@Async
public ListenableFuture<List<IMBaseDefine.UserStat>> userStatusReq(Long fromUserId, List<Long> userIdList) {
logger.debug("查询用户在线状态, user_cnt={}", userIdList.size());
List<IMBaseDefine.UserStat> userStatList = new ArrayList<>();
for (Long userId: userIdList) {
UserClientInfoManager.UserClientInfo userClientInfo = userClientInfoManager.getUserInfo(userId);
IMBaseDefine.UserStat.Builder userStatBuiler = IMBaseDefine.UserStat.newBuilder();
userStatBuiler.setUserId(userId);
if (userClientInfo != null) {
userStatBuiler.setStatus(userClientInfo.getStatus());
} else {
userStatBuiler.setStatus(IMBaseDefine.UserStatType.USER_STATUS_OFFLINE);
}
userStatList.add(userStatBuiler.build());
}
AsyncResult<List<IMBaseDefine.UserStat>> result = new AsyncResult<>(userStatList);
return result;
}
示例3: getRxJavaDTO
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
/**
* 异步执行,需要返回的Future<>类型
*
* @param name
* @return
*/
@Async
public Future<RxJavaDTO> getRxJavaDTO(String name) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("common service begin to process");
RxJavaDTO item = new RxJavaDTO();
item.setName(name);
String value = MDC.get(MdcConstans.MDC_REMOTE_IP);
if (!StringUtils.isEmpty(value)) {
log.info("remoteid id " + value);
} else {
log.info("remoteid id is empty");
}
value = MDC.get(MdcConstans.MDC_ClientRequest_ID);
if (!StringUtils.isEmpty(value)) {
log.info("client id " + value);
} else {
log.info("client id is empty");
}
log.info("common service end to process");
return new AsyncResult<>(item);
}
示例4: execute
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Override
public Future<List<Event>> execute(Event event, Device device) {
List<Event> outEvents = new ArrayList<>();
ServiceResponse<List<EventRoute>> serviceRoutes = eventRouteService.getAll(device.getTenant(), device.getApplication());
if (!serviceRoutes.isOk()) {
LOGGER.error("Error listing application events routes", device.toURI(), device.getTenant().getLogLevel());
return new AsyncResult<>(outEvents);
}
List<EventRoute> eventRoutes = serviceRoutes.getResult();
if (eventRoutes.isEmpty()) {
return new AsyncResult<>(outEvents);
}
eventRoutes.parallelStream().forEach((eventRoute) ->
processEventRoute(event, device, outEvents, eventRoute)
);
return new AsyncResult<>(outEvents);
}
示例5: runTask
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Async
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Future<Boolean> runTask(Integer jobId) throws AsyncTaskException {
Job job = this.jobRepo.findOne(jobId);
try {
this.restorer.restore(job.getDbDumperServiceInstance(), job.getDatabaseRefTarget(), job.getDumpDate());
} catch (RestoreException e) {
logger.error(String.format("Cannot restore dump for '%s' in '%s': %s", job.getDatabaseRefSrc().getDatabaseName(), job.getDatabaseRefTarget().getDatabaseName(), e.getMessage()));
job.setJobEvent(JobEvent.ERRORED);
job.setErrorMessage(e.getMessage());
this.databaseRefManager.deleteServiceKey(job);
jobRepo.save(job);
return new AsyncResult<Boolean>(false);
}
this.databaseRefManager.deleteServiceKey(job);
job.setJobEvent(JobEvent.FINISHED);
jobRepo.save(job);
return new AsyncResult<Boolean>(true);
}
示例6: processBusinessObjectDataNotificationEventAsync
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Override
@Async
public Future<Void> processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata notificationEventType,
BusinessObjectDataKey businessObjectDataKey, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus)
{
/*
* Need to clear the security context here since the current thread may have been reused, which may might have left over its security context. If we do
* not clear the security context, any subsequent calls may be restricted by the permissions given to the previous thread's security context.
*/
SecurityContextHolder.clearContext();
processBusinessObjectDataNotificationEventSync(notificationEventType, businessObjectDataKey, newBusinessObjectDataStatus, oldBusinessObjectDataStatus);
// Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they
// can call "get" to see if any exceptions were thrown.
return new AsyncResult<>(null);
}
示例7: processStorageUnitNotificationEventAsync
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Override
@Async
public Future<Void> processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit notificationEventType,
BusinessObjectDataKey businessObjectDataKey, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus)
{
/*
* Need to clear the security context here since the current thread may have been reused, which may might have left over its security context. If we do
* not clear the security context, any subsequent calls may be restricted by the permissions given to the previous thread's security context.
*/
SecurityContextHolder.clearContext();
processStorageUnitNotificationEventSync(notificationEventType, businessObjectDataKey, storageName, newStorageUnitStatus, oldStorageUnitStatus);
// Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they
// can call "get" to see if any exceptions were thrown.
return new AsyncResult<>(null);
}
示例8: indexValidateAllTags
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Override
@Async
public Future<Void> indexValidateAllTags(String indexName)
{
final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
// Get a list of all tags
final List<TagEntity> tagEntityList = Collections.unmodifiableList(tagDao.getTags());
// Remove any index documents that are not in the database
removeAnyIndexDocumentsThatAreNotInTagsList(indexName, documentType, tagEntityList);
// Validate all Tags
tagHelper.executeFunctionForTagEntities(indexName, documentType, tagEntityList, indexFunctionsDao::validateDocumentIndex);
// Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they
// can call "get" to see if any exceptions were thrown.
return new AsyncResult<>(null);
}
示例9: indexValidateAllBusinessObjectDefinitions
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Override
@Async
public Future<Void> indexValidateAllBusinessObjectDefinitions(String indexName)
{
final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
// Get a list of all business object definitions
final List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityList =
Collections.unmodifiableList(businessObjectDefinitionDao.getAllBusinessObjectDefinitions());
// Remove any index documents that are not in the database
removeAnyIndexDocumentsThatAreNotInBusinessObjectsDefinitionsList(indexName, documentType, businessObjectDefinitionEntityList);
// Validate all Business Object Definitions
businessObjectDefinitionHelper.executeFunctionForBusinessObjectDefinitionEntities(indexName, documentType, businessObjectDefinitionEntityList,
indexFunctionsDao::validateDocumentIndex);
// Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they
// can call "get" to see if any exceptions were thrown.
return new AsyncResult<>(null);
}
示例10: indexAllTags
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Override
@Async
public Future<Void> indexAllTags(SearchIndexKey searchIndexKey, String documentType)
{
// Get a list of all tags
final List<TagEntity> tagEntities = Collections.unmodifiableList(tagDao.getTags());
// Index all tags.
tagHelper.executeFunctionForTagEntities(searchIndexKey.getSearchIndexName(), documentType, tagEntities, indexFunctionsDao::createIndexDocument);
// Simple count validation, index size should equal entity list size.
validateSearchIndexSize(searchIndexKey.getSearchIndexName(), documentType, tagEntities.size());
// Update search index status to READY.
searchIndexDaoHelper.updateSearchIndexStatus(searchIndexKey, SearchIndexStatusEntity.SearchIndexStatuses.READY.name());
// Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they can call
// "get" to see if any exceptions were thrown.
return new AsyncResult<>(null);
}
示例11: createVimInstance
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Test
public void createVimInstance()
throws VimException, PluginException, IOException, BadRequestException,
AlreadyExistingException, ExecutionException, InterruptedException {
OpenstackVimInstance datacenter = new OpenstackVimInstance();
datacenter.setId("123");
datacenter.setName("DC-1");
datacenter.setType("OpenStack");
datacenter.setUsername("datacenter_test");
datacenter.setTenant("tenant");
datacenter.setKeyPair("keypair");
datacenter.setPassword("");
when(mock.add(any(datacenter.getClass()), anyString()))
.thenReturn(new AsyncResult<>(datacenter));
log.info("" + restVimInstances.create(datacenter, "pi"));
BaseVimInstance datacenter2 = restVimInstances.create(datacenter, "pi");
assertEquals(datacenter, datacenter2);
}
示例12: requestLog
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Override
@Async
public Future<NFVMessage> requestLog(VirtualNetworkFunctionRecord vnfr, String hostname)
throws NotFoundException, BadFormatException, ExecutionException, InterruptedException {
VnfmManagerEndpoint endpoint = generator.getVnfm(vnfr.getEndpoint());
if (endpoint == null)
throw new NotFoundException(
"VnfManager of type "
+ vnfr.getType()
+ " (endpoint = "
+ vnfr.getEndpoint()
+ ") is not registered");
OrVnfmLogMessage orVnfmLogMessage = new OrVnfmLogMessage(vnfr.getName(), hostname);
VnfmSender vnfmSender;
try {
vnfmSender = generator.getVnfmSender(endpoint.getEndpointType());
} catch (BeansException e) {
throw new NotFoundException(e);
}
Future<NFVMessage> answerFuture = vnfmSender.sendCommand(orVnfmLogMessage, endpoint);
answerFuture.get();
NFVMessage message = answerFuture.get();
return new AsyncResult<>(message);
}
示例13: handleVNF
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Override
@Async
public Future<Void> handleVNF(
NetworkServiceDescriptor networkServiceDescriptor,
NetworkServiceRecord networkServiceRecord,
DeployNSRBody body,
Map<String, Set<String>> vduVimInstances,
VirtualNetworkFunctionDescriptor vnfd,
String monitoringIp)
throws NotFoundException, BadFormatException, ExecutionException, InterruptedException {
log.debug(
"Processing VNFD ("
+ vnfd.getName()
+ ") for NSD ("
+ networkServiceDescriptor.getName()
+ ")");
VnfmSender vnfmSender = generator.getVnfmSender(vnfd);
NFVMessage message =
generator.getNextMessage(vnfd, vduVimInstances, networkServiceRecord, body, monitoringIp);
VnfmManagerEndpoint endpoint = generator.getEndpoint(vnfd);
log.debug("----------Executing ACTION: " + message.getAction());
executeAction(vnfmSender.sendCommand(message, endpoint));
log.info("Sent " + message.getAction() + " to VNF: " + vnfd.getName());
return new AsyncResult<>(null);
}
示例14: send
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Override
@Async
public Future<Void> send(EventEndpoint endpoint, final ApplicationEventNFVO event) {
log.debug("Sending message: " + event + " to endpoint: " + endpoint);
log.info("Sending message: " + event.getAction() + " to endpoint: " + endpoint.getName());
final String json =
"{\"action\":\""
+ event.getAction()
+ "\",\"payload\":"
+ new Gson().toJson(event.getPayload())
+ "}";
log.trace("Event body is: " + json);
rabbitTemplate.convertAndSend(endpoint.getEndpoint(), json);
return new AsyncResult<>(null);
}
示例15: nsrManagementDeleteTest
import org.springframework.scheduling.annotation.AsyncResult; //导入依赖的package包/类
@Test
public void nsrManagementDeleteTest()
throws VimException, InterruptedException, ExecutionException, NamingException,
NotFoundException, WrongStatusException, PluginException, BadFormatException {
NetworkServiceRecord nsd_exp = createNetworkServiceRecord();
when(resourceManagement.release(any(VirtualDeploymentUnit.class), any(VNFCInstance.class)))
.thenReturn(new AsyncResult<Void>(null));
when(nsrRepository.findFirstByIdAndProjectId(nsd_exp.getId(), projectId)).thenReturn(nsd_exp);
Configuration system = new Configuration();
system.setConfigurationParameters(new HashSet<>());
ConfigurationParameter configurationParameter = new ConfigurationParameter();
configurationParameter.setConfKey("delete-on-all-status");
configurationParameter.setValue("true");
when(configurationManagement.queryByName("system")).thenReturn(system);
nsrManagement.delete(nsd_exp.getId(), projectId);
}