Aom

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Aom as PDF for free.

More details

  • Words: 3,883
  • Pages: 28
Professional Open Source Source™

Aspect-Oriented Middleware Middleware Applications with Plain Old Java Objects

© JBoss JBoss,Inc., Inc. 2003-2005.

8/2/2005

1

Topics Professional Open Source™

– What is AOM/AOP? – JBoss AOP framework – Prepackaged Middleware Aspects • Dynamic Aspects • Metadata Driven Aspects

© JBoss JBoss,Inc., Inc. 2003-2005.

2

1

What is AOP? Professional Open Source™

– – – – –

Modular way of defining and applying cross-cutting concerns Functionality that is not specific to any particular class Code that looks like it has structure, but cannot be described in OOP Modular way of layering code like an onion Turning any execution point in the Java runtime into an event • Writing event handlers for these events • Providing a “query” language to specify these points

Class1

Class2

Class3

Class1

CROSS HIERARCHY

Class4

Class2

Class3

Class4

3

© JBoss JBoss,Inc., Inc. 2003-2005.

What is AOM? Professional Open Source™

Aspect Orientation addresses the notion of an assembly at or below the component level – Assembly exists at different levels in all software systems 1. Integration Level 2. Component Level 3. Class Level

1) Assembly at integration level is traditionally addressed by using protocols and interfaces (MOM, ESB, JBI, etc.)

© JBoss JBoss,Inc., Inc. 2003-2005.

4

2

2. Component Level in AOM Professional Open Source™

2) Today component level is addressed by fixed container contracts – – – –

EJB, servlet, etc. component models Provide a fixed set of services (remoteness, security, transactions) Assembly between container components (J2EE Assembler role definition) Fixed contract is ”one-size-for-all” model – evidence shows that there is no one size that fits for all purposes

AOM formalizes the assembly of the container services – Can be a predefined fixed contract, such as EJB container – Can be customized for a plain old Java object (POJO) using advices developed in-house or by 3rd party (will define what is an advice in following slides) – Can be dynamic and changed based on run-time requirements – This is ”custom-size-for-all” model -- allows you to implement a container contract using a proven framework and known practices for your needs – System level aspects

5

© JBoss JBoss,Inc., Inc. 2003-2005.

3. Class Level Professional Open Source™

3) Assemble class level functionality declaratively rather than statically at compile time – Inheritance or delegation are fixed at compile time – Aspect assembly can be declared and modified without compilation – Track class field usage (design by contract), constructor usage (count or restrict number of instances in the virtual machine), etc. – Move repetitive code outside of the business code implementation (traditionally done by inheritance or delegation but cannot be changed after compiled). For example, tracing, metrics, etc. – Application level aspects

© JBoss JBoss,Inc., Inc. 2003-2005.

6

3

Cross-cutting Concern Professional Open Source™

public publicclass classBankAccount BankAccount { { public publicvoid voidwithdraw(double withdraw(doubleamount) amount) { { long start = System.currentTimeMillis(); long start = System.currentTimeMillis(); try try{ { Connection Connectioncon con==datasource.getConnection(); datasource.getConnection(); con.execute…(“select con.execute…(“select……blah blahblah”); blah”); this.balance -= amount; this.balance -= amount; con.commit(); con.commit(); }} finally finally { { long longtotalTime totalTime==System.currentTimeMillis() System.currentTimeMillis()- -start; start; System.out.println(“withdraw System.out.println(“withdrawtook took““++totalTime); totalTime); }} }}

What’s What’s wrong? wrong? •• Difficult Difficult to to enable/disable enable/disable •• Have to modify Have to modify all all methods methods with with the the same same functionality functionality •• Bloated Bloated code code

}}

7

© JBoss JBoss,Inc., Inc. 2003-2005.

Where Does AOP Come In? Professional Open Source™

– Can encapsulate “cross-cutting” functionality in one isolated place • Similar to encapsulating functionality to Java classes and methods – Execution points are declarative with “pointcuts” • AOP pointcut language applies the encapsulated logic into Java execution flow – Encapsulated functionality can easily be removed from your application code (change the declaration, rather than recompile code)

© JBoss JBoss,Inc., Inc. 2003-2005.

8

4

Terminology Professional Open Source™

Advice – Encapsulates cross-cutting code – An “event handler” for an execution point in code – Behavior you want to weave into your Java classes (metrics code)

