当前位置: 首页>>代码示例>>Java>>正文


Java DeferredResult.setResult方法代码示例

本文整理汇总了Java中org.springframework.web.context.request.async.DeferredResult.setResult方法的典型用法代码示例。如果您正苦于以下问题:Java DeferredResult.setResult方法的具体用法?Java DeferredResult.setResult怎么用?Java DeferredResult.setResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.context.request.async.DeferredResult的用法示例。


在下文中一共展示了DeferredResult.setResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDeviceAttributesShadow

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/device/token/{deviceToken}/attributes/shadow", method = RequestMethod.GET, produces = "application/json")
public DeferredResult<ResponseEntity> getDeviceAttributesShadow(@PathVariable("deviceToken") String deviceToken) {
  DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
  HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
  if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
    DeviceId _deviceId = ctx.getDevice().getId();
    try {
      List<ListenableFuture<List<AttributeKvEntry>>> futures = new ArrayList<>();
      Arrays.asList(DataConstants.ALL_SCOPES)
          .forEach(attributeType -> futures.add(attributesService.findAll(_deviceId, attributeType)));
      ListenableFuture<List<List<AttributeKvEntry>>> successfulAsList = Futures.successfulAsList(futures);
      List<AttributeKvEntry> result = new ArrayList<>();
      successfulAsList.get().forEach(r -> result.addAll(r));
      List<ThingsKVData> collect = result.stream().map(attribute -> new ThingsKVData(attribute.getKey(), attribute.getValue())).collect(Collectors.toList());
      responseWriter.setResult(new ResponseEntity<>(collect, HttpStatus.OK));

    } catch (InterruptedException | ExecutionException e) {
      e.printStackTrace();
      responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
    }
  } else {
    responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
  }

  return responseWriter;
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:27,代码来源:DeviceApiController.java

示例2: processRequest

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/{pluginToken}/**")
@ResponseStatus(value = HttpStatus.OK)
public DeferredResult<ResponseEntity> processRequest(
        @PathVariable("pluginToken") String pluginToken,
        RequestEntity<byte[]> requestEntity,
        HttpServletRequest request)
        throws IoTPException {
    log.debug("[{}] Going to process requst uri: {}", pluginToken, requestEntity.getUrl());
    DeferredResult<ResponseEntity> result = new DeferredResult<ResponseEntity>();
    PluginMetaData pluginMd = pluginService.findPluginByApiToken(pluginToken);
    if (pluginMd == null) {
        result.setErrorResult(new PluginNotFoundException("Plugin with token: " + pluginToken + " not found!"));
    } else {
        TenantId tenantId = getCurrentUser().getTenantId();
        CustomerId customerId = getCurrentUser().getCustomerId();
        if (validatePluginAccess(pluginMd, tenantId, customerId)) {
            if(ModelConstants.NULL_UUID.equals(tenantId.getId())){
                tenantId = null;
            }
            PluginApiCallSecurityContext securityCtx = new PluginApiCallSecurityContext(pluginMd.getTenantId(), pluginMd.getId(), tenantId, customerId);
            actorService.process(new BasicPluginRestMsg(securityCtx, new RestRequest(requestEntity, request), result));
        } else {
            result.setResult(new ResponseEntity<>(HttpStatus.FORBIDDEN));
        }

    }
    return result;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:31,代码来源:PluginApiController.java

示例3: requestAsync

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
public static <T> DeferredResult<T> requestAsync(final TaskExecutor executor,
    final Callable<T> action) {
    final DeferredResult<T> result = new DeferredResult<>();

    final Runnable beforeCallable = () -> {
        try {
            T t = action.call();

            if (result.isSetOrExpired()) {
                log.error("async request expired");
                return;
            }

            result.setResult(t);
        } catch (final Exception ex) {
            result.setErrorResult(ex);
        }
    };

    executor.execute(beforeCallable);
    return result;
}
 
开发者ID:rsdomingues,项目名称:wiredtigervsvmap,代码行数:23,代码来源:DeferredResultAdapter.java

示例4: postEvent

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
/**
 * Receives an event
 * <p>
 * Sample event payload:
 * <pre>
 *  {
 *      "timestamp": "2016-11-19T20:55:32Z",
 *      "target": "product",
 *      "targetId": "8976",
 *      "subject": "customer",
 *      "subjectId": "2134"
 *  }
 * </pre>
 * <p>
 * The client can call
 * <a href="http://localhost:8080/events/resource.accessed/">http://localhost:8080/events/resource.accessed/</a>
 * with the sample payload as the body.
 *
 * @param event   Event name
 * @param payload Event payload
 * @return Http status 202 (Accepted) if the call succeeds. The corresponding 4XX or 5XX codes otherwise.
 * @see <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">Status Code Definitions</a>
 */
