In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Background
When a broker creates a client, it needs to add war report information to the corresponding broker. At the code level, the related classes of the guest source only operate on the guest source data table. The war report information contains a variety of business statistics, and the tourist source is only part of the statistics. In view of the fact that the two are relatively independent, and the war report information of the tourist source will be modified. Therefore, the code is built in AOP+ Observer mode.
Code
Define an annotation for AOP interception.
/ * Retention (RetentionPolicy.RUNTIME) @ Target ({ElementType.METHOD, ElementType.PARAMETER}) @ Documentedpublic @ interface AchievementAnnotation {OperateEnum operate () default OperateEnum.ADD; enum OperateEnum {ADD,UPDATE,DELETE}}
Define AOP, where the user acquires the data and forwards it to the observer
/ * * War report AOP * / @ Aspect@Componentpublic class AchievementAop {/ * War report Observer list * / private List observerList; public AchievementAop () {this.observerList = new ArrayList ();} public List getObserverList () {return observerList;} public void setObserverList (List observerList) {if (null! = this.observerList) this.observerList.addAll (observerList) This.observerList = observerList;} / * Observer injected into the guest source * / @ Autowired public void setCustomerAchievementObserver (CustomerAchievementObserver customerAchievementObserver) {getObserverList () .add (customerAchievementObserver) } @ Pointcut ("@ annotation (com.pretang.cloud.aop.AchievementAnnotation)") private void pointCut () {} @ AfterReturning (pointcut = "pointCut ()", returning = "retVal") public void after (JoinPoint joinPoint, Object retVal) {Signature signature = joinPoint.getSignature (); MethodSignature methodSignature = (MethodSignature) signature; Method targetMethod = methodSignature.getMethod (); AchievementAnnotation annotation = targetMethod.getAnnotation (AchievementAnnotation.class) AchievementAnnotation.OperateEnum operateEnum = annotation.operate (); for (AchievementObserver observer: observerList) {if (observer.isSupport (retVal)) observer.execute (retVal);}
Define a common interface for observers
/ * * War report Information Observer Interface * @ param * / public interface AchievementObserver {/ * whether the object is supported * @ param obj * @ return * / boolean isSupport (Object obj); / * manipulate business data * @ param t * @ throws RuntimeException * / void execute (T t) throws RuntimeException;}
Tourist source observer
/ * * Observer of guest source information * / @ Componentpublic class CustomerAchievementObserver implements AchievementObserver {@ Autowired private CustomerRpcService customerRpcService; @ Override public boolean isSupport (Object obj) {return obj instanceof CustomerBase;} @ Override public void execute (CustomerBase customerBase) throws RuntimeException {/ / actual business processing customerRpcService.saveAchievement (customerBase.getAgentUserId (), "ADD_CUSTOMER", customerBase.getId ());}}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.