Aspect – Java class that defines advices

Pointcut – AOP’s “query” language – Declaratively selects any point within Java code – For example, a method call, field access, instance construction

Invocation – Object instance that represents an invocation and its context

9

© JBoss JBoss,Inc., Inc. 2003-2005.

Professional Open Source Source™

Aspects and Advices in JBossAOP Intercepting Java Calls

© JBoss JBoss,Inc., Inc. 2003-2005.

8/2/2005

10

5

Aspect and Advice Professional Open Source™

Advice is the behavior you want to add – This will be executed on a selected point in the code flow

Aspects encapsulate one or more advices – Aspect itself is a regular Java class – Contains one or more advice definitions – Can use normal Java OOP features such as inheritance, delegation, methods that are not used as advices public publicclass class extends extendsX, X,implements implementsYY{{ public publicObject Object<methodname>(org.jboss.aop.joinpoint.Invocation <methodname>(org.jboss.aop.joinpoint.Invocationinv) inv)throws throwsThrowable Throwable{{ try try{{ ////ininpath path … … return returninv.invokeNext(); inv.invokeNext(); ////proceed proceedwith withthe theinvocation invocation }} finally finally {{ //out //outpath path ...... }}

11

© JBoss JBoss,Inc., Inc. 2003-2005.

Aspects Professional Open Source™

Sample metrics aspect with ‘profile’ advice – Invocation instance holds the context of the invocation that was intercepted (method arguments, metadata, etc.)

public publicclass classMetricsAspect MetricsAspect{{ public publicObject Objectprofile(MethodInvocation profile(MethodInvocationinvocation) invocation)throws throwsThrowable Throwable{{ try try{{ long longstart start==System.currentTimeMillis(); System.currentTimeMillis();

}}

}}

Advice Advice

return returninvocation.invokeNext(); invocation.invokeNext(); }} finally finally {{ long longtotalTime totalTime==System.currentTimeMillis() System.currentTimeMillis()--start; start; System.out.println(invocation.getMethod() System.out.println(invocation.getMethod()++““took took““++totalTime) totalTime) }}

© JBoss JBoss,Inc., Inc. 2003-2005.

12

6

Aspects Professional Open Source™

– invokeNext proceeds to the next advice or continues the original invocation normally

public publicclass classMetricsAspect MetricsAspect{ { public publicObject Objectprofile(MethodInvocation profile(MethodInvocationinvocation) invocation)throws throwsThrowable Throwable{ { long start = System.currentTimeMillis(); long start = System.currentTimeMillis(); try try{ { return returninvocation.invokeNext(); invocation.invokeNext(); }} finally finally { { long longtotalTime totalTime==System.currentTimeMillis() System.currentTimeMillis()- -start; start; System.out.println(invocation.getMethod() System.out.println(invocation.getMethod()++““took took““++totalTime) totalTime) }} }}

Advice Advice

}}

13

© JBoss JBoss,Inc., Inc. 2003-2005.

Aspect Scope Professional Open Source™

Aspects can be scoped depending on their usage – Scope determines the number if aspect instances created in the VM

PER_VM – Only one instance is created in the VM – All threads execute on the same aspect instance

PER_CLASS – One instance per adviced class is created. – All threads executing on any instance of adviced class use the same aspect instance

PER_INSTANCE – One instance for every instanced object of an adviced class – Threads that execute on the same object instance use the same aspect instance

PER_JOINPOINT – One instance on every matched join point for every instance of adviced class – Threads that execute on the same field, method or constructor of an object instance share the same aspect instance © JBoss JBoss,Inc., Inc. 2003-2005.

14

7

Aspect Configuration Professional Open Source™

Deployment descriptor META-INF/jboss-aop.xml – Declare the name of your aspect class – Declare where the advices should be applied (we will see this later)

jboss-aop.xml

class=“org.jboss.MetricsAspect”/> --> ......

15

© JBoss JBoss,Inc., Inc. 2003-2005.

Aspect Initialization Professional Open Source™

Aspect can be initialized with standard setter injection – Include JavaBean style method accessors in the aspect implementation – Configure the initialization values in the deployment descriptor jboss-aop.xml

class=“org.jboss.MetricsAspect”> PerformanceMetrics.log ”LogFile”>PerformanceMetrics.log ......

– Assumes method setLogFile() is exposed in aspect implementation. – Automatic type conversions exists for primitive types, Strings, URL, File, InetAddress, org.w3c.dom.Document (arbitrary complex initialization structure as DOM document), etc. (see the documentation for complete list). © JBoss JBoss,Inc., Inc. 2003-2005.

16

8

Aspect Initialization Professional Open Source™

If the aspect initialization depends on runtime properties or conditionals, you can use an aspect factory implementation – Implement org.jboss.aop.advice.AspectFactory interface – Configure in the deployment descriptor

jboss-aop.xml

“org.acme.MetricsAspectFactory”/> ......

17

© JBoss JBoss,Inc., Inc. 2003-2005.

Professional Open Source Source™

Pointcut Language Declarative Selectors in JBossAOP

© JBoss JBoss,Inc., Inc. 2003-2005.

8/2/2005

18

9

Pointcuts and Bindings Professional Open Source™

– Apply the aspect to your Java class – Pointcut expression declares where the aspect is to be invoked jboss-aop.xml

class=“org.jboss.MetricsAspect”/> credit(java.lang.String, BankAccount->credit(java.lang.String,int))”> int))”> name=“profile”/>

19

© JBoss JBoss,Inc., Inc. 2003-2005.

Pointcuts and Bindings Professional Open Source™

JBossAOP supports two kinds of pointcut wildcards – ‘*’ matches zero or more characters – ‘..’ matches any number of parameters on method or constructor call

--> toString())”> org.jboss.*->toString())”> ”formatStrings”/> --> deploy(..))” org.jboss.deployment.MainDeployer->deploy(..))”>> “authorizeDeploy”/>

