org.springframework.scheduling.annotation.AsyncResult Java Examples
The following examples show how to use
org.springframework.scheduling.annotation.AsyncResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RoleRedisCacheServiceAsync.java From momo-cloud-permission with Apache License 2.0 | 6 votes |
/** * redis:更新角色状态 * * @param roleDO 角色信息 * @return */ public Future<String> roleStatusToRedis(RoleDO roleDO, Integer disabledFlag) { Future<String> future = new AsyncResult<>("redis:变更角色状态成功"); RoleDORedisCache roleDORedisCache = RoleDORedisCache.builder().sysRoleName(roleDO.getSysRoleName()) .sysRoleType(roleDO.getSysRoleType()).disabledFlag(disabledFlag) .id(roleDO.getId()).remark(roleDO.getRemark()).createBy(roleDO.getCreateBy()) .createTime(roleDO.getCreateTime()).delFlag(roleDO.getDelFlag()) .updateTime(roleDO.getUpdateTime()).updateBy(roleDO.getUpdateBy()) .tenantId(roleDO.getTenantId()).uuid(roleDO.getUuid()).build(); String redisKey = RedisKeyEnum.REDIS_ROLE_STR.getKey() + roleDORedisCache.getId(); String redisAdminKey = RedisKeyEnum.REDIS_ADMIN_ROLE_STR.getKey() + roleDORedisCache.getTenantId(); String roleStr = JSONObject.toJSONString(roleDORedisCache, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteDateUseDateFormat); redisUtil.set(redisKey, roleStr); //角色的类型,0:管理员(老板),1:管理员(员工) 2:普通员工 3:其他 if (roleDO.getSysRoleType().equals(0)) { redisUtil.set(redisAdminKey, roleStr); } return future; }
Example #2
Source File: VimManagement.java From NFVO with Apache License 2.0 | 6 votes |
@Async @Override public Future<Void> deleteNetwork(VirtualLinkRecord vlr) throws PluginException, NotFoundException, VimException { BaseVimInstance vimInstance = this.query(vlr.getVim_id()); if (vimInstance == null) throw new NotFoundException( String.format("VimInstance with it %s not found", vlr.getVim_id())); vimBroker .getVim(vimInstance.getType()) .delete( vimInstance, vimInstance .getNetworks() .parallelStream() .filter(n -> n.getExtId().equals(vlr.getExtId())) .findFirst() .orElseThrow( () -> new NotFoundException( String.format("Network with it %s not found", vlr.getExtId())))); return new AsyncResult<>(null); }
Example #3
Source File: TagServiceImpl.java From herd with Apache License 2.0 | 6 votes |
@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); }
Example #4
Source File: NetworkServiceRecordManagementClassSuiteTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test public void nsrManagementDeleteTest() throws VimException, InterruptedException, ExecutionException, NotFoundException, WrongStatusException, PluginException, BadFormatException { NetworkServiceRecord nsd_exp = createNetworkServiceRecord(); when(resourceManagement.release(any(VirtualDeploymentUnit.class), any(VNFCInstance.class))) .thenReturn(new AsyncResult<>(null)); when(nsrRepository.findFirstByIdAndProjectId(nsd_exp.getId(), projectId)).thenReturn(nsd_exp); when(vnfrRepository.findByParentNsId(anyString())).thenReturn(new ArrayList<>()); Configuration system = new Configuration(); system.setConfigurationParameters(new HashSet<>()); ConfigurationParameter configurationParameter = new ConfigurationParameter(); configurationParameter.setConfKey("delete-on-all-status"); configurationParameter.setValue("true"); nsrManagement.delete(nsd_exp.getId(), projectId); }
Example #5
Source File: VnfStateHandler.java From NFVO with Apache License 2.0 | 6 votes |
@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); }
Example #6
Source File: AbstractTestCommand.java From camel-spring-boot with Apache License 2.0 | 6 votes |
@Async // needs to run on a spring background thread @Override public Future<Object> execute(Object[] parameters) throws Exception { Assert.assertNotNull("Parameters cannot be null", parameters); Assert.assertEquals("Parameters should contain two elements", 2, parameters.length); Object configObj = parameters[0]; Assert.assertNotNull("The first parameter cannot be null", configObj); Assert.assertTrue("First parameter should be of type ITestConfig, found type " + configObj.getClass().getName(), configObj instanceof ITestConfig); Object compNameObj = parameters[1]; Assert.assertNotNull("The second parameter cannot be null", compNameObj); Assert.assertTrue("Second parameter should be of type String, found type " + compNameObj.getClass().getName(), compNameObj instanceof String); String compName = (String) compNameObj; ITestConfig config = (ITestConfig) configObj; Object result = this.executeTest(config, compName); return new AsyncResult<>(result); }
Example #7
Source File: MessageServerCluster.java From sctalk with Apache License 2.0 | 6 votes |
@Async public ListenableFuture<?> webrtcInitateCallRes(long fromId, long toId, long netId) { // FIXME // 从当前的通话中查看是否已存在 IMAVCall toAvCall = userClientInfoManager.getCalled(toId); if (toAvCall != null) { // 如果存在,返回给呼叫发起方 // TODO 其他端,已经接受了 IMAVCallCancelReq return AsyncResult.forExecutionException(new Exception()); } // 如果不存在,则处理呼叫 userClientInfoManager.addCalled(toId, netId); return AsyncResult.forValue(""); }
Example #8
Source File: MessageServerCluster.java From sctalk with Apache License 2.0 | 6 votes |
/** * 查询用户在线状态 * * @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; }
Example #9
Source File: EmployeeServiceImpl.java From Spring-5.0-Cookbook with MIT License | 5 votes |
@Async public Future<Employee> readEmployee(Integer empId) { try { System.out.println("service:readEmployee(empid) task executor: " + Thread.currentThread().getName()); System.out.println("processing for 2000 ms"); System.out.println("readEmployee @Async login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal()); Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } return new AsyncResult<>(employeeDaoImpl.getEmployee(empId)); }
Example #10
Source File: TestService.java From SpringAll with MIT License | 5 votes |
@Async("asyncThreadPoolTaskExecutor") // @Async public Future<String> asyncMethod() { sleep(); logger.info("异步方法内部线程名称:{}", Thread.currentThread().getName()); return new AsyncResult<>("hello async"); }
Example #11
Source File: AsyncDemoTask.java From seed with Apache License 2.0 | 5 votes |
@Async("seedSimpleExecutor") Future<Integer> doTaskAndGetResultTwo(){ try{ LogUtil.getLogger().info("任务二开始执行"); long start = System.currentTimeMillis(); TimeUnit.SECONDS.sleep(2); LogUtil.getLogger().info("任务二执行完毕,耗时:" + (System.currentTimeMillis() - start) + "ms"); return new AsyncResult<>(2); }catch(Exception e){ LogUtil.getLogger().info("任务二执行期间发生异常,堆栈轨迹如下:", e); return new AsyncResult<>(-2); } }
Example #12
Source File: AsyncDemoTask.java From seed with Apache License 2.0 | 5 votes |
@Async("seedSimpleExecutor") Future<String> doTaskAndGetResultOne(){ try{ LogUtil.getLogger().info("任务一开始执行"); long start = System.currentTimeMillis(); TimeUnit.SECONDS.sleep(1); LogUtil.getLogger().info("任务一执行完毕,耗时:" + (System.currentTimeMillis() - start) + "ms"); return new AsyncResult<>("任务一执行完毕"); }catch(Exception e){ LogUtil.getLogger().info("任务一执行期间发生异常,堆栈轨迹如下:", e); return new AsyncResult<>("任务一执行期间发生异常"); } }
Example #13
Source File: NearbyEntityRetriever.java From Cleanstone with MIT License | 5 votes |
@Async public ListenableFuture<Set<Entity>> getEntitiesInRadius(Entity entity, int chunkRadius) throws ExecutionException, InterruptedException { World world = entity.getWorld(); Chunk baseChunk = world.getChunkAt(entity.getPosition()).get(); return new AsyncResult<>(nearbyChunkRetriever.getChunksAround( baseChunk.getCoordinates(), chunkRadius, world).get().stream() .flatMap(c -> c.getEntities().stream()) .collect(Collectors.toSet())); }
Example #14
Source File: AsyncGetService.java From orders with Apache License 2.0 | 5 votes |
@Async public <T> Future<Resource<T>> getResource(URI url, TypeReferences.ResourceType<T> type) throws InterruptedException, IOException { RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build(); LOG.debug("Requesting: " + request.toString()); Resource<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody(); LOG.debug("Received: " + body.toString()); return new AsyncResult<>(body); }
Example #15
Source File: EmployeeServiceImpl.java From Spring-5.0-Cookbook with MIT License | 5 votes |
@Async public Future<Employee> readEmployee(Integer empId) { try { System.out.println("service:readEmployee(empid) task executor: " + Thread.currentThread().getName()); System.out.println("processing for 2000 ms"); System.out.println("readEmployee @Async login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal()); Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } return new AsyncResult<>(employeeDaoImpl.getEmployee(empId)); }
Example #16
Source File: DataService.java From canal-mongo with Apache License 2.0 | 5 votes |
@Async("myTaskAsyncPool") public Future<Integer> doAsyncTask(String tableName, List<EventData> dataList, String destination) { try { MDC.put("destination", destination); logger.info("thread: " + Thread.currentThread().getName() + " is doing job :" + tableName); for (EventData eventData : dataList) { SpringUtil.doEvent(eventData.getPath(), eventData.getDbObject()); } } catch (Exception e) { logger.error("thread:" + Thread.currentThread().getName() + " get Exception", e); return new AsyncResult(0); } return new AsyncResult(1); }
Example #17
Source File: EmailMessageSender.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Async @Override public Future<OutboundMessageResponse> sendMessageAsync( String subject, String text, String footer, User sender, Set<User> users, boolean forceSend ) { OutboundMessageResponse response = sendMessage( subject, text, footer, sender, users, forceSend ); return new AsyncResult<>(response); }
Example #18
Source File: ResourceManagement.java From NFVO with Apache License 2.0 | 5 votes |
@Override @Async public Future<Void> operate(VirtualDeploymentUnit vdu, String operation) throws PluginException, ExecutionException, InterruptedException, VimException { for (VNFCInstance vnfcInstance : vdu.getVnfc_instance()) { BaseVimInstance vimInstance = vimInstanceRepository.findFirstById(vnfcInstance.getVim_id()); org.openbaton.nfvo.vim_interfaces.resource_management.ResourceManagement vim = vimBroker.getVim(vimInstance.getType()); log.info("rebuilding vnfcInstance: " + vnfcInstance.getHostname()); vim.operate(vimInstance, vdu, vnfcInstance, operation).get(); } return new AsyncResult<>(null); }
Example #19
Source File: AbstractRolloutManagement.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
@Override @Async public ListenableFuture<RolloutGroupsValidation> validateTargetsInGroups(final List<RolloutGroupCreate> groups, final String targetFilter, final Long createdAt) { final String baseFilter = RolloutHelper.getTargetFilterQuery(targetFilter, createdAt); final long totalTargets = targetManagement.countByRsql(baseFilter); if (totalTargets == 0) { throw new ConstraintDeclarationException("Rollout target filter does not match any targets"); } return new AsyncResult<>(validateTargetsInGroups( groups.stream().map(RolloutGroupCreate::build).collect(Collectors.toList()), baseFilter, totalTargets)); }
Example #20
Source File: AsyncTask.java From spring-boot-101 with Apache License 2.0 | 5 votes |
@Async("myAsync") public Future<String> doTask2() throws InterruptedException{ logger.info("Task2 started."); long start = System.currentTimeMillis(); Thread.sleep(3000); long end = System.currentTimeMillis(); logger.info("Task2 finished, time elapsed: {} ms.", end-start); return new AsyncResult<>("Task2 accomplished!"); }
Example #21
Source File: QuadraticRegionManager.java From Cleanstone with MIT License | 5 votes |
@Override public ListenableFuture<Region> loadRegion(ChunkCoords chunkCoords) { Pair<Integer, Integer> regionCoords = getRegionCoordinates(chunkCoords); Region region = new SimpleRegion("QuR[" + regionCoords.getLeft() + ":" + regionCoords.getRight() + "]", new LocalRegionWorker(), chunkProvider); regions.put(regionCoords, region); return new AsyncResult<>(region); }
Example #22
Source File: MockMessageSender.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Async @Override public Future<OutboundMessageResponse> sendMessageAsync( String subject, String text, String footer, User sender, Set<User> users, boolean forceSend ) { OutboundMessageResponse response = sendMessage( subject, text, footer, sender, users, forceSend ); return new AsyncResult<OutboundMessageResponse>( response ); }
Example #23
Source File: AsyncTask.java From springBoot-study with Apache License 2.0 | 5 votes |
@Async public Future<String> test3() { System.out.println("开始三"); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("结束三"); return new AsyncResult<>("任务三完成"); }
Example #24
Source File: AsyncTask.java From springBoot-study with Apache License 2.0 | 5 votes |
@Async public Future<String> test2() { System.out.println("开始二"); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("结束二"); return new AsyncResult<>("任务二完成"); }
Example #25
Source File: MyPoolTask.java From springBoot-study with Apache License 2.0 | 5 votes |
@Async("MyExecutor") public Future<String> test1() { System.out.println("~开始一"); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("~结束一"); return new AsyncResult<>("~任务一完成"); }
Example #26
Source File: AsyncConnectorFacade.java From syncope with Apache License 2.0 | 5 votes |
@Async public Future<Set<ObjectClassInfo>> getObjectClassInfo(final ConnectorFacade connector) { Set<ObjectClassInfo> result = Set.of(); try { result = connector.schema().getObjectClassInfo(); } catch (Exception e) { // catch exception in order to manage unpredictable behaviors LOG.debug("While reading schema on connector {}", connector, e); } return new AsyncResult<>(result); }
Example #27
Source File: AsyncTask.java From hdw-dubbo with Apache License 2.0 | 5 votes |
@Async public Future<String> doTaskThree() throws Exception { System.out.println("开始做任务三"); long start = System.currentTimeMillis(); Thread.sleep(random.nextInt(10000)); long end = System.currentTimeMillis(); System.out.println("完成任务三,耗时:" + (end - start) + "毫秒"); return new AsyncResult<>("任务三完成"); }
Example #28
Source File: AsyncTask.java From hdw-dubbo with Apache License 2.0 | 5 votes |
@Async public Future<String> doTaskTwo() throws Exception { System.out.println("开始做任务二"); long start = System.currentTimeMillis(); Thread.sleep(random.nextInt(10000)); long end = System.currentTimeMillis(); System.out.println("完成任务二,耗时:" + (end - start) + "毫秒"); return new AsyncResult<>("任务二完成"); }
Example #29
Source File: AsyncTask.java From Hands-On-High-Performance-with-Spring-5 with MIT License | 5 votes |
@Async public Future<String> doAsyncTaskWithReturnType() { try { return new AsyncResult<String>("Running Async Task thread : " + Thread.currentThread().getName()); } catch (Exception e) { // } return null; }
Example #30
Source File: BankAsyncService.java From Hands-On-High-Performance-with-Spring-5 with MIT License | 5 votes |
@Async public Future<String> syncCustomerAccount() throws InterruptedException { LOGGER.info("Sync Account Processing Started - Thread id: " + Thread.currentThread().getId()); // Sleeps 2s Thread.sleep(2000); String processInfo = String.format("Sync Account Processing Completed - Thread Name= %d, Thread Name= %s", Thread.currentThread().getId(), Thread.currentThread().getName()); LOGGER.info(processInfo); return new AsyncResult<String>(processInfo); }