Search in sources :

Example 6 with SentinelResource

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));
}
Also used : FlashActivityDTO(com.actionworks.flashsale.app.model.dto.FlashActivityDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping) SentinelResource(com.alibaba.csp.sentinel.annotation.SentinelResource)

Example 7 with SentinelResource

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();
}
Also used : SentinelResource(com.alibaba.csp.sentinel.annotation.SentinelResource) Method(java.lang.reflect.Method)

Example 8 with SentinelResource

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);
}
Also used : Person(com.xiaolyuh.entity.Person) SentinelResource(com.alibaba.csp.sentinel.annotation.SentinelResource)

Example 9 with SentinelResource

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);
}
Also used : FlashItemDTO(com.actionworks.flashsale.app.model.dto.FlashItemDTO) FlashItemsQuery(com.actionworks.flashsale.app.model.query.FlashItemsQuery) GetMapping(org.springframework.web.bind.annotation.GetMapping) SentinelResource(com.alibaba.csp.sentinel.annotation.SentinelResource)

Example 10 with SentinelResource

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());
}
Also used : FlashActivityDTO(com.actionworks.flashsale.app.model.dto.FlashActivityDTO) FlashActivitiesQuery(com.actionworks.flashsale.app.model.query.FlashActivitiesQuery) GetMapping(org.springframework.web.bind.annotation.GetMapping) SentinelResource(com.alibaba.csp.sentinel.annotation.SentinelResource)

Aggregations

SentinelResource (com.alibaba.csp.sentinel.annotation.SentinelResource)11 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 FlashActivityDTO (com.actionworks.flashsale.app.model.dto.FlashActivityDTO)3 Method (java.lang.reflect.Method)3 FlashItemDTO (com.actionworks.flashsale.app.model.dto.FlashItemDTO)2 FlashActivitiesQuery (com.actionworks.flashsale.app.model.query.FlashActivitiesQuery)2 FlashItemsQuery (com.actionworks.flashsale.app.model.query.FlashItemsQuery)2 Entry (com.alibaba.csp.sentinel.Entry)2 EntryType (com.alibaba.csp.sentinel.EntryType)2 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)2 FlashPlaceOrderCommand (com.actionworks.flashsale.app.model.command.FlashPlaceOrderCommand)1 PlaceOrderResult (com.actionworks.flashsale.app.model.result.PlaceOrderResult)1 Person (com.xiaolyuh.entity.Person)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 Around (org.aspectj.lang.annotation.Around)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1