use of com.alibaba.csp.sentinel.annotation.SentinelResource in project flash-sale by ThoughtsBeta.
the class FlashActivityController method getFlashActivity.
@GetMapping(value = "/flash-activities/{activityId}")
@SentinelResource("GetActivityResource")
public SingleResponse<FlashActivityResponse> getFlashActivity(@RequestAttribute Long userId, @PathVariable Long activityId, @RequestParam(required = false) Long version) {
AppSimpleResult<FlashActivityDTO> flashActivityResult = flashActivityAppService.getFlashActivity(userId, activityId, version);
if (!flashActivityResult.isSuccess() || flashActivityResult.getData() == null) {
return ResponseBuilder.withSingle(flashActivityResult);
}
FlashActivityDTO flashActivityDTO = flashActivityResult.getData();
return SingleResponse.of(toFlashActivityResponse(flashActivityDTO));
}
use of com.alibaba.csp.sentinel.annotation.SentinelResource in project Sentinel by alibaba.
the class AbstractSentinelAspectSupport method extractDefaultFallbackMethod.
private Method extractDefaultFallbackMethod(ProceedingJoinPoint pjp, String defaultFallback, Class<?>[] locationClass) {
if (StringUtil.isBlank(defaultFallback)) {
SentinelResource annotationClass = pjp.getTarget().getClass().getAnnotation(SentinelResource.class);
if (annotationClass != null && StringUtil.isNotBlank(annotationClass.defaultFallback())) {
defaultFallback = annotationClass.defaultFallback();
if (locationClass == null || locationClass.length < 1) {
locationClass = annotationClass.fallbackClass();
}
} else {
return null;
}
}
boolean mustStatic = locationClass != null && locationClass.length >= 1;
Class<?> clazz = mustStatic ? locationClass[0] : pjp.getTarget().getClass();
MethodWrapper m = ResourceMetadataRegistry.lookupDefaultFallback(clazz, defaultFallback);
if (m == null) {
// First time, resolve the default fallback.
Class<?> originReturnType = resolveMethod(pjp).getReturnType();
// Default fallback allows two kinds of parameter list.
// One is empty parameter list.
Class<?>[] defaultParamTypes = new Class<?>[0];
// The other is a single parameter {@link Throwable} to get relevant exception info.
Class<?>[] paramTypeWithException = new Class<?>[] { Throwable.class };
// We first find the default fallback with empty parameter list.
Method method = findMethod(mustStatic, clazz, defaultFallback, originReturnType, defaultParamTypes);
// If default fallback with empty params is absent, we then try to find the other one.
if (method == null) {
method = findMethod(mustStatic, clazz, defaultFallback, originReturnType, paramTypeWithException);
}
// Cache the method instance.
ResourceMetadataRegistry.updateDefaultFallbackFor(clazz, defaultFallback, method);
return method;
}
if (!m.isPresent()) {
return null;
}
return m.getMethod();
}
use of com.alibaba.csp.sentinel.annotation.SentinelResource in project spring-boot-student by wyh-spring-ecosystem-student.
the class PersonServiceImpl method semaphore.
@Override
@SentinelResource(entryType = EntryType.IN)
public Result semaphore(String arg) {
Person person = new Person();
person.setAge(18);
person.setId(2L);
person.setName("名称semaphore");
person.setAddress("地址semaphore");
logger.info(JSON.toJSONString(person));
return Result.success(person);
}
use of com.alibaba.csp.sentinel.annotation.SentinelResource in project flash-sale by ThoughtsBeta.
the class FlashItemController method getFlashItems.
@GetMapping(value = "/activities/{activityId}/flash-items")
@SentinelResource("GetFlashItems")
public MultiResponse<FlashItemDTO> getFlashItems(@RequestAttribute Long userId, @PathVariable Long activityId, @RequestParam Integer pageSize, @RequestParam Integer pageNumber, @RequestParam(required = false) String keyword) {
FlashItemsQuery flashItemsQuery = new FlashItemsQuery().setKeyword(keyword).setPageSize(pageSize).setPageNumber(pageNumber);
AppMultiResult<FlashItemDTO> flashItemsResult = flashItemAppService.getFlashItems(userId, activityId, flashItemsQuery);
return ResponseBuilder.withMulti(flashItemsResult);
}
use of com.alibaba.csp.sentinel.annotation.SentinelResource in project flash-sale by ThoughtsBeta.
the class FlashActivityController method getOnlineFlashActivities.
@GetMapping(value = "/flash-activities/online")
@SentinelResource("GetOnlineActivitiesResource")
public MultiResponse<FlashActivityResponse> getOnlineFlashActivities(@RequestAttribute Long userId, @RequestParam Integer pageSize, @RequestParam Integer pageNumber, @RequestParam(required = false) String keyword) {
FlashActivitiesQuery flashActivitiesQuery = new FlashActivitiesQuery().setKeyword(keyword).setPageSize(pageSize).setPageNumber(pageNumber).setStatus(FlashActivityStatus.ONLINE.getCode());
AppMultiResult<FlashActivityDTO> flashActivitiesResult = flashActivityAppService.getFlashActivities(userId, flashActivitiesQuery);
if (!flashActivitiesResult.isSuccess() || flashActivitiesResult.getData() == null) {
return ResponseBuilder.withMulti(flashActivitiesResult);
}
return MultiResponse.of(toFlashActivitiesResponse(flashActivitiesResult.getData()), flashActivitiesResult.getTotal());
}
Aggregations