© JBoss JBoss,Inc., Inc. 2003-2005.

20

10

Pointcuts and Bindings Professional Open Source™

Pointcut matching can be made based on declared exceptions and subclass types as well – Any declared exceptions in the advice declaration are matched to Java classes – An $instanceof{} operator can be used to declare matching on subclasses --> toString())”> $instanceof{org.jboss.ejb.Container}->toString())”> ”formatStrings”/> --> deploy(..) deploy(..)throws throws org.jboss.deployment.DeploymentException, org.jboss.deployment.DeploymentException,java.net.MalformedURLException)”> java.net.MalformedURLException)”> “authorizeDeploy”/>

21

© JBoss JBoss,Inc., Inc. 2003-2005.

Pointcuts and Bindings Professional Open Source™

– For method attributes, ‘!’ negator is accepted --> *(..))”> org.jboss.ejb.*->*(..))”> />

– Constructors can be declared with ‘new’ keyword – Constructors do not have a return type --> new(..))”> new(..))”> />

© JBoss JBoss,Inc., Inc. 2003-2005.

22

11

Pointcuts and Bindings Professional Open Source™

Advices can be added to either class methods or fields – “execution” keyword is used for method pointcuts (notice that a constructor in Java is just a special method) – “field” keyword can be used for pointcutting an instance field (read or write) – “get” keyword can be used for pointcutting a read of instance field value – “set” keyword can be used for pointcutting a write of instance field value --> deploy(..))”> org.jboss.deployment.MainDeployer->deploy(..))”> ”authorizeDeploy”/> --> SSN)”> com.acme.PersonVO->SSN)”> ”invariant”/> --> age)”> com.acme.PersonVO->age)”> ”precondition”/>

23

© JBoss JBoss,Inc., Inc. 2003-2005.

Pointcuts and Bindings Professional Open Source™

Additional keywords in the pointcut language – “all” keyword is used to find all possible point cuts in a given expression • Especially useful when used with annotations (will cover annotations in the following slides) – “call” keyword is similar to “execution” but adds caller side context information • “within” and “withincode” keywords match any method and constructor calls within the selected set • E.g. execute advice if an instance of class Foo was invoked from an instance of class Bar – “has” and “hasfield” keywords can be used for additional conditions for setting up join point selectors (whether a method, constructor or an instance field exists).

© JBoss JBoss,Inc., Inc. 2003-2005.

24

12

Pointcut Composition Professional Open Source™

You can compose a pointcut from multiple pointcut expressions using logical operators – Logical not ’!’, logical and ’AND’ and logical or ’OR’ operators are accepted – Parenthesis can be used to group expressions --> new(..))”> new(..))”> ”countMyClassOfFoo”/>

25

© JBoss JBoss,Inc., Inc. 2003-2005.

Pointcut References Professional Open Source™

