Aop@work: Using the ASPECTJ 5 test library aspect

Source: Internet
Author: User
Tags aop stack trace

Write reusable aspects that meet the needs of all types of users

Introduction: AspectJ 5 The new language and deployment features simplify the library aspect (libraries aspect), while the library ensures that general developers can master AOP. Despite their incredible ease of use, they are very difficult to write. In this part of the aop@work series , Wes Isberg a hypothetical story about a world not far from your real life, with 30 major challenges. With this story, you will learn how to use and write libraries, and how to deliver solutions for people who believe in this technology and who do not believe in it.

Help me!

A damsel in distress ran to you breathlessly: "Help!" Everything was fine during the test, but after deployment, the system suddenly stopped. No anomaly! There's nothing! No one knows what to do! World Peace is on the verge of danger! ”

You didn't ask for one more word, just open the backpack and take out two bottles, "Try this:"

Java-

javaagent:aspectjweaver.jar-classpath 

"Vmerroraspect.jar:${classpath}".

A minute later, a stack trace pops up. Someone places all the Error in the log, including OutOfMemoryError, and continues to run. Thanks to your side Rethrowvmerror!

From magic bottles to specific aspects

In fact, there is no magic in the two bottles mentioned above: only the notice in the library (advice), which is woven into the deployment when loaded. Library Aspect Rethrowvmerror will run a notification before any urgent error handlers throw an error, preventing it from hiding vmerror. AspectJ 5 has a number of new language features that can be written to simplify the library, as well as new deployment options that simplify the use of specific aspects. Together, these features and options make it easy for new users with less experience (less experience in using fault-tolerant build or deployment processes) to master aop--but only if the library aspect has to be well adjusted. As an expert in writing a library--or, at least, an author who introduces enough knowledge to readers--I would like to take this opportunity to invite dear readers to actively ask the right questions and to deploy a simple library-side solution based on appropriate answers.

Rethrowvmerror is a simple but powerful solution that is easy to understand and use. Other library aspects of capacity, understanding and tools are more comprehensive than that. What is a good library aspect? I think the successful delivery of the library stems from a tailored solution based on user needs and skills, rather than trying to provide the most powerful or reusable solution. In this article, you'll learn from a simple little story about how to start designing with an evaluation user. As a protagonist of the story, your great task is to write libraries for end users that are uneven in their levels, from simple XML deployments to Java™ and AspectJ programmers. In the course of the story, you need to train some people who want to be AOP experts and convince a manager with a distrust attitude to adopt AOP. In the final success, you will see that the key to building everyone's confidence in AOP is to go all the way through each step.

Reusable aspects of AspectJ 5

AspectJ 5 makes it easier to write reusable aspects than ever before. First, it has a new form of extensibility and authoring Pointcuts (pointcut), not only in the pure Java side that supports Java 5 language features, but also within AspectJ languages. Java 5 Annotations Enable Java developers who have never been in touch to understand or even write. At the same time, generic types have increased security and new methods for the qualification of types, especially for users of new parameterized libraries. All of these features are demonstrated in the aspects described in this article.

Second, AspectJ 5 makes authoring and deployment easier and does not require the use of AspectJ compilers. In writing, it supports writing comments about aspects as pure Java code, such as Aspectwerkz. These annotation-style aspects can be compiled by Javac and subsequently woven into using a loom. In terms of deployment, the new loaded looms support XML configuration file Meta-inf/aop.xml, allowing you to declare specific pointcuts for the abstract library aspects of a specific aspect. This is likely to be the case in the first batch of libraries, because users don't need to know everything about AspectJ, just complete the minimum XML editing required to deploy the library.

With these new methods of deploying the AspectJ Library, users need only know what is necessary to deploy their aspects. When loaded, the loom minimizes the impact of the development and build processes, and the aspect library minimizes the expertise required-but only if the library developer is able to meet the challenge, write a robust aspect, and work with the minimized specifications provided by the Deployer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.