JAC : Aspect Oriented Programming in Java - PowerPoint PPT Presentation

About This Presentation
Title:

JAC : Aspect Oriented Programming in Java

Description:

Defining an weave order when more than one aspect refers to the same join point. ... defines the advice and is completely independent of join points definition. ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 32
Provided by: csBg
Category:

less

Transcript and Presenter's Notes

Title: JAC : Aspect Oriented Programming in Java


1
JAC Aspect Oriented Programming in Java
  • An article review by
  • Yuval Nir and Limor Lahiani

2
Introduction
  • JAC Java Aspect Component
  • Cleanly deal with inter-aspect composition
  • Aspects more modular, hence more reusable

3
Main Problem in AOP
  • Inter-Aspect composition
  • How to interleave different aspects applied on
    the same join points
  • Cross-Cutting Concern
  • The problem itself can be viewed as
  • a cross-cutting concern

4
Inter-Aspect composition
  • The problem is divided into two types
  • Weave-Time issues
  • When weaving the aspects into the base cod
  • Weaving at compile/run time (AOS dependent)
  • Run-Time issues
  • When aspect is already woven
  • Execution of Join-Point intercessed by aspects
  • Most of the issues remain open

5
Weave Time Issues
  • Problems that can be detected and
  • handled on weave time.
  • Aspect Application Compatibility
  • Inter-Aspect Compatibility
  • Inter-Aspect Dependency
  • Aspect Redundancy
  • Weave-Time Ordering of Aspects

6
WI1 Aspect-Application Compatibility
  • Checking that an aspect is safe to apply on a
  • specific base code.
  • Example
  • We would like to prevent an authentication
    aspect from being woven to an application that
    already handles/implements authentication issues.

7
WI2 Inter-Aspect Compatibility
  • Checking that aspects can be woven together.
  • Example
  • When more than one aspect conflict with each
    other, such as two aspects writing to the same
    port, the system should allow only one to be
    woven.

8
WI3 Inter-Aspect Dependency
  • Aspect depending on another aspect, both aspects
    should be woven or an error should be reported.
  • Example
  • An aspect that uses super-user authorization
    might require use of a logging aspect.

9
WI4 Aspect Redundancy
  • Aspects implement the same concern in different
    ways ? weave only one.
  • Example
  • One aspect performs logging of all send
    operations, and the other on receive.
  • Internal operations will have redundant logging
    aspect.

10
WI5 Aspects Ordering
  • Defining an weave order when more than one aspect
    refers to the same join point.
  • AOS should correctly order the aspects, so that
    aspect programmers dont care about other
    aspects.
  • Example
  • Timing aspect for measuring run-time.
  • Base code run-time only ? most internal
  • Global run-time ? most external

11
Run Time Issues
  • Problems that can be detected and
  • handled on run time.
  • Intra-Aspect consistency
  • Skipping an Aspect
  • Choosing an aspect
  • Run-Time Aspect Ordering
  • Run-Time dependency

12
RI1 Intra-Aspect consistency
  • Applying one aspect can affect another aspect at
    run-time and cause inconsistency
  • Example
  • Aspects referring to the same objects and changes
    it can cause inconsistency with other aspects.

13
RI1 Intra-Aspect consistency
  • Aspect WrongOptCountingAspect
  • private int counter
  • joinpoint jp1 (class A, method m1)
  • joinpoint jp2 (class A, method m2)
  • before ( jp1) advice1
  • counter
  • before (jp2) advice2
  • counter 10

14
RI1 Intra-Aspect consistency
  • Aspect OptCountingAspect
  • private int counter
  • joinpoint jp1 (class A, method m1)
  • joinpoint jp2 (class A, method m2)
  • before ( jp1) advice1
  • if ( advice2.alreadyApplied ()) skip
  • counter
  • before (jp2) advice2
  • counter 10

15
RI2 Skipping an Aspect
  • Depending on the run-time context, we might
    choose to dynamically skip an advice.
  • Example
  • Skipping the logging aspect when the system is
    overloaded
  • Skipping authentication aspect when user is
    already authenticted

