當前位置: 首頁>>代碼示例>>Java>>正文


Java ListenableFuture.addCallback方法代碼示例

本文整理匯總了Java中org.springframework.util.concurrent.ListenableFuture.addCallback方法的典型用法代碼示例。如果您正苦於以下問題:Java ListenableFuture.addCallback方法的具體用法?Java ListenableFuture.addCallback怎麽用?Java ListenableFuture.addCallback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.util.concurrent.ListenableFuture的用法示例。


在下文中一共展示了ListenableFuture.addCallback方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: send

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
public void send(String topic, LifecycleEvent message) {
    // the KafkaTemplate provides asynchronous send methods returning a Future
    ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(topic, message);

    // register a callback with the listener to receive the result of the send asynchronously
    future.addCallback(new ListenableFutureCallback<SendResult<String, Object>>() {

        @Override
        public void onSuccess(SendResult<String, Object> result) {
            LOGGER.info("sent message='{}' with offset={}", message,
                    result.getRecordMetadata().offset());
        }

        @Override
        public void onFailure(Throwable ex) {
            LOGGER.error("unable to send message='{}'", message, ex);
        }
    });
}
 
開發者ID:corydissinger,項目名稱:mtgo-best-bot,代碼行數:20,代碼來源:LifecycleEventSender.java

示例2: createCell

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.GET, path = "/createCell")
public void createCell(@NotNull @RequestParam String name, @NotNull @RequestParam CellType cellType) throws ExecutionException, InterruptedException {
    JSONObject cell = new JSONObject();
    cell.put("name", name);
    cell.put("type", cellType);

    ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, cell.toString());
    future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
        @Override
        public void onSuccess(SendResult<String, String> result) {
            System.out.println("success");
        }

        @Override
        public void onFailure(Throwable ex) {
            System.out.println("failed");
        }
    });
}
 
開發者ID:Chabane,項目名稱:mitosis-microservice-spring-reactor,代碼行數:20,代碼來源:SpringBootKafkaController.java

示例3: websyncDeptList

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@GetMapping(value="/webSyncDept/{id}.json", produces ="application/json", headers = {"Accept=text/xml, application/json"})
public WebAsyncTask<Department> websyncDeptList(@PathVariable("id") Integer id){
   
    Callable<Department> callable = new Callable<Department>() {
    	public Department call() throws Exception {
    		
    		 ListenableFuture<Department> listenFuture = departmentServiceImpl.findAllFirstById(id);
    		 listenFuture.addCallback(new ListenableFutureCallback<Department>(){

				@Override
				public void onSuccess(Department dept) {
					result = dept;
				}

				@Override
				public void onFailure(Throwable arg0) {
					result = new Department();
				}
    			 
    		 });
    		 return result;
          }
    };
    return new WebAsyncTask<Department>(500, callable);
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:26,代碼來源:DeptAsyncController.java

示例4: rest

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@GetMapping("/rest")
public DeferredResult<String> rest(int idx) {
    DeferredResult<String> dr = new DeferredResult<String>();

    ListenableFuture<ResponseEntity<String>> f1 = rt.getForEntity(URL1, String.class, "h" + idx);
    f1.addCallback(s -> {

        ListenableFuture<ResponseEntity<String>> f2 = rt.getForEntity(URL2, String.class, s.getBody());
        f2.addCallback(s2 -> {
            ListenableFuture<String> f3 = myService.work(s2.getBody());
            f3.addCallback(s3 -> {
                dr.setResult(s3);
            }, e3 -> {
                dr.setErrorResult(e3.getMessage());
            });
        }, e2 -> {
            dr.setErrorResult(e2.getMessage());
        });
    }, e -> {
        dr.setErrorResult(e.getMessage());
    });
    return dr;
}
 
開發者ID:sejoung,項目名稱:ReactiveTest,代碼行數:24,代碼來源:SpringTobyTv009Application.java

示例5: getProcessState

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@Async
public Future<ProcessStateDTO> getProcessState(final Long piId) throws URISyntaxException {
  final CompletableFuture<ProcessStateDTO> future = new CompletableFuture<>();

  final URIBuilder uri =
      new URIBuilder(gatewayConfig.getProcessEngineAddress()).setPath("processes/state/" + piId);

  final ListenableFuture<ResponseEntity<ProcessStateDTO>> responseFuture =
      createRequest(uri, HttpMethod.GET, null, ProcessStateDTO.class, null);

  responseFuture.addCallback(result -> {
    final List<UserContainer> container = Lists.newArrayList(result.getBody().getSubjects());
    getUser(container);
    future.complete(result.getBody());
  }, error -> {
    future.completeExceptionally(error);
  });

  return future;
}
 
開發者ID:stefanstaniAIM,項目名稱:IPPR2016,代碼行數:21,代碼來源:ProcessEngineCallerImpl.java

示例6: send

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
public void send(String topic, String data) {
    ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, data);
    future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
        @Override
        public void onSuccess(SendResult<String, String> result) {
            logger.info("Success on sending message \"" + data + "\" to topic " + topic);
        }

        @Override
        public void onFailure(Throwable ex) {
            logger.error("Error on sending message \"" + data + "\", stacktrace " + ex.getMessage());
        }
    });
}
 
開發者ID:Arquisoft,項目名稱:participationSystem3b,代碼行數:15,代碼來源:KafkaProducer.java