With pointcut composition, expressions may get long and hard to read – Repeating long expressions is not ideal

You can create named pointcut expressions and reference them in bindings – <pointcut> tag – Helps keeping the declarations more human-readable --> <pointcut <pointcutname name==”public.methods” ”public.methods” expr expr ==”execution(public ”execution(public***->*(..))”/> *->*(..))”/> --> <pointcut name = ”public.constructors” <pointcut name = ”public.constructors” expr expr ==”execution(public ”execution(public*->new(..))”/> *->new(..))”/> --> public.constructors”> ”tracePublicMethodsAndConstructors”/>

© JBoss JBoss,Inc., Inc. 2003-2005.

26

13

Group Types with TypeDef Professional Open Source™

For complex group of types or type conditions that resolve to a class, you can create a new type group with – Useful especially when you have to repeat the group declaration a lot – Instead of writing many pointcuts individually, create a new type definition – Operators class(), has(), hasfield() and $instanceof{} are allowed in the typedef clause – You don’t have to rely as much on wildcard patterns that may have unexpected consequences later as the software evolves --> ”/> --> new(..))”> $typedef{ValueObjects}->new(..))”> ”countCreatedVOs”/>

27

© JBoss JBoss,Inc., Inc. 2003-2005.

Stack Advices Professional Open Source™

Several advices can be bound to a pointcut

”all(com.acme.BusinessObject)”> ”myAdvice”/> ”someAdvice”/>

© JBoss JBoss,Inc., Inc. 2003-2005.

28

14

Stack Advices Professional Open Source™

Create a named set of advices to apply on Java objects – Foundation for interceptor based containers <stack <stackname name==”MyContainer”> ”MyContainer”> ”com.acme.MethodLogAspect”/> ”com.acme.SecurityAspect”/> ”com.acme.TransactionAspect”/> ”all(com.acme.BusinessObject)”> <stack-ref <stack-refname name==”MyContainer”/> ”MyContainer”/>

29

© JBoss JBoss,Inc., Inc. 2003-2005.

Professional Open Source Source™

Dynamic AOP

© JBoss JBoss,Inc., Inc. 2003-2005.

8/2/2005

30

15

Dynamic AOP Professional Open Source™

Every AOPized class has an extended interface – At classloading time, bytecode manipulation forces AOP POJOs to implement a standard AOP interface.

public publicinterface interfaceInstanceAdvised InstanceAdvised{{ public publicInstanceAdvisor InstanceAdvisor_getInstanceAdvisor(); _getInstanceAdvisor(); public publicvoid void_setInstanceAdvisor(InstanceAdvisor _setInstanceAdvisor(InstanceAdvisornewAdvisor); newAdvisor); }}

public publicinterface interfaceAdvised Advisedextends extendsInstanceAdvised InstanceAdvised{{ Advisor _getAdvisor(); Advisor _getAdvisor(); }}

31

© JBoss JBoss,Inc., Inc. 2003-2005.

Dynamic AOP Professional Open Source™

– Dynamic insertion of interceptors per object instance – Object instance can hold its own metadata public public interface interface InstanceAdvisor InstanceAdvisor {{ public public SimpleMetaData SimpleMetaData getMetaData(); getMetaData(); public public Interceptor[] Interceptor[] getInterceptors(); getInterceptors(); public public Interceptor[] Interceptor[] getInterceptors(Interceptor[] getInterceptors(Interceptor[] baseChain); baseChain); public public boolean boolean hasAspects(); hasAspects(); public public void void insertInterceptor(Interceptor insertInterceptor(Interceptor interceptor); interceptor); public public void void removeInterceptor(String removeInterceptor(String name); name); public public void void appendInterceptor(Interceptor appendInterceptor(Interceptor interceptor); interceptor); public public void void insertInterceptorStack(String insertInterceptorStack(String stackName); stackName); public public void void removeInterceptorStack(String removeInterceptorStack(String name); name); public public void void appendInterceptorStack(String appendInterceptorStack(String stackName); stackName); }}

© JBoss JBoss,Inc., Inc. 2003-2005.

32

16

Dynamic Pointcuts Professional Open Source™

AdviceBinding AdviceBinding binding binding == new new AdviceBinding("execution(POJO->new(..))", AdviceBinding("execution(POJO->new(..))", null); null); binding.addInterceptor(SimpleInterceptor.class); binding.addInterceptor(SimpleInterceptor.class); AspectManager.instance().addBinding(binding); AspectManager.instance().addBinding(binding);