16
RI3 Choosing an Aspect
  • More than one aspect dealing with the same
    concern are woven and we would like the most
    efficient in the current context to can be
    applied.
  • Example
  • Depending on connection type (remote/local),
  • Choose an encryption aspect (algorithm).
  • Choose an Image compression algorithm.

17
RI4 Run-Time Aspect Ordering
  • Defining an aspect order when more than one
    aspect refers to the same join point, depending
    on the context.
  • Example
  • Logging/tracing aspect
  • Verbose mode traces only successful auths.
  • apply auth. aspect before the logging aspect
  • Very verbose mode trace all the logging tries
  • apply auth. aspect after the logging aspect

18
RI5 Run-Time Dependency
  • Aspects depending on each other on run time.
  • Example
  • When skipping an aspect, all the other aspects
    depending on it, must be skipped also.

19
Possible AOS designs
  • Aspects with cross-cutting composition and
    optimization rules. Hardly re-usable, Hardly
    maintainable .
  • Application dependent aspects.
  • Simple weaver

Aspect
Aspect
Aspect
Weaver
20
Possible AOS designs
  • Simple aspects with no composition and
    optimization rules.
  • Complex weaver.
  • Application dependent weaver. Not reusable.

Aspect
Aspect
Aspect
Weaver
21
The JAC Design
  • Simple aspects without composition rules
  • Simple weaver
  • Composition aspect defines composition rules
    and optimizations

Aspect
Aspect
Aspect
Weaver
Composition Aspect
22
The JAC Framework
  • JAC is composed of four main parts
  • The base program
  • The aspects wrapper classes
  • Weaver
  • Composition aspect
  • Another part of the JAC system is the property
    file
  • The JAC framework is entirely written in Java, no
    addition to the language.

23
The Base Program
  • The base code is independent from the aspects.
  • Can be run without the JAC support
  • To run the JAC support only global changes are
    needed
  • Definition of Aspect Components used.
  • Property files

24
The Aspects- Wrapper
  • Aspects are regular classes in Java implementing
    the Wrapper interface
  • An aspect defines the advice and is completely
    independent of join points definition.
  • Kinds of aspect methods
  • Wrapping
  • Role extending the object interface
  • Exception handlers

25
The Weaver
  • Responsible for deploying aspect objects on the
    base objects
  • Defines point cuts
  • Linking of advice to point cuts
  • Easily re-usable
  • Can be modified at run-time
  • Creates instances of the required Wrappers and
    defines wrapping order to apply them by
    consulting the composition aspect.

26
The Composition Aspect
  • Rules for composing aspects at weave time
  • Rules for composing aspects at run time
  • Provides interface for interacting with Context
  • Adding context
  • Accessing context
  • The Weaver consults the composition aspect
    whenever a composition issue is addressed
    explicitly

27
Weaver Base Program Interaction
  • The weaver is notified when a new instance of a
    base class is created, so that the aspects can
    be added/removed at run time
  • Weaver notifies the base program (application)
    which advice to should be applied.

28
Base Program Aspect Interaction
  • Transformation of base objects to JAC objects at
    Class Load Time
  • Can use property file to specify which objects
    are transformed.
  • JAC Objects contain manipulating capabilities on
    aspect methods
  • Contain Context access/modify operations

29
(No Transcript)
30
Conclusions
  • Base program in regular Java
  • Aspect programming doesnt require additional
    syntax
  • Base program independent from aspects
  • Base code and aspects are compiled separately
  • Simplifies programming of weaver
  • Modular and reusable aspect and weaver code
  • Real implementation of JAC has completely
    different framework.

31
JAC implementation
  • Aspect Component
  • Creates wrapper instances and applies their
    methods if needed
  • Wrappers
  • Defines aspect code Role / Wrapper / Exceptions
  • Base Program
  • Notifies Aspect Component of every instance that
    is created and every instance method that is
    called.
  • Configuration File
  • clean addition of aspect components and objects
    that need to be checked for use
  • Can be done at run time with code instead of
    conf. file
Write a Comment
User Comments (0)
About PowerShow.com