@RequestMapping(value = "{event}", method = RequestMethod.POST)
public DeferredResult<ResponseEntity> postEvent(@PathVariable("event") String event, @RequestBody String payload) {

    //The DeferredResult return type makes this an asynchronous call
    DeferredResult<ResponseEntity> result = new DeferredResult<ResponseEntity>();

    /*
        Just delegate the processing to Akka.
        Because this is a non blocking call, there's no wait for execution.
     */
    eventSupervisor.tell(new EventReceived(event, payload), ActorRef.noSender());

    /*
        As ActorSelection.tell is a non blocking call,
        just return HTTP status code 202 (Accepted) to client
        and the processing continue into Akka actors.

        In this case, exceptions must be logged by actors processing logic.
     */
    result.setResult(new ResponseEntity(HttpStatus.ACCEPTED));

    return result;
}
 
开发者ID:flaviomedeiros,项目名称:spring-akka-poc,代码行数:47,代码来源:EventController.java

示例5: getDeviceAttributes

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/{deviceToken}/attributes", method = RequestMethod.GET, produces = "application/json")
public DeferredResult<ResponseEntity> getDeviceAttributes(@PathVariable("deviceToken") String deviceToken,
                                                          @RequestParam(value = "clientKeys", required = false, defaultValue = "") String clientKeys,
                                                          @RequestParam(value = "sharedKeys", required = false, defaultValue = "") String sharedKeys) {
    DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
    HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
    if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
        GetAttributesRequest request;
        if (StringUtils.isEmpty(clientKeys) && StringUtils.isEmpty(sharedKeys)) {
            request = new BasicGetAttributesRequest(0);
        } else {
            Set<String> clientKeySet = !StringUtils.isEmpty(clientKeys) ? new HashSet<>(Arrays.asList(clientKeys.split(","))) : null;
            Set<String> sharedKeySet = !StringUtils.isEmpty(sharedKeys) ? new HashSet<>(Arrays.asList(sharedKeys.split(","))) : null;
            request = new BasicGetAttributesRequest(0, clientKeySet, sharedKeySet);
        }
        process(ctx, request);
    } else {
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
    }

    return responseWriter;
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:23,代码来源:DeviceApiController.java

示例6: postDeviceAttributes

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/{deviceToken}/attributes", method = RequestMethod.POST)
public DeferredResult<ResponseEntity> postDeviceAttributes(@PathVariable("deviceToken") String deviceToken,
                                                           @RequestBody String json) {
    DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
    HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
    if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
        try {
            process(ctx, JsonConverter.convertToAttributes(new JsonParser().parse(json)));
        } catch (IllegalStateException | JsonSyntaxException ex) {
            responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
        }
    } else {
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
    }
    return responseWriter;
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:17,代码来源:DeviceApiController.java

示例7: postTelemetry

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/{deviceToken}/telemetry", method = RequestMethod.POST)
public DeferredResult<ResponseEntity> postTelemetry(@PathVariable("deviceToken") String deviceToken,
                                                    @RequestBody String json) {
    DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
    HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
    if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
        try {
            process(ctx, JsonConverter.convertToTelemetry(new JsonParser().parse(json)));
        } catch (IllegalStateException | JsonSyntaxException ex) {
            responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
        }
    } else {
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
    }
    return responseWriter;
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:17,代码来源:DeviceApiController.java

