Logo
StartDownloadsDocumentationPublicationsContactCommunityDevelopers

0.8.5M3 Release Notes

Important upgrade information:

Gotchas:

  • Default VM target is now 1.5, when using JAsCo in 1.4, use the target flag for compiling JAsCo artifacts..
  • Make sure to alter all your existing aspects and connectors since four keywords have changed for compliance with AspectJ’s terminology. See 0.8.5M1 release notes.
  • Several features now require a Java 1.5 VM (refinable methods, run-time weaver), a clear error is shown when this is not the case

If you are updgrading from a version earlier then:

  • 0.8.x: you have to redo the install procedure as outlined by the installation instructions. The classpath has changed.
  • 0.7.4: the HotSwap 2 startup command is Modified for compliance with Java 1.5 final! See here for the new command.

Latest public build detailed information: Click here. See also for known limitations and bugs of current version.

Major Changes for latest build:

1. Aspect Factories

JAsCo now supports a range of facilities for automatically creating multiple aspect instances depending on the current joinpoint. The following keywords are currently supported:

  • perobject: one unique hook for every target object instance
  • perclass: one unique hook for every target class
  • permethod: one unique hook for every target method
  • perall: one unique hook for every joinpoint
  • perthread: one unique hook per executing thread, i.e. a ThreadLocal hook instance

They are placed in front of a hook instantiation in the connector. For example, the following connector instantiates the ProtocolChecker hook once for every thread running in the application:

static connector PerThreadConnector {
    perthread Protocol.ProtocolChecker aspect3 = new Protocol.ProtocolChecker(....); //predefined factory instantiation
}

It is also possible to implement custom aspect factories by implementing the jasco.runtime.aspect.factory.IAspectFactory interface. This interface contains one method, getAspectInstance, that is responsible for fetching the aspect instance for the currently executing joinpoint jp. The second argument allows to create a new hook instance and initialize it properly as defined in the associated connector.

public interface IAspectFactory {
     public IHook getAspectInstance(MethodJoinpoint jp, IAspectInstanceCreator creator);
}

The following code fragment illustrates a custom aspect factory that returns a new hook instance for every class loader that loaded the executing class of the current joinpoint. As such, both the hook and the joinpoint are loaded by the same class loader and thus avoiding possible class loader hell problems.

package test.aspects;
 
public class PerClassLoaderAspectFactory implements IAspectFactory {
    
     public PerClassLoaderAspectFactory(){}
 
     private Hashtable map = new Hashtable();
 
     IHook getAspectInstance(MethodJoinpoint jp, IAspectInstanceCreator creator) {
        
           IHook instance = (IHook) map.get(jp.getClassLoader());
           if(instance==null) {
               instance = creator.createNewInstance(jp.getClassLoader());  
               map.put(jp.getClassLoader(),instance);
           }
           return instance;
     }
 
}

Good to know:

  • Custom aspect factories must be public and have a public default constructor (no arguments).
  • There is also a convenience class named DefaultAspectFactory available that manages the dictionary for you. Subclasses only need to implement the getKey(MethodJoinpoint) method.
  • In case the result of the aspect factory, i.e. hook instance, does not remain constant given all static information in the joinpoint like method name, class name, class loader, return types, argument types, etc... In other words, it depends on some dynamic information, like target object or thread, then the aspect factory must implement the jasco.runtime.DoNotCache interface. This empty interface is merely a marker interface that declares that this aspect factory has to be used for every execution of all joinpoints. Per default, the factory result is optimized by the run-time weaver to only execute once for every static shadow joinpoint.

Applying the Factory:

The custom factory can now be used in a connector as follows:

static connector PerConnector {
    per(test.aspects.PerClassLoaderAspectFactory) MyAspect.MyHook aspect2 = new MyAspect.MyHook(....); //custom factory instantiation
}

The custom factory will be used for all joinpoints where this instantiation of the MyAspect.MyHook hook is applicable.

2. Limited subtype matching pattern

The + operator defined in a method signature in an instantiatian expression in the connector allows to match all subtypes of a given class. However, it is often useful to match all overriden methods of a given type or all implemented methods of a certain interface. This is now supported using the ++ operator.

Take for instance the following connector:

static connector LimitedSubtypeConnector {
    MyAspect.MyHook test= MyAspect.MyHook(* MouseListener.*++(*);
}

The MyHook hook will be triggered on all methods of the type MousListener implemented by implementing classes. Other methods of the implementing classes are not affected by the hook (this in contrary to the regular + operator).

3. Virtual Mixins can be cast normally

Virtual mixins allow to insert the implementation of an interface in target classes so that other aspects can depend on that. This is mainly useful for communicating information between aspects.

Previously, in order to cast an object to the mixin interface, the mixinOf operator was required. Now it is possibly to use plain Java casting in order to cast an object to the mixin interface. Suppose a ICustomerInfo interface was inserted into the Customer class, then the mixin interface can be accessed as follows:

ICustomerInfo info = (ICustomerInfo) customer; //customer is an instance of the Customer class

The implementation of the ICustomerInfo interface is inserted in the Customer class by a JAsCo hook as described in the quick language reference.

Good to know:

  • Casting an object to the inserted mixin is only possible inside hooks, inline refinements in a connector and refining classes
  • Anywhere else, you have to use the following: jasco.runtime.mixin.MixinManager.mixinOf(Object,Class)

4. Easier fetching of hook instances from Java code

In order to fetch aspect instances directly, do the following in case of normal instantiation:

Connector.MyConnectorName.getConnector().myAspectVariableName(); 
//myAspectVariableName is the variable name of the hook instance in the connector
  • In order to fetch aspect instances directly, do the following in case of per* instantiation:
Connector.MyConnectorName.getConnector().myAspectVariableName(keyForPerInstantiation); 
//myAspectVariableName is the var name of the aspect instance in the connector
//keyForPerInstantiation is the key to fetch the hook instance, e.g. target object in case of perobject, targetclass in case of perclass etc...

5. Small improvements

  • better warning when hook variable name is already defined in connector
  • fixed the after finally bug (after not executed when exception is thrown)
  • fixed hotswap in case of global strict and complement
  

Changes of previous milestones

kernel/0.8.5m3.txt · Last modified: 10.06.2005 14:24
SiteMapRecent Content by SSEL ©2002-2005     Latest JAsCo Release: JAsCo 0.8.7 (revised 2005-11-25 16:29:02)