Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
 public abstract class BaseCmd {
      static public ConfigurationService _configService;
      static public AccountService _accountService;
      static public UserVmService _userVmService;
      static public ManagementService _mgr;
     
    // more code ...
     
    // code to resolve above static references using runtime resolution
}

...

Code Block
public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String> implements ConfigurationDao {

	@PostConstruct @PostConstruct 	void initComponent() {		// more code...	}  
}

4.4 When to use or avoid creating run-time relationship with component container

...

Code Block
public class FooObject {

    FooService _fooService;
     
    public FooObject(FooService service) {
        _fooService = service;
    }



    ....
}

...

If you ever need to implement a method interceptor, implement interface ComponentMethodInterceptor and declare it in applicationContext.xml.in. As you see in the above example, ActionEventInterceptor implements an aspect to automatically log events at methods in classes that have been marked as @ActionEvent. To install such interceptor, declare it as following in applicationContext.xml.in 

Code Block
  <bean  <bean id="actionEventInterceptor" class="com.cloud.event.ActionEventInterceptor" />

  <bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
    <property name="Interceptors">
        <list>
            <ref bean="transactionContextBuilder" />
            <ref bean="actionEventInterceptor" />
        </list>
    </property>
  </bean>

Not any class can be intercepted in this way, both due to implementation limitation and for sake of performance, only classes that have marked itself with a marker interface ComponentMethodInterceptable can be intercepted for above AOP pattern. to apply above AOP pattern. All Manager, Adapter and DAO classes are currently marked with ComponentMethodInterceptable.

ComponentInstantiationPostProcessor is a CloudStack implemented Spring post processor that eventually implements the Customized AOP pattern. ComponentInstantiationPostProcessor uses CGLIB to replace loaded component instance with a CGLIB generated wrapper object that is a sub-class instance of the original object, in this way, it can provide hooks to all method calls to the object through ComponentMethodInterceptor.

The sub-class generated by CGLIB uses the naming convention implemented in ComponentNamingPolicy. All these generated classes are named after "EnhancedByCloudStack" pattern, you may notice it in log messages or in debug session.

4.6 Pluggable adapters

Adapter components usually works under the management of its manager component, a same set of adapter components may be used by multiple managers, and sometimes, order of the adapters may also be significant. Whether or not an adapter component is in action depends not only the existence of its <bean> declaration, but also the references in manager components.

...