示例8: replyToCommand

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/{deviceToken}/rpc/{requestId}", method = RequestMethod.POST)
public DeferredResult<ResponseEntity> replyToCommand(@PathVariable("deviceToken") String deviceToken,
                                                     @PathVariable("requestId") Integer requestId,
                                                     @RequestBody String json) {
    DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
    HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
    if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
        try {
            JsonObject response = new JsonParser().parse(json).getAsJsonObject();
            process(ctx, new ToDeviceRpcResponseMsg(requestId, response.toString()));
        } catch (IllegalStateException | JsonSyntaxException ex) {
            responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
        }
    } else {
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
    }
    return responseWriter;
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:19,代码来源:DeviceApiController.java

示例9: postRpcRequest

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/{deviceToken}/rpc", method = RequestMethod.POST)
public DeferredResult<ResponseEntity> postRpcRequest(@PathVariable("deviceToken") String deviceToken,
                                                     @RequestBody String json) {
    DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
    HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
    if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
        try {
            JsonObject request = new JsonParser().parse(json).getAsJsonObject();
            process(ctx, new ToServerRpcRequestMsg(0,
                    request.get("method").getAsString(),
                    request.get("params").toString()));
        } catch (IllegalStateException | JsonSyntaxException ex) {
            responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
        }
    } else {
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
    }
    return responseWriter;
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:20,代码来源:DeviceApiController.java

示例10: test

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/asyncDeferred", method = RequestMethod.GET)
public  DeferredResult<ResponseEntity<String>> test() {
    verifyActiveSpan();
    DeferredResult<ResponseEntity<String>> df = new DeferredResult<>();
    df.setResult(ResponseEntity.status(202).body("deferred"));
    return df;
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-web,代码行数:8,代码来源:TestController.java

示例11: getDeviceTelemetryShadow

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/device/token/{deviceToken}/telemetry/shadow", method = RequestMethod.GET, produces = "application/json")
  public DeferredResult<ResponseEntity> getDeviceTelemetryShadow(@PathVariable("deviceToken") String deviceToken) {
    DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
    HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
    if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
      DeviceId _deviceId = ctx.getDevice().getId();
      try {
        List<TsKvEntry> tsList = timeseriesService.findAllLatest(_deviceId).get();
//        if (tsList != null) {
//          for (TsKvEntry tsKvEntry : tsList) {
//            String key = tsKvEntry.getKey();
//            Object value = tsKvEntry.getValue();
//            log.info("key:{}, value:{}", key, value);
//          }
//        }
        List<ThingsKVData> collect = tsList.stream().map(attribute -> new ThingsKVData(attribute.getKey(), attribute.getValue())).collect(Collectors.toList());
        responseWriter.setResult(new ResponseEntity<>(collect, HttpStatus.OK));

      } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
      }
    } else {
      responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
    }

    return responseWriter;
  }
 
开发者ID:osswangxining,项目名称:iothub,代码行数:29,代码来源:DeviceApiController.java

示例12: postDeviceAttributes

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/{deviceToken}/attributes", method = RequestMethod.POST)
public DeferredResult<ResponseEntity> postDeviceAttributes(@PathVariable("deviceToken") String deviceToken,
    @RequestBody String json) {
  DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
  HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
  if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
    try {
      String kafkaOutboundTopic = KafkaTopics.DEVICE_ATTRIBUTES_TOPIC;
      Device device = ctx.getDevice();
      if (device != null && device.getId() != null) {
        // BasicToDeviceActorSessionMsg basicToDeviceActorSessionMsg = new
        // BasicToDeviceActorSessionMsg(
        // device, msg);
        JsonObject root = new JsonObject();
        JsonElement jsonElement = new JsonParser().parse(json);
        root.add("d", jsonElement);
        root.addProperty("messageId", DEFAULT_REQUEST_ID);
        log.info("msg: {}", root.toString());

        this.msgProducer.send(kafkaOutboundTopic, device.getId().toString(), root.toString());
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.OK));
      } else {
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
      }
      // process(ctx, JsonConverter.convertToAttributes(new
      // JsonParser().parse(json)));
    } catch (IllegalStateException | JsonSyntaxException ex) {
      responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
    }
  } else {
    responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
  }
  return responseWriter;
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:35,代码来源:DeviceApiController.java