示例7: send

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
public DeferredResult<LoginDetails> send(String content) {
	System.out.println("send request");
	final DeferredResult<LoginDetails> response = new DeferredResult<>();
	ListenableFuture<LoginDetails> future = asyncRabbitTemplate.convertSendAndReceive(requestQueue.getName(),
			content);
	future.addCallback(new LoginHandlerResponse(response));

	System.out.println(asyncRabbitTemplate.isAutoStartup());
	System.out.println(asyncRabbitTemplate.isRunning());

	return response;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:13,代碼來源:SendAsyncEventLogin.java

示例8: send

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
public DeferredResult<LoginDetails> send(String content) {  
    System.out.println("send request");
    final DeferredResult<LoginDetails> response = new DeferredResult<>();    
    ListenableFuture<LoginDetails> future =
    		asyncRabbitTemplate.convertSendAndReceive(exchange.getName(), "packt.async", content);
    future.addCallback(new LoginHandlerResponse(response));
        
    System.out.println(asyncRabbitTemplate.isAutoStartup());
    System.out.println(asyncRabbitTemplate.isRunning());
		
	return response;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:13,代碼來源:SendAsyncLogin.java

示例9: run

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@Bean
ApplicationRunner run() {
    return args -> {
        log.debug("run");
        ListenableFuture<String> s = myService.hello();
        s.addCallback(a -> log.debug(a), e -> log.debug(e.getMessage()));
        log.debug("exit");
    };

}
 
開發者ID:sejoung,項目名稱:ReactiveTest,代碼行數:11,代碼來源:Spring5Application.java

示例10: sendMessage

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
public void sendMessage(Student student) {

		ListenableFuture<SendResult<String, Student>> future = kafkaTemplate
				.send(env.getProperty("kafka.topics"), student);

		future.addCallback(new ListenableFutureCallback<SendResult<String, Student>>() {

			@Override
			public void onFailure(Throwable ex) {
				LOGGER.error("Inside Exception");

			}

			@Override
			public void onSuccess(SendResult<String, Student> result) {
				LOGGER.info("Inside Success");

			}
		});

	}
 
開發者ID:sarojrout,項目名稱:spring-tutorial,代碼行數:22,代碼來源:KafkaEventProducer.java

示例11: appendUserInformation

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@Async
private <T extends UserContainer> void appendUserInformation(
    final ListenableFuture<ResponseEntity<T[]>> responseFuture,
    final CompletableFuture<List<T>> future) {

  responseFuture.addCallback(result -> {
    final List<T> entries = Lists.newArrayList(result.getBody());
    getUser(Lists.newArrayList(result.getBody()));
    future.complete(entries);
  }, error -> future.completeExceptionally(error));
}
 
開發者ID:stefanstaniAIM,項目名稱:IPPR2016,代碼行數:12,代碼來源:ProcessEngineCallerImpl.java

示例12: send

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
/**
 * Metodo funndamental para la informacion en Kafka.
 * @param topic Topico de Kafka.
 * @param data Datos a enviar.
 */
public void send(String topic, String data) {
    ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, data); //Valido por si solo para el manejo de la informacion.
    future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
        @Override
        public void onSuccess(SendResult<String, String> result) {
            logger.info("Success on sending message \"" + data + "\" to topic " + topic);
        }

        @Override
        public void onFailure(Throwable ex) {
            logger.error("Error on sending message \"" + data + "\", stacktrace " + ex.getMessage());
        }
    });
}
 
開發者ID:Arquisoft,項目名稱:dashboard1b,代碼行數:20,代碼來源:KafkaProducer.java

示例13: send

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
public void send(String topic, String data) {
    ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, data);
    future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
        @Override
        public void onSuccess(SendResult<String, String> result) {
            logger.info(result);
            logger.info("Success on sending message \"" + data + "\" to topic " + topic);
        }

        @Override
        public void onFailure(Throwable ex) {
            logger.error("Error on sending message \"" + data + "\", stacktrace " + ex.getMessage());
        }
    });
}
 
開發者ID:Arquisoft,項目名稱:dashboard1b,代碼行數:16,代碼來源:KafkaProducer.java

示例14: userStatusReq

import org.springframework.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@Override
public void userStatusReq(IMHeader header, MessageLite body, ChannelHandlerContext ctx) {

    // CID_BUDDY_LIST_USERS_STATUS_REQUEST
    logger.debug("Send the users status request to router");
    long userId = super.getUserId(ctx);

    IMUsersStatReq usersStatReq = (IMUsersStatReq) body;

    ListenableFuture<List<IMBaseDefine.UserStat>> userStatFuture =
            messageServerCluster.userStatusReq(userId, usersStatReq.getUserIdListList());
    userStatFuture.addCallback((List<IMBaseDefine.UserStat> userStatList) -> {
        // 查詢用戶狀態後處理
        IMBuddy.IMUsersStatRsp.Builder userStatRes = IMBuddy.IMUsersStatRsp.newBuilder();
        userStatRes.addAllUserStatList(userStatList);
        userStatRes.setUserId(userId);
        userStatRes.setAttachData(usersStatReq.getAttachData());

        IMHeader headerRes = header.clone();
        headerRes.setCommandId(
                (short) BuddyListCmdID.CID_BUDDY_LIST_USERS_STATUS_RESPONSE_VALUE);
        ctx.writeAndFlush(new IMProtoMessage<>(headerRes, userStatRes.build()));
    }, (Throwable e) -> {
        // 異常處理
        logger.warn("處理推送異常", e);
    });
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:28,代碼來源:IMBuddyListHandlerImpl.java


注:本文中的org.springframework.util.concurrent.ListenableFuture.addCallback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。