private String buildRepositorySuffix(final String repositorySuffix) { if (StringUtils.isNoneBlank(repositorySuffix)) { return repositorySuffix; } else { return hmilyApplicationService.acquireName(); } }
private String buildRepositorySuffix(final String repositorySuffix) { if (StringUtils.isNoneBlank(repositorySuffix)) { return repositorySuffix; } else { return mythApplicationService.acquireName(); } }
/** * 获取EagleEyeId * * @param loader 目标ClassLoader * @return EagleEyeId */ public static String getTraceId(final ClassLoader loader) { if (!GlobalOptions.isEnableTraceId) { return ILLEGAL_EAGLE_EYE_TRACE_ID; } final Thread currentThread = Thread.currentThread(); final ClassLoader contextClassLoader = currentThread.getContextClassLoader(); currentThread.setContextClassLoader(loader); try { final Class<?> classOfEagleEye = loader.loadClass(EAGLE_EYE_CLASS_NAME); final Method methodOfGetTraceId = classOfEagleEye.getMethod(GET_TRACE_ID_NAME); final Object returnOfGetTraceId = methodOfGetTraceId.invoke(null); if (null != returnOfGetTraceId && returnOfGetTraceId instanceof String && StringUtils.isNoneBlank((String) returnOfGetTraceId)) { return (String) returnOfGetTraceId; } else { return ILLEGAL_EAGLE_EYE_TRACE_ID; } } catch (Throwable t) { return ILLEGAL_EAGLE_EYE_TRACE_ID; } finally { currentThread.setContextClassLoader(contextClassLoader); } }
public GoogleClosureJavascriptMinificationServiceImpl(@Value("${minify.closure.compiler.languageIn:ECMASCRIPT5}") String compilerLanguageIn, @Value("${minify.closure.compiler.languageOut:NO_TRANSPILE}") String compilerLanguageOut) { this.languageIn = null; this.languageOut = null; if (StringUtils.isNotBlank(compilerLanguageIn)) { this.languageIn = CompilerOptions.LanguageMode.valueOf(compilerLanguageIn); this.languageOut = this.languageIn; } if (StringUtils.isNoneBlank(compilerLanguageOut)) { this.languageOut = CompilerOptions.LanguageMode.valueOf(compilerLanguageOut); if (this.languageIn == null) { this.languageIn = this.languageOut; } } if (this.languageIn == null) { throw new IllegalArgumentException("Please set properties \"minify.closure.compiler.languageIn\" or \"minify.closure.compiler.languageOut\" if you wish to use Google Closure Compiler for Javascript minification"); } }
@Test public void testIsNoneBlank() { assertFalse(StringUtils.isNoneBlank((String) null)); assertTrue(StringUtils.isNoneBlank((String[]) null)); assertFalse(StringUtils.isNoneBlank(null, "foo")); assertFalse(StringUtils.isNoneBlank(null, null)); assertFalse(StringUtils.isNoneBlank("", "bar")); assertFalse(StringUtils.isNoneBlank("bob", "")); assertFalse(StringUtils.isNoneBlank(" bob ", null)); assertFalse(StringUtils.isNoneBlank(" ", "bar")); assertTrue(StringUtils.isNoneBlank("foo", "bar")); }
@Override public Class factoryOf(final TxTransactionInfo info) { if (StringUtils.isNoneBlank(info.getCompensationId())) { return StartCompensationHandler.class; } if (StringUtils.isBlank(info.getTxGroupId())) { return StartTxTransactionHandler.class; } else { if (Objects.equals(CommonConstant.COMPENSATE_ID, info.getTxGroupId())) { return InsideCompensationHandler.class; } return ActorTxTransactionHandler.class; } } }
private MythTransaction buildMythTransaction(final ProceedingJoinPoint point, final int role, final int status, final String transId) { MythTransaction mythTransaction; if (StringUtils.isNoneBlank(transId)) { mythTransaction = new MythTransaction(transId); } else { mythTransaction = new MythTransaction(); } MethodSignature signature = (MethodSignature) point.getSignature(); Method method = signature.getMethod(); Class<?> clazz = point.getTarget().getClass(); mythTransaction.setStatus(status); mythTransaction.setRole(role); mythTransaction.setTargetClass(clazz.getName()); mythTransaction.setTargetMethod(method.getName()); return mythTransaction; }
@Override public Object handler(final ProceedingJoinPoint point, final HmilyTransactionContext context) throws Throwable { if (HmilyActionEnum.TRYING.getCode() == context.getAction()) { MethodSignature signature = (MethodSignature) point.getSignature(); Method method = signature.getMethod(); Class<?> clazz = point.getTarget().getClass(); Object[] args = point.getArgs(); final Hmily hmily = method.getAnnotation(Hmily.class); HmilyInvocation confirmInvocation = null; String confirmMethodName = hmily.confirmMethod(); String cancelMethodName = hmily.cancelMethod(); if (StringUtils.isNoneBlank(confirmMethodName)) { confirmInvocation = new HmilyInvocation(clazz, confirmMethodName, method.getParameterTypes(), args); } HmilyInvocation cancelInvocation = null; if (StringUtils.isNoneBlank(cancelMethodName)) { cancelInvocation = new HmilyInvocation(clazz, cancelMethodName, method.getParameterTypes(), args); } final HmilyParticipant hmilyParticipant = new HmilyParticipant(context.getTransId(), confirmInvocation, cancelInvocation); hmilyTransactionExecutor.registerByNested(context.getTransId(), hmilyParticipant); } return point.proceed(); }
@Override public CommonPager<HmilyCompensationVO> listByPage(final CompensationQuery query) { final String tableName = RepositoryPathUtils.buildDbTableName(query.getApplicationName()); final PageParameter pageParameter = query.getPageParameter(); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.append("select trans_id,target_class,target_method,confirm_method,cancel_method," + " retried_count,create_time,last_time,version from ") .append(tableName).append(" where 1= 1 "); if (StringUtils.isNoneBlank(query.getTransId())) { sqlBuilder.append(" and trans_id = ").append(query.getTransId()); } if (Objects.nonNull(query.getRetry())) { sqlBuilder.append(" and retried_count < ").append(query.getRetry()); } final String sql = buildPageSql(sqlBuilder.toString(), pageParameter); CommonPager<HmilyCompensationVO> pager = new CommonPager<>(); final List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql); if (CollectionUtils.isNotEmpty(mapList)) { pager.setDataList(mapList.stream().map(this::buildByMap).collect(Collectors.toList())); } final Integer totalCount = jdbcTemplate.queryForObject(String.format("select count(1) from %s", tableName), Integer.class); if (Objects.nonNull(totalCount)) { pager.setPage(PageHelper.buildPage(pageParameter, totalCount)); } return pager; }
@Override public CommonPager<LogVO> listByPage(final ConditionQuery query) { final String tableName = RepositoryPathUtils.buildDbTableName(query.getApplicationName()); final PageParameter pageParameter = query.getPageParameter(); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.append("select trans_id,target_class,target_method," + " retried_count,create_time,last_time,version,error_msg from ") .append(tableName).append(" where 1= 1 "); if (StringUtils.isNoneBlank(query.getTransId())) { sqlBuilder.append(" and trans_id = ").append(query.getTransId()); } final String sql = buildPageSql(sqlBuilder.toString(), pageParameter); CommonPager<LogVO> pager = new CommonPager<>(); final List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql); if (CollectionUtils.isNotEmpty(mapList)) { pager.setDataList(mapList.stream().map(this::buildByMap).collect(Collectors.toList())); } final Integer totalCount = jdbcTemplate.queryForObject(String.format("select count(1) from %s", tableName), Integer.class); pager.setPage(PageHelper.buildPage(pageParameter, totalCount)); return pager; }
@Override public CommonPager<TransactionRecoverVO> listByPage(final RecoverTransactionQuery query) { final String tableName = RepositoryPathUtils.buildDbTableName(query.getApplicationName()); final PageParameter pageParameter = query.getPageParameter(); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.append("select id,target_class,target_method," + " retried_count,create_time,last_time,version,group_id,task_id from ") .append(tableName).append(" where 1= 1 "); if (StringUtils.isNoneBlank(query.getTxGroupId())) { sqlBuilder.append(" and group_id = ").append(query.getTxGroupId()); } if (Objects.nonNull(query.getRetry())) { sqlBuilder.append(" and retried_count < ").append(query.getRetry()); } final String sql = buildPageSql(sqlBuilder.toString(), pageParameter); CommonPager<TransactionRecoverVO> pager = new CommonPager<>(); final List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql); if (CollectionUtils.isNotEmpty(mapList)) { pager.setDataList(mapList.stream() .map(this::buildByMap).collect(Collectors.toList())); } final Integer totalCount = jdbcTemplate.queryForObject(String.format("select count(1) from %s", tableName), Integer.class); pager.setPage(PageHelper.buildPage(pageParameter, totalCount)); return pager; }
@Override public void doConnect() { if (channel != null && channel.isActive()) { return; } final TxManagerServer txManagerServer = TxManagerLocator.getInstance().locator(); if (Objects.nonNull(txManagerServer) && StringUtils.isNoneBlank(txManagerServer.getHost()) && Objects.nonNull(txManagerServer.getPort())) { host = txManagerServer.getHost(); port = txManagerServer.getPort(); } ChannelFuture future = bootstrap.connect(host, port); LogUtil.info(LOGGER, ".....connect txManager-socket -> host:port:{}", () -> host + ":" + port); future.addListener((ChannelFutureListener) futureListener -> { if (futureListener.isSuccess()) { channel = futureListener.channel(); LogUtil.info(LOGGER, "Connect to server successfully!-> host:port:{}", () -> host + ":" + port); } else { LogUtil.info(LOGGER, "Failed to connect to server, try connect after 5s-> host:port:{}", () -> host + ":" + port); futureListener.channel().eventLoop().schedule(this::doConnect, 5, TimeUnit.SECONDS); } }); }
private void init() { Crawler c = clazz.getAnnotation(Crawler.class); Assert.notNull(c, StrFormatUtil.info("crawler {} lost annotation @cn.wanghaomiao.seimi.annotation.Crawler!", clazz.getName())); this.queueClass = c.queue(); this.queueInstance = context.getBean(queueClass); Assert.notNull(queueInstance, StrFormatUtil.info("can not get {} instance,please check scan path", queueClass)); memberMethods = new HashMap<>(); ReflectionUtils.doWithMethods(clazz, method -> memberMethods.put(method.getName(), method)); this.crawlerName = StringUtils.isNoneBlank(c.name()) ? c.name() : clazz.getSimpleName(); instance.setCrawlerName(this.crawlerName); resolveProxy(c.proxy()); this.useCookie = c.useCookie(); this.currentUA = instance.getUserAgent(); this.delay = c.delay(); this.useUnrepeated = c.useUnrepeated(); this.seimiHttpType = c.httpType(); this.httpTimeOut = c.httpTimeOut(); logger.info("Crawler[{}] init complete.", crawlerName); }
@Override public Object interceptor(final ProceedingJoinPoint pjp) throws Throwable { HmilyTransactionContext hmilyTransactionContext; RequestAttributes requestAttributes = null; try { requestAttributes = RequestContextHolder.currentRequestAttributes(); } catch (Throwable ex) { LogUtil.warn(LOGGER, () -> "can not acquire request info:" + ex.getLocalizedMessage()); } HttpServletRequest request = requestAttributes == null ? null : ((ServletRequestAttributes) requestAttributes).getRequest(); String context = request == null ? null : request.getHeader(CommonConstant.HMILY_TRANSACTION_CONTEXT); if (StringUtils.isNoneBlank(context)) { hmilyTransactionContext = GsonUtils.getInstance().fromJson(context, HmilyTransactionContext.class); } else { hmilyTransactionContext = HmilyTransactionContextLocal.getInstance().get(); if (Objects.nonNull(hmilyTransactionContext)) { hmilyTransactionContext.setRole(HmilyRoleEnum.SPRING_CLOUD.getCode()); } } return hmilyTransactionAspectService.invoke(hmilyTransactionContext, pjp); }
private HmilyTransaction buildHmilyTransaction(final ProceedingJoinPoint point, final int role, final String transId) { HmilyTransaction hmilyTransaction; if (StringUtils.isNoneBlank(transId)) { hmilyTransaction = new HmilyTransaction(transId); } else { String confirmMethodName = hmily.confirmMethod(); String cancelMethodName = hmily.cancelMethod(); if (StringUtils.isNoneBlank(confirmMethodName)) { hmilyTransaction.setConfirmMethod(confirmMethodName); confirmInvocation = new HmilyInvocation(clazz, confirmMethodName, method.getParameterTypes(), args); if (StringUtils.isNoneBlank(cancelMethodName)) { hmilyTransaction.setCancelMethod(cancelMethodName); cancelInvocation = new HmilyInvocation(clazz, cancelMethodName, method.getParameterTypes(), args);
@Override public Object interceptor(final ProceedingJoinPoint pjp) throws Throwable { HmilyTransactionContext hmilyTransactionContext = null; final Request request = RpcContext.getContext().getRequest(); if (Objects.nonNull(request)) { final Map<String, String> attachments = request.getAttachments(); if (attachments != null && !attachments.isEmpty()) { String context = attachments.get(CommonConstant.HMILY_TRANSACTION_CONTEXT); if (StringUtils.isNoneBlank(context)) { hmilyTransactionContext = GsonUtils.getInstance().fromJson(context, HmilyTransactionContext.class); request.getAttachments().remove(CommonConstant.HMILY_TRANSACTION_CONTEXT); } else { hmilyTransactionContext = HmilyTransactionContextLocal.getInstance().get(); } } } else { hmilyTransactionContext = HmilyTransactionContextLocal.getInstance().get(); } return hmilyTransactionAspectService.invoke(hmilyTransactionContext, pjp); } }
@Override public Object interceptor(final ProceedingJoinPoint pjp) throws Throwable { MythTransactionContext mythTransactionContext = TransactionContextLocal.getInstance().get(); if (Objects.nonNull(mythTransactionContext) && mythTransactionContext.getRole() == MythRoleEnum.LOCAL.getCode()) { mythTransactionContext = TransactionContextLocal.getInstance().get(); } else { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); String context = request.getHeader(CommonConstant.MYTH_TRANSACTION_CONTEXT); if (StringUtils.isNoneBlank(context)) { mythTransactionContext = GsonUtils.getInstance().fromJson(context, MythTransactionContext.class); } } return mythTransactionAspectService.invoke(mythTransactionContext, pjp); }
@Override public Object interceptor(final ProceedingJoinPoint pjp) throws Throwable { final String context = RpcContext.getContext().getAttachment(CommonConstant.HMILY_TRANSACTION_CONTEXT); HmilyTransactionContext hmilyTransactionContext; if (StringUtils.isNoneBlank(context)) { hmilyTransactionContext = GsonUtils.getInstance().fromJson(context, HmilyTransactionContext.class); RpcContext.getContext().getAttachments().remove(CommonConstant.HMILY_TRANSACTION_CONTEXT); } else { hmilyTransactionContext = HmilyTransactionContextLocal.getInstance().get(); } return hmilyTransactionAspectService.invoke(hmilyTransactionContext, pjp); } }
@Override public Object interceptor(final ProceedingJoinPoint pjp) throws Throwable { final String context = RpcContext.getContext().getAttachment(CommonConstant.MYTH_TRANSACTION_CONTEXT); MythTransactionContext mythTransactionContext; if (StringUtils.isNoneBlank(context)) { mythTransactionContext = GsonUtils.getInstance().fromJson(context, MythTransactionContext.class); } else { mythTransactionContext = TransactionContextLocal.getInstance().get(); } return mythTransactionAspectService.invoke(mythTransactionContext, pjp); } }
final int pageSize = pageParameter.getPageSize(); Query baseQuery = new Query(); if (StringUtils.isNoneBlank(query.getTransId())) { baseQuery.addCriteria(new Criteria("transId").is(query.getTransId()));