当前位置: 首页 > news >正文

个人网站可以做音乐吗市场调研公司收费标准

个人网站可以做音乐吗,市场调研公司收费标准,关于文案的网站,个性婚纱摄影文章目录 1. 利用 ThreadLocal 缓存 AssetBranchCache 数据1. 定义 AssetBranchCache 类2. 定义 BranchContext 类操作 AssetBranchCache 对象3. 配置拦截器实时更新和清除缓存数据4. 定义 SaasThreadContextDataHolderBranch 类持有 AssetBranchCache 对象5. 定义 SaasThreadC… 文章目录 1. 利用 ThreadLocal 缓存 AssetBranchCache 数据1. 定义 AssetBranchCache 类2. 定义 BranchContext 类操作 AssetBranchCache 对象3. 配置拦截器实时更新和清除缓存数据4. 定义 SaasThreadContextDataHolderBranch 类持有 AssetBranchCache 对象5. 定义 SaasThreadContextHolder 接口6. 定义 SaasThreadContextHolderBranch 组件7. 定义 SaasThreadContextUtil 工具类8. 定义 BranchNameCache 组件获取 AssetBranchCache 数据 2. 业务使用1. 请求入口 IncidentController1. 请求参数的封装2. 响应实体的封装 2. 获取延迟加载数据 IEventDelayLoadService 业务逻辑安全事件安全告警风险主机列表页面会需要一些延迟加载数据因此当我们进入这个页面时就会请求该接口获取延迟加载数据。 1. 利用 ThreadLocal 缓存 AssetBranchCache 数据 ThreadLocal 是 Java 中的一个类它提供了一种线程局部变量的机制。线程局部变量是指只能被同一个线程访问和修改的变量不同线程之间互不干扰。ThreadLocal 可以用来解决多线程并发访问共享变量的问题。 ThreadLocal可以用来实现数据缓存即在一个线程中缓存一些上下文相关的数据以便在该线程的后续操作中使用。在使用ThreadLocal实现上下文缓存时可以将需要缓存的数据存储在ThreadLocal对象中然后在需要使用这些数据的地方通过ThreadLocal对象获取数据。由于每个线程都有自己的ThreadLocal对象因此不同线程之间的数据不会相互干扰从而保证了线程安全性。 1. 定义 AssetBranchCache 类 Data NoArgsConstructor AllArgsConstructor public class AssetBranchCache {private UnmodifiableMapInteger, String idToNameMap; }2. 定义 BranchContext 类操作 AssetBranchCache 对象 BranchContext 类定义了一个静态的 ThreadLocal 变量 BRANCH_CACHE_THREAD_LOCAL用于存储当前线程的 AssetBranchCache 对象 public class BranchContext {private static final ThreadLocalNullable AssetBranchCache BRANCH_CACHE_THREAD_LOCAL new TransmittableThreadLocal();/*** 设置 assetBranchCache*/public static void load(Nullable AssetBranchCache assetBranchCache) {BRANCH_CACHE_THREAD_LOCAL.set(assetBranchCache);}/*** 获取 assetBranchCache*/Nullablepublic static AssetBranchCache save() {return BRANCH_CACHE_THREAD_LOCAL.get();}/*** 清除 assetBranchCache 信息*/public static void remove() {BRANCH_CACHE_THREAD_LOCAL.remove();} }3. 配置拦截器实时更新和清除缓存数据 在使用ThreadLocal时需要注意内存泄漏问题因为ThreadLocal对象是存储在每个线程的ThreadLocalMap中的如果不及时清除ThreadLocal对象可能会导致内存泄漏。 Data Configuration CustomLog public class IncidentInterceptorConfig implements WebMvcConfigurer {Overridepublic void addInterceptors( NotNull InterceptorRegistry registry) {registry.addInterceptor(new HandlerInterceptorAdapter() {// preHandle方法在请求处理前会执行Overridepublic boolean preHandle( NotNull HttpServletRequest request, NotNull HttpServletResponse response, NotNull Object handler) throws Exception {BranchContext.remove();return true;}// afterCompletion方法在请求处理后会执行Overridepublic void afterCompletion(NotNull HttpServletRequest request,NotNull HttpServletResponse response, NotNull Object handler,Nullable Exception ex) throws Exception {BranchContext.remove();}});} }该类实现WebMvcConfigurer接口用于配置拦截器。在addInterceptors方法中注册了一个HandlerInterceptorAdapter类型的拦截器该拦截器在请求处理前和请求处理后都会执行。在preHandle方法中调用了BranchContext类的remove方法用于清除ThreadLocal 缓存的数据。在afterCompletion方法中也调用了BranchContext类的remove方法确保在请求处理完成后也清除当前线程的ThreadLocal 缓存的数据。 使用拦截器可以保证ThreadLocal中缓存的数据是实时更新的每次请求进来都会清除缓存中的数据重新加载。 4. 定义 SaasThreadContextDataHolderBranch 类持有 AssetBranchCache 对象 为了在项目的各个地方获取ThreadLocal中缓存的资产组数据可以定义一个线程上下文资产组数据持有者类 SaasThreadContextDataHolderBranch public interface SaasThreadContextDataHolder {}Data AllArgsConstructor public class SaasThreadContextDataHolderBranch implements SaasThreadContextDataHolder {Nullableprivate final AssetBranchCache assetBranchCache; }5. 定义 SaasThreadContextHolder 接口 SaasThreadContextHolder 接口中定义了一些方法来管理 SaasThreadContextDataHolder 对象 public interface SaasThreadContextHolderT extends SaasThreadContextDataHolder {// 获取 SaasThreadContextDataHolder 类NotNullClassT getSaasThreadContextDataHolderClass();// 尝试加载SaasThreadContextDataHolderdefault boolean tryLoad(NotNull SaasThreadContextDataHolder holder) {if (!getSaasThreadContextDataHolderClass().isInstance(holder)) {return false;}this.load((T) holder);return true;}// 加载 SaasThreadContextDataHoldervoid load(NotNull T holder);// 存储 SaasThreadContextDataHolderNotNullT save();// 清理 SaasThreadContextDataHoldervoid remove(); }6. 定义 SaasThreadContextHolderBranch 组件 // 应用程序中自动发现和注册该组件 AutoService(SaasThreadContextHolder.class) public class SaasThreadContextHolderBranch implements SaasThreadContextHolderSaasThreadContextDataHolderBranch {NotNullOverridepublic ClassSaasThreadContextDataHolderBranch getSaasThreadContextDataHolderClass() {return SaasThreadContextDataHolderBranch.class;}// 加载 SaasThreadContextDataHolderBranch 设置 ThreadLocal 缓存数据Overridepublic void load(NotNull SaasThreadContextDataHolderBranch holder) {AssetBranchCache assetBranchCache holder.getAssetBranchCache();if (assetBranchCache ! null) {BranchContext.load(assetBranchCache);}}// 获取 ThreadLocal 缓存数据填充 SaasThreadContextDataHolderBranch NotNullOverridepublic SaasThreadContextDataHolderBranch save() {return new SaasThreadContextDataHolderBranch(BranchContext.save());}// 清除 ThreadLocal 缓存数据Overridepublic void remove() {BranchContext.remove();} }7. 定义 SaasThreadContextUtil 工具类 public class SaasThreadContextUtil {// 获取Spring容器中所有实现了SaasThreadContextHolder接口的组件NotNullstatic ListSaasThreadContextHolder? getSaasThreadContextHolders() {return (List) IterableUtils.toList(ServiceLoader.load(SaasThreadContextHolder.class));}NotNullpublic static ListSaasThreadContextDataHolder save() {ListSaasThreadContextHolder? saasThreadContextHolders getSaasThreadContextHolders();ListSaasThreadContextDataHolder saasThreadContextDataHolders new ArrayList(saasThreadContextHolders.size());for (SaasThreadContextHolder? saasThreadContextHolder : saasThreadContextHolders) {saasThreadContextDataHolders.add(saasThreadContextHolder.save());}return saasThreadContextDataHolders;}public static void load(NotNull ListSaasThreadContextDataHolder saasThreadContextDataHolders) {for (SaasThreadContextHolder? saasThreadContextHolder : getSaasThreadContextHolders()) {for (SaasThreadContextDataHolder saasThreadContextDataHolder : saasThreadContextDataHolders) {if (saasThreadContextHolder.tryLoad(saasThreadContextDataHolder)) {break;}}}}public static void remove() {for (SaasThreadContextHolder? saasThreadContextHolder : getSaasThreadContextHolders()) {saasThreadContextHolder.remove();}} }8. 定义 BranchNameCache 组件获取 AssetBranchCache 数据 Component CustomLog public class BranchNameCache {GetterSetter(onMethod_ Autowired)private IBranchService branchService;Setter(onMethod_ Autowired)private ApplicationContext applicationContext;// 查询缓存数据 AssetBranchCachepublic AssetBranchCache getAssetBranchCache() {// 从ThreadLocal对象中获取缓存数据如果不为null,直接返回AssetBranchCache result BranchContext.save();if (result ! null) {return result;}// 查询缓存数据BranchNameCache bean applicationContext.getBean(BranchNameCache.class);String cacheKey String.format(RedisKey.ASSET_BRANCH, Objects.requireNonNull(TenantInfoContext.getTenantInfo()).getTenantId()) CacheUtil.getCacheUserRegion();result bean.getAssetBranchInfo(cacheKey);// 将缓存数据设置到ThreadLocal对象中BranchContext.load(result);return result;}// Spring Cache 注解Cacheable(value assetBranchCache, key #cacheKey)public AssetBranchCache getAssetBranchInfo(String cacheKey) {ListBranch branches this.getBranchService().listAll();MapInteger, String idToNameMap new HashMap(branches.size());branches.forEach(branch - {idToNameMap.put(branch.getId().intValue(), branch.getName());});return new AssetBranchCache( (UnmodifiableMapInteger, String) UnmodifiableMap.unmodifiableMap(idToNameMap));}public MapInteger, String getBranchIdToNameMap() {return this.getAssetBranchCache().getIdToNameMap();} }① getAssetBranchCache方法获取 AssetBranchCache数据先从ThreadLocal对象中查询如果查询结果不为null直接返回否则调用资产服务查询最后将查询结果设置到ThreadLocal对象中。 ② Cacheable注解Spring框架的注解用于缓存方法的返回值。具体来说Cacheable注解表示该方法的返回值应该被缓存value属性指定了缓存的名称key属性指定了缓存的键值即用于查找缓存的唯一标识符。在这个例子中缓存的名称为assetBranchCache缓存的键值为cacheKeycacheKey是一个方法参数或者是一个表达式用于生成缓存的键值。如果缓存中已经存在相同的键值则直接返回缓存中的值否则执行方法并将返回值存入缓存中。 2. 业务使用 1. 请求入口 IncidentController Api(安全事件信息) CustomLog Validated ResponseResult RestController RequestMapping(/api/v1/incidents) public class IncidentController {CheckValidateAblePreAuthorize(hasAnyAuthority(superAdmin,incidentQuery))PostMapping(/delayloaddata)ApiOperation(安全事件额外数据延迟加载)OperateLog(handle { LoggerEnum.operation }, target operate.incident.log, action operate.incident.delayloaddata.log)public IncidentDelayLoadData delayLoadData(RequestBody Validated IncidentDelayLoadDataQo qo) {MapString, IncidentDelayLoadData.EachIncidentDelayLoadData incidentMap delayLoadService.richInfo(qo);return IncidentDelayLoadData.builder().incidentMap(incidentMap).build();} }1. 请求参数的封装 Data Validated Builder ApiModel(description 事件延迟加载数据) NoArgsConstructor AllArgsConstructor public class IncidentDelayLoadDataQo {ApiModelProperty(value 数据类型, example INCIDENT)RiskTypeEnum riskType RiskTypeEnum.INCIDENT;ValidSize(max 1000, message 延迟加载的数据最大1000条)NotNullprivate ListSecurityEntry data; }① 风险类型安全事件安全告警风险资产 public enum RiskTypeEnum {/*** 安全事件*/INCIDENT,/*** 安全告警*/ALERT,MOCK,/*** 风险资产*/RISK_ASSET; }② 事件延迟加载数据 Data Builder ApiModel(description 事件延迟加载数据) NoArgsConstructor AllArgsConstructor public class SecurityEntry {// 安全事件id、安全告警id、风险主机idNotBlankPattern(regexp [^\()%\\\\])private String uuId;Nullableprivate Long assetId;Nullableprivate Long lastTime;Nullableprivate ListNotBlank Pattern(regexp [^\()%\\\\]) String alertIds;}Nullable 注解是一种用于 Java 代码中的注解它用于标记一个方法的返回值、参数或字段可以为 null。 ③ 请求参数示例 {data: [{uuId: alert-ad41da97-94b2-4091-9a6d-a6972a7ce919,assetId: 17582,lastTime: 1690460941},{uuId: alert-a6a2d31f-34df-4176-bca5-1ee368e41006,assetId: 17581,lastTime: 1690460896}],riskType: ALERT }2. 响应实体的封装 Data Builder ApiModel(description 事件延迟加载数据) NoArgsConstructor AllArgsConstructor public class IncidentDelayLoadData {ApiModelProperty(事件延迟加载数据)private MapString, EachIncidentDelayLoadData incidentMap;DataBuilderApiModel(description 每条事件的延迟加载数据)NoArgsConstructorAllArgsConstructorpublic static class EachIncidentDelayLoadData {ApiModelProperty(一键遏制禁用标记)private Boolean oneClickDisposeDisabled;private String oneClickDisposeStatus;private String newestUsername;private String checkOutUsername;private String responsible;private AlertSeverityNumber alertSeverityNumber;private Long remarkNumber;private Integer connectStatus;ApiModelProperty(当前资产类别信息)private MagnitudeInfo magnitude;ApiModelProperty(处置入口威胁根除判断)private TableCellDataVo entryDisposal;ApiModelProperty(主机IP)private HostIpDelayVo hostIp;ApiModelProperty(主机资产组)private HostBranchDelayVo hostBranchId;ApiModelProperty(主机业务组)private HostGroupDelayVo hostGroupIds;ApiModelProperty(目的IP)private SrcDstIpDelayVo dstIp;ApiModelProperty(源IP)private SrcDstIpDelayVo srcIp;ApiModelProperty(源IP)private AssetUserDelayVo assetUser;} }① 外部类 IncidentDelayLoadData包含一个名为incidentMap的Map对象其中键为事件ID值为EachIncidentDelayLoadData对象表示每个事件的延迟加载数据。 Data Builder ApiModel(description 事件延迟加载数据) NoArgsConstructor AllArgsConstructor public class IncidentDelayLoadData {ApiModelProperty(事件延迟加载数据)private MapString, EachIncidentDelayLoadData incidentMap;// .... }② 静态内部类 EachIncidentDelayLoadData包含了事件的各种属性如一键遏制禁用标记、最新用户名、检出用户名、责任人、告警严重性等等。其中MagnitudeInfo、TableCellDataVo、HostIpDelayVo、HostBranchDelayVo、HostGroupDelayVo、SrcDstIpDelayVo和AssetUserDelayVo都是其他自定义类的对象用于表示不同的属性。 ③ 静态内部类的使用 Java中的静态内部类是指在一个类的内部定义的静态类。静态内部类与非静态内部类的区别在于静态内部类不依赖于外部类的实例可以直接通过外部类名访问而非静态内部类必须依赖于外部类的实例才能访问。 静态内部类可以访问外部类的静态成员和方法但不能访问外部类的非静态成员和方法。静态内部类也可以定义静态成员和方法这些静态成员和方法与外部类的静态成员和方法类似可以直接通过类名访问。 public class OuterClass {// 外部类的成员和方法public static class StaticInnerClass {// 静态内部类的成员和方法} }静态内部类的实例化方式如下 OuterClass.StaticInnerClass inner new OuterClass.StaticInnerClass();④ 响应数据示例 {strCode: null,message: 成功,data: {incidentMap: {lqlapp35test3-452799db-2557-424b-ba86-aa1f2d72eb3e: {oneClickDisposeDisabled: true,oneClickDisposeStatus: WAIT_DEAL,newestUsername: null,checkOutUsername: null,responsible: null,alertSeverityNumber: null,remarkNumber: 0,connectStatus: null,magnitude: null,entryDisposal: {originalValue: true,renderValue: null},hostIp: {originalValue: 6.6.6.7,renderValue: 6.6.6.7(美国)},hostBranchId: {originalValue: 0,renderValue: },hostGroupIds: {count: 0,data: []},dstIp: null,srcIp: null,assetUser: null},16c28c0d-649a-dispose-entity111-5d419e8790129: {oneClickDisposeDisabled: false,oneClickDisposeStatus: WAIT_DEAL,newestUsername: null,checkOutUsername: null,responsible: null,alertSeverityNumber: null,remarkNumber: 0,connectStatus: null,magnitude: null,entryDisposal: {originalValue: true,renderValue: null},hostIp: {originalValue: 192.168.40.29,renderValue: 192.168.40.29(管理IP范围)},hostBranchId: {originalValue: 1,renderValue: },hostGroupIds: {count: 0,data: []},dstIp: null,srcIp: null,assetUser: null}}},code: 0 }2. 获取延迟加载数据 IEventDelayLoadService 利用线程池管理并发任务的执行。通过将任务提交到线程池中让线程池自动分配线程来执行任务从而实现并发执行。线程池还可以控制并发任务的数量避免系统资源被过度占用从而提高系统的稳定性和可靠性。 CustomLog Service public class EventDelayLoadServiceImpl implements IEventDelayLoadService, ApplicationListenerContextStoppedEvent {// 定义一个线程池private static final ThreadPoolExecutor THREAD_POOL_EXECUTOR new ThreadPoolExecutor(5,20,4,TimeUnit.SECONDS,new LinkedBlockingQueue(),new ThreadFactoryBuilder().setNameFormat(IncidentResponseDispositionServiceImpl.class.getSimpleName() -pool-%d).setDaemon(true).build(),new ThreadPoolExecutor.DiscardOldestPolicy());// 监听应用程序上下文停止事件,用于关闭线程资源Overridepublic void onApplicationEvent(NotNull ContextStoppedEvent ignored) {try {THREAD_POOL_EXECUTOR.shutdown();} catch (Exception e) {log.error(停止线程池失败, e);}}Overridepublic MapString, IncidentDelayLoadData.EachIncidentDelayLoadData richInfo(IncidentDelayLoadDataQo delayLoadDataQo) {ListSecurityEntry securityEntryList delayLoadDataQo.getData();if (CollectionUtils.isEmpty(securityEntryList)) {return Collections.emptyMap();}RiskTypeEnum riskType delayLoadDataQo.getRiskType();ConcurrentHashMapString, IncidentDelayLoadData.EachIncidentDelayLoadData data new ConcurrentHashMap(securityEntryList.size());securityEntryList.forEach(entry - data.put(entry.getUuId(), new IncidentDelayLoadData.EachIncidentDelayLoadData()));ListCallableVoid callables;// 根据riskType的不同调用不同的方法获取Callable列表callablesswitch (riskType) {case INCIDENT:callables getIncidentCallableList(securityEntryList, data);break; case ALERT:callables getAlertCallableList(securityEntryList, data);break; case RISK_ASSET:callables getRiskAssetCallableList(securityEntryList, data);break;default:return Collections.emptyMap();}// 通过线程池执行callables中的任务并将结果存储在ConcurrentHashMap类型的数据data中try {ListFutureVoid futures THREAD_POOL_EXECUTOR.invokeAll(callables, 1, TimeUnit.MINUTES);for (FutureVoid future : futures) {try {future.get();} catch (Exception e) {log.warn(incident delay data,future get warn, e);}}} catch (Exception e) {log.warn(incident delay data warn , e);}return data;} }以获取安全告警页面延迟加载数据的线程执行任务为例getAlertCallableList private ListCallableVoid getAlertCallableList(ListSecurityEntry securityEntryList, ConcurrentHashMapString, IncidentDelayLoadData.EachIncidentDelayLoadData data) {HashMapNotNull String, Nullable Long uuIdToAssetId new HashMap(securityEntryList.size());for (SecurityEntry securityEntry : securityEntryList) {uuIdToAssetId.put(securityEntry.getUuId(), securityEntry.getAssetId());}try {ListAlert alerts alertDao.getAlerts(securityEntryList.stream().map(SecurityEntry::getUuId).collect(Collectors.toList()));if (CollectionUtils.isEmpty(alerts)) {log.warn(no alert data to deal);data.clear();return List.of();}// 尝试加载ThreadLocal对象中的缓存数据ListSaasThreadContextDataHolder contextDataHolders SaasThreadContextUtil.save();CallableVoid assetCallable getAssetCallable(securityEntryList, data, uuIdToAssetId, contextDataHolders);CallableVoid assetUserCallable getAssetUserCallable(securityEntryList, data, uuIdToAssetId, contextDataHolders);CallableVoid assetBranchCallable getAlertAssetBranchCallable(securityEntryList, alerts, data, contextDataHolders);CallableVoid remarkNumberCallable getRemarkNumberCallable(securityEntryList, ALERT, data, contextDataHolders);return Arrays.asList(assetCallable,assetUserCallable,assetBranchCallable,remarkNumberCallable);} catch (IOException | JsonSerializeException e) {throw new IncidentRuntimeException(I18nUtils.i18n(I18nConstant.AlertOperateConstant.EXCEPTION_TO_BE_TRANSFERRED), e);} }在该方法中定义了一个获取安全告警资产组信息线程体继续看下 getAlertAssetBranchCallable 方法 CustomLog Service public class EventDelayLoadServiceImpl implements IEventDelayLoadService, ApplicationListenerContextStoppedEvent {Setter(onMethod_ { Autowired })private BranchNameCache branchNameCache; private CallableVoid getAssetBranchCallable(ListSecurityEntry securityEntryList, ListIncident incidentList, ConcurrentHashMapString, IncidentDelayLoadData.EachIncidentDelayLoadData data,ListSaasThreadContextDataHolder contextDataHolders) {return () - {try {// 设置ThreadLocal对象中的缓存数据SaasThreadContextUtil.load(contextDataHolders);// BranchNameCache 获取 AssetBranchCache 数据MapInteger, String branchIdToNameMap branchNameCache.getBranchIdToNameMap();for (SecurityEntry securityEntry : securityEntryList) {//设置响应数据eachIncidentDelayLoadData.setHostBranchId(new HostBranchDelayVo(branchId, HostIpUtils.getHostBranch(assetId, branchId, branchIdToFullNameMap)));}return null;} finally {// 清除ThreadLocal对象中的缓存数据SaasThreadContextUtil.remove();}};} }
http://www.w-s-a.com/news/858287/

相关文章:

  • 宁波品牌网站推广优化公司开发公司工程部工作总结
  • 长沙建站模板微信网站建设方案
  • 不让网站在手机怎么做门户网站 模板之家
  • 网站建设及推广图片wordpress文章摘要调用
  • 手机版网站案例全国信息企业公示系统
  • 模仿别人网站建设银行广州招聘网站
  • 沧州网站建设沧州内页优化
  • 代加工网站有哪些专门做网站关键词排名
  • 郑州做景区网站建设公司软件开发者模式怎么打开
  • 长沙企业网站建设哪家好做app一般多少钱
  • 南宁一站网网络技术有限公司网站开发技术应用领域
  • 公司网站建设方案ppt专业构建网站的公司
  • 深圳网站建设方维网络网站框架设计好后怎么做
  • 合肥网站建设过程网站栏目建设调研
  • 手机访问网站页面丢失北京电商平台网站建设
  • 郑州网站怎么推广中山 网站关键词优化
  • 国外试用网站空间网站建设与管理题目
  • 淄博网赢网站建设网站设计的技术选择
  • 建外贸网站 东莞厦门做网站最好的公司
  • 为您服务网站新网站做百度推广
  • 电子商务免费网站建设网站制作哪个好薇
  • 全面启动门户网站建设中小型企业建设一个网站大概需要多少钱
  • 建网站一般多少钱网站建设上传服务器步骤
  • 手机销售网站怎么做的网站推广优化建设方案
  • 做任务分享赚钱的网站德阳网站建设公司哪家好
  • 云南建设工程质量监督网站wordpress网站导航主题
  • 徐州网站建设哪家好薇手机开源网站代码
  • 更新网站要怎么做呢泰安市58同城招聘网
  • 溧阳网站建设价格企业网站设计费用
  • 我建设的网站打开很慢河北住房和城乡建设厅网站卡