jboss-aop.xml

<prepare <prepareexpr="execution(POJO->new(..))"/> expr="execution(POJO->new(..))"/>

33

© JBoss JBoss,Inc., Inc. 2003-2005.

Professional Open Source Source™

Annotated Aspects

© JBoss JBoss,Inc., Inc. 2003-2005.

8/2/2005

34

17

Java Annotations Professional Open Source™

JDK 1.5 adds a new language feature – annotations – Formalizes the XDoclet approach of adding descriptive tags to your Java code

JBossAOP can be used with annotations instead of XML deployment descriptors – XML deployment descriptors are declarative, and can be changed without recompilation – Annotations are compiled, and changes require recompilation – Some features are better expressed as Java language level attributes to methods, fields and classes (for example, transactional attributes) – Some features are better expressed as easily changeable, and dynamic, configuration (tracing, metrics, authorization roles, etc.)

Annotations can also be used with JDK1.4 with JBossAOP annotation precompiler.

35

© JBoss JBoss,Inc., Inc. 2003-2005.

Define Annotation Professional Open Source™

Defining custom annotations is easy – Similar to defining interfaces

public public@interface @interfaceReadLock ReadLock{}{} public public@interface @interfaceWriteLock WriteLock{}{}

ReadLock and WriteLock are marker annotations – No additional elements class classXX{ { @ReadLock @ReadLockpublic publicObject ObjectgetData() getData() { {. .. .. .} } @WriteLock @WriteLockpublic publicvoid voidsetData(Object setData(Objectdata) data){ {. .. .. .} } }}

© JBoss JBoss,Inc., Inc. 2003-2005.

36

18

Define Annotation Professional Open Source™

You can add elements to annotations – Types can be primitives, strings, enums, classes or annotations public public @interface @interface WriteLock WriteLock {{ int int timeout(); timeout(); }}

class class XX {{ @WriteLock(timeout @WriteLock(timeout == 5000) 5000) public public void void setData(Object setData(Object data) data) {{ .. .. .. }} }}

See JDK 1.5 documentation for full details.

37

© JBoss JBoss,Inc., Inc. 2003-2005.

Annotation Compiler for Java 1.4 Professional Open Source™

JBossAOP comes with a precompiler that you can use against Java 1.4 compliant codebase – Annotation types are defined as interfaces – Annotations are part of javadoc comments package package com.mypackage; com.mypackage; public public interface interface RWLock RWLock {{ int int timeout(); timeout(); }}

/** /** ** @@com.mypackage.RWLock @@com.mypackage.RWLock (timeout=3) (timeout=3) */*/ public public int int myMethod() myMethod() {{ … … }}

© JBoss JBoss,Inc., Inc. 2003-2005.

38

19

Annotation Compiler for Java 1.4 Professional Open Source™

Notice some important differences: – Starts with a double sign ’@@’ – Must have whitespace between annotation type name and element names – Must use the fully qualified name of the annotation interface (cannot use imports) – No default values for elements (JDK 1.5 annotations support this feature)

39

© JBoss JBoss,Inc., Inc. 2003-2005.

JBossAOP Defined Annotations Professional Open Source™

org.jboss.aop.Aspect – Marks a class as an aspect

org.jboss.aop.PointcutDef – Defines a named pointcut declaration

org.jboss.aop.Bind – Binds an advice within aspect with a given pointcut