示例13: postTelemetry

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(value = "/{deviceToken}/telemetry", method = RequestMethod.POST)
public DeferredResult<ResponseEntity> postTelemetry(@PathVariable("deviceToken") String deviceToken,
    @RequestBody String json) {
  DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
  HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
  if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
    try {
      String kafkaOutboundTopic = KafkaTopics.DEVICE_TELEMETRY_TOPIC;
      Device device = ctx.getDevice();
      if (device != null && device.getId() != null) {
        // BasicToDeviceActorSessionMsg basicToDeviceActorSessionMsg = new
        // BasicToDeviceActorSessionMsg(
        // device, msg);
        JsonObject root = new JsonObject();
        JsonElement jsonElement = new JsonParser().parse(json);
        root.add("d", jsonElement);
        root.addProperty("messageId", DEFAULT_REQUEST_ID);
        log.info("msg: {}", root.toString());

        this.msgProducer.send(kafkaOutboundTopic, device.getId().toString(), root.toString());
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.OK));
      } else {
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
      }
      // process(ctx, JsonConverter.convertToTelemetry(new
      // JsonParser().parse(json)));
    } catch (IllegalStateException | JsonSyntaxException ex) {
      responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
    }
  } else {
    responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
  }
  return responseWriter;
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:35,代码来源:DeviceApiController.java

示例14: handleMessage

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Override
public void handleMessage(ReleaseMessage message, String channel) {
  logger.info("message received - channel: {}, message: {}", channel, message);

  String content = message.getMessage();
  Tracer.logEvent("Apollo.LongPoll.Messages", content);
  if (!Topics.APOLLO_RELEASE_TOPIC.equals(channel) || Strings.isNullOrEmpty(content)) {
    return;
  }
  List<String> keys = STRING_SPLITTER.splitToList(content);
  //message should be appId+cluster+namespace
  if (keys.size() != 3) {
    logger.error("message format invalid - {}", content);
    return;
  }

  ResponseEntity<ApolloConfigNotification> notification =
      new ResponseEntity<>(
          new ApolloConfigNotification(keys.get(2), message.getId()), HttpStatus.OK);

  if (!deferredResults.containsKey(content)) {
    return;
  }
  //create a new list to avoid ConcurrentModificationException
  List<DeferredResult<ResponseEntity<ApolloConfigNotification>>> results =
      Lists.newArrayList(deferredResults.get(content));
  logger.debug("Notify {} clients for key {}", results.size(), content);

  for (DeferredResult<ResponseEntity<ApolloConfigNotification>> result : results) {
    result.setResult(notification);
  }
  logger.debug("Notification completed");
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:34,代码来源:NotificationController.java

示例15: reply

import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
public void reply(PluginContext ctx, DeferredResult<ResponseEntity> responseWriter, FromDeviceRpcResponse response) {
  if (response.getError().isPresent()) {
    RpcError error = response.getError().get();
    switch (error) {
    case TIMEOUT:
      responseWriter.setResult(new ResponseEntity<>(HttpStatus.REQUEST_TIMEOUT));
      break;
    case NO_ACTIVE_CONNECTION:
      responseWriter.setResult(new ResponseEntity<>(HttpStatus.CONFLICT));
      break;
    default:
      responseWriter.setResult(new ResponseEntity<>(HttpStatus.REQUEST_TIMEOUT));
      break;
    }
  } else {
    if (response.getResponse().isPresent() && !StringUtils.isEmpty(response.getResponse().get())) {
      String data = response.getResponse().get();
      try {
        responseWriter.setResult(new ResponseEntity<>(jsonMapper.readTree(data), HttpStatus.OK));
      } catch (IOException e) {
        log.debug("Failed to decode device response: {}", data, e);
        responseWriter.setResult(new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE));
      }
    } else {
      responseWriter.setResult(new ResponseEntity<>(HttpStatus.OK));
    }
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:29,代码来源:RpcRestMsgHandler.java


注:本文中的org.springframework.web.context.request.async.DeferredResult.setResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。