@Aspect @Aspect (scope (scope == Scope.PER_VM) Scope.PER_VM) public public class class MyAspect MyAspect {{ @PointcutDef @PointcutDef (”execution(\”public (”execution(\”public ** com.acme.*->create(..)\”) com.acme.*->create(..)\”) public public static static Pointcut Pointcut createMethods; createMethods; @Bind @Bind (pointcut (pointcut == ”createMethods”) ”createMethods”) public public Object Object countInstances(Invocation countInstances(Invocation invocation) invocation) {{ … … }} }}

© JBoss JBoss,Inc., Inc. 2003-2005.

40

20

Annotations in Pointcuts Professional Open Source™

You can take advantage of annotations in pointcut expressions as well – At times better than using wildcards and fixed class and method names

all(@com.acme.createMethod) – All methods marked with @createMethod annotation

withincode(@javax.ejb.Entity->new(..)) – Public constructors of EJB3 entity classes

41

© JBoss JBoss,Inc., Inc. 2003-2005.

Professional Open Source Source™

Aspect Examples POJO Middleware

© JBoss JBoss,Inc., Inc. 2003-2005.

8/2/2005

42

21

ReadWriteLock Aspect Professional Open Source™

public publicclass classReadWriteLockAspect ReadWriteLockAspect{{ java.util.concurrent.ReentrantReadWriteLock java.util.concurrent.ReentrantReadWriteLocklock lock==new newReentrantReadWriteLock(); ReentrantReadWriteLock(); public publicObject ObjectreadLock(Invocation readLock(Invocationinvocation) invocation)throws throwsThrowable Throwable{{ try { try { lock.readLock().lock(); lock.readLock().lock(); return returninvocation.invokeNext(); invocation.invokeNext(); }} finally finally {{ lock.readLock().unlock(); lock.readLock().unlock(); }} }} public publicObject ObjectwriteLock(Invocation writeLock(Invocationinvocation) invocation)throws throwsThrowable Throwable{{ try try{{ lock.writeLock().lock(); lock.writeLock().lock(); return returninvocation.invokeNext(); invocation.invokeNext(); }} finally finally {{ lock.writeLock().unlock(); lock.writeLock().unlock(); }}

43

© JBoss JBoss,Inc., Inc. 2003-2005.

ReadWriteLock Aspect Professional Open Source™

– Specify pointcut that selects @ReadLock and @WriteLock annotations

scope=“PER_INSTANCE”/> @org.jboss.ReadLock(..))”> *->@org.jboss.ReadLock(..))”> name=“readLock”/> @org.jboss.WriteLock(..))”> *->@org.jboss.WriteLock(..))”> name=“writeLock”/>

© JBoss JBoss,Inc., Inc. 2003-2005.

44

22

Asynchronous Invocations Professional Open Source™

Asynchronous Aspect – – – – –

Tag Methods Invoke them in background Obtain response asynchronously In-VM only Working on Remote asynchronous invocations

45

© JBoss JBoss,Inc., Inc. 2003-2005.

Asynchronous Invocations Professional Open Source™

import importorg.jboss.aspects.asynchronous.aspects.jboss.Asynchronous; org.jboss.aspects.asynchronous.aspects.jboss.Asynchronous; public publicclass classPOJO POJO{{ public publicvoid voidprocessBusinessModel(){...} processBusinessModel(){...} @Asynchronous @Asynchronous public publiclong longprocessBusinessModel(...){} processBusinessModel(...){} }}

© JBoss JBoss,Inc., Inc. 2003-2005.

46

23

Asynchronous Invocations Professional Open Source™

POJO POJOpojo pojo==new newPOJO(...); POJO(...); ////non-blocking long longresult result==pojo.processBusinessModel(...); pojo.processBusinessModel(...); non-blockingcall call AsynchronousFacade AsynchronousFacadefaçade façade==(AsynchronousFacade)pojo; (AsynchronousFacade)pojo; ...... ////do dosome somework work ...... ifif(facade.isDone()) (facade.isDone()){{ ifif(facade.getResponseCode() ////Test (facade.getResponseCode()== ==OK) OK) Testresponse responsecode codereturned returned result ////get result==((Long)facade.getReturnValue()).longValue(); ((Long)facade.getReturnValue()).longValue(); getmethod methodresponse response else ////Test elseifif(facade.getResponseCode()==TIMEOUT) (facade.getResponseCode()==TIMEOUT){...} {...} Testififmethod methodtimed timedout out else else{{ AsynchronousResponse AsynchronousResponseresponse response==facade.waitForResponse(); facade.waitForResponse(); ////blocking blockingcall call IfIf(response.getResponseCode()==OK) // get (response.getResponseCode()==OK) // getmethod methodresponse response result=((Long)response.getReturnValue()).longValue(); result=((Long)response.getReturnValue()).longValue(); else ////Test elseifif(response.getReponseCode()==TIMEOUT) (response.getReponseCode()==TIMEOUT){...} {...} Testififmethod methodtimed timedout out }} }}

47

© JBoss JBoss,Inc., Inc. 2003-2005.

Transaction Demarcation Professional Open Source™

Transaction demarcation (method, field, constructor) – You can specify transaction boundaries within code

Tags can transparently interact with Transaction Manager – Begin, suspend, commit and rollback transactions – On method, field, or constructor execution

EJB adjectives used to specify transactional behavior – Required, RequiresNew, Supports, Never, NotSupported, Mandatory

Complete control over when a rollback is triggered – i.e. which thrown exceptions cause a rollback

© JBoss JBoss,Inc., Inc. 2003-2005.

48

24

Transaction Demarcation Professional Open Source™

– Annotations or XML metadata can specify annotation

@Tx(TxType.REQUIRED) @Tx(TxType.REQUIRED) public public void void somepojoMethod() somepojoMethod() {{ … … }}

<metadata <metadata tag="transaction" tag="transaction" class="org.jboss.test.POJO"> class="org.jboss.test.POJO"> <method <method name="somepojoMethod“> name="somepojoMethod“> RequiresNew RequiresNew

49

© JBoss JBoss,Inc., Inc. 2003-2005.

Transactional Locking Professional Open Source™

Enhanced Java “synchronized” – Allows you to lock object/class for duration of a transaction

Can specify on any member field or method – Locks object instance

Can specify for any constructor or static method, field – Locks class access

© JBoss JBoss,Inc., Inc. 2003-2005.

50

25

Transactional Locking Professional Open Source™

– Annotations or XML metadata can specify annotation @TxSynchronized @TxSynchronized public public void void somepojoMethod() somepojoMethod() {{ … … }}

<metadata <metadata tag="transactionSynchronized" tag="transactionSynchronized" class="org.jboss.test.POJO"> class="org.jboss.test.POJO"> <method <method name="somepojoMethod“/> name="somepojoMethod“/>

51

© JBoss JBoss,Inc., Inc. 2003-2005.

Roled-based Security Professional Open Source™

Secured access to any method, field, or constructor – Only users of a certain role allowed to access

Authentication/Authorization integrated with JBoss Security – Various Security Domains (LDAP, RDBMS, SRP, etc…)

Access to username available within other interceptors

© JBoss JBoss,Inc., Inc. 2003-2005.

52

26

Role-Based security Professional Open Source™

XML metadata can specify annotation <metadata <metadatatag="security" tag="security"class="org.jboss.test.aop.bean.SecuredPOJO"> class="org.jboss.test.aop.bean.SecuredPOJO"> <security-domain>other <security-domain>other <method-permission> <method-permission> allowed allowed <method><method-name>someMethod <method><method-name>someMethod <exclude-list> <exclude-list> <description>Methods <description>Methodsthat thatconnect connectbe beused used <method> <method> <method-name>excluded <method-name>excluded

53

© JBoss JBoss,Inc., Inc. 2003-2005.

Role-Based security Professional Open Source™

JDK 5.0 Annotations are usable @SecurityDomain(“other”) @SecurityDomain(“other”) public publicclass classPOJO POJO{ { @Unchecked @Uncheckedpublic publicPOJO() POJO(){}{} @Exclude @Excludepublic publicexcludedMethod() excludedMethod(){…} {…} @Permissions({“admin”, @Permissions({“admin”,“manager”}) “manager”}) public publicvoid voidsomeMethod() someMethod(){…} {…} @Permissions({“user”}) @Permissions({“user”}) public publicstatic staticint intstatus; status; }}

© JBoss JBoss,Inc., Inc. 2003-2005.

54

27

Role-based Security Professional Open Source™

Security information is available within advice/interceptors – Useful if you want to do your own rule-based security

import importjava.security.Principal; java.security.Principal; public publicObject Objectinvoke(org.jboss.aop.joinpoint.Invocation invoke(org.jboss.aop.joinpoint.Invocationinvocation) invocation)throws throwsThrowable Throwable {{ Principal Principalprincipal principal==(Principal)invocation.getMetaData("security", (Principal)invocation.getMetaData("security","principal"); "principal"); …… }}

55

© JBoss JBoss,Inc., Inc. 2003-2005.

Conclusion Professional Open Source™

AOP Framework – – – –

Hot deployment Dynamic API Metadata Integration Seamless integration with JBoss architecture

Aspect-Oriented Middleware – POJO based development – Free developers from specifications

© JBoss JBoss,Inc., Inc. 2003-2005.

56

28

Related Documents

Aom
November 2019 11
Aom Compliance.docx
June 2020 13
Aom Sample.doc
June 2020 7
Aom%20reg
December 2019 10
Aom-donation-101.docx
April 2020 6
Aom 006 Aics.docx
